Artificial Inteligence week 1!


In our 6th week of Intro to Comp Science we looked at artificial inteligence!
Our first objective was to gather some background information!

On the first day of coding we all created a chatbot!


Here's a picture of the code we used!

We used a program called python to create our own programs! It was awesome being able to use the information that we learned before to help with our recent projects. We used python our 3rd week of intersession, becuase we created a number guessing game. The basic principles were the same because we were essentially putting a combination of caracters into the program and got others out.... Of course having to come up with dialogue was a lot more complex! The whole program was written as a function- which is why the second line is defining it. We wrote what the program wanted to ask in the green! The words could not be simply printed, as seen later on in the picture, because then it would not know what do say. For example, after the question of what song is the users favorite, the program randomly chooses a number of out 1 or 2. If it is 1 then the program prints "Thats my favorite, too." or ELSE it says "I hate that song." Later on in the code the question is asked on weather the user has a question to ask, and depending on the answer it either continues the conversation or it prints "ok, bye" then ends the program

.


Here's a picture of actual dialogue between a user and the program!


It looks a lot better than the code, but it is crazy to think about how hard it is for the computer to even do this much talk back. Coming up with artificial inteligence sounds a lot easier than it is!






One the second day of coding our class taught the computers to speak!

I was late to class that day so our awesome TA, Tommy L, helped me to get caught up! He just came over to my table and showed me examples of codes on how to make the computer speak back to you! It was not nearly as hard as I thought it would be!



It was that simple! All that had to happen was a little import from a code that came wiht the program. Then step two was telling the engine e.g. the computer, to speak by using the steel program and then telling the computer to do eSpeak. There were two ways to tell the computer what to say, and both are showed in the picture! The first is simply directly typing in the words that you would like for it to speak, and the second was giving a phrase a variable by setting it equal to something. As you can see the letter a was set equal to the word world so when you typed the next line of code the word world was added to the phrase! Boom as simple as that!


On our third day we took a little break from chatbots... and made factbots!


This was a lot easier to do than I thought it would be too! Here's a picture of the code we made!


The point of the program was to create a different sort of chatbot, but it was not really a chat bot. It was a factbot! At first I thought this was going to be one of the most tedious and unnecessary things ever because we only knew how to directly program responces for the computer to say, so having it just spit back facts actually sounded like "Sit there and write line after line of facts that you want your computer to know." Although thats what it sounded like that was nothing like what happened!

If you look at the code you'll see a couple of things that were not on any other codes written that far! The first being the import of "wolframalpha." Wolframalpha was basically the first google! It is a database that can be querried for information! Sooooo you could say we kind of made a mini google!




On Friday, the last day of week seven, we started to create RPS!


RPS stands for Rock, Paper, Scissors! What we did to make games was come up with the thought process that the computer would use to play the game. Surprisingly the human brain is a lot more complex than what people give it credit for, so playing a game like rock paper scissors, or hangman is pretty simple for us, but when you try to make a computer think like a human... that's where the snags come in...
So we broke it down! We took every action, or thought, and put it into its own function.
Here's a picture of the final code for the game!



There was only a total of 10 lines because we broke the task down into functions!



The first function being the imports and the setting of the array. Arrys have been mentioned in previous sites; but for a refresher, it is a list. So the second part of the set up is just the list of possibilities that the computer can choose from when deciding if it wants to go with rock, paper, or scissors.



The program then greets the player, and prompts the user for the game!



The next part of the algorithm was the computer picking from the array, mentioned earlier.



Next, the user is prompted to make achoice on what they would like to pick. The user then inputs their choice and then the next part of the code decides if its a winner.



This part was byfar the hardest, and the most complicated part to come up with. At first everyone thought that we would have to go through ever single possibility and tell the computer what to do or what the outcome would be... That did not end up happening because we were shown how to use if and else statements to replicate the answers you would get from playing the game. For example the first line that says "elif" says that if the computer picks r and the human picks s then it would say"I win. I chose rock." and if that did not happen it would say "You win. I chose paper." The reason the computer knows that it can not also be a rock is because the first "if" statement says that if the computers answer is the same as the computer then its a tie.



The last part was asking if the user would like to play again. If they say y then it would start again, but if they did not then the game would be over and the program would be ended.



Here's a link to week 2!
Heres the link back home!