Artificial intelligence

Back to Home

A Brief Introduction

Artificial intelligence goes back to as early as the 13th century but it didn't truly take form until the 20th century when numerous advances were made including a chess machine that played using an electro magnet and possible the most important: Alan Turing's Turing test. In this test a chat bot (computer that talks to a human) would try to be misinterpreted by a human to be another human. However, John McCarthy was the first person to refer to computers thinking intelligently as artificial intelligence. Since then, numerous advances have been made in the field of Artificial Intelligence.

Forms of Intelligence

There are nine main forms of intelligence as described by Dr. Howard Gardner. Linguistic intelligence is the ability to read, write, tell stories, and learn languages, grammar, and syntax. Logical-mathematical intelligence is the knowledge of numbers, logic, reasoning, and abstractions. Musical Intelligence is the knowledge of sounds, rhythms, musical pitch, and key. Spatial intelligence is the ability to imagine, understand, and represent the visual spatial world. Bodily-kinesthetic intelligence is focused on motor skills related to physical movement. Interpersonal Intelligence is the ability to organize people and recognize another person's feelings and emotions and is also good at communicating and being a leader. Intrapersonal Intelligence is the ability to be self-aware and explore emotions, goals and motivations. Naturalistic Intelligence is focused on the knowledge of nature. Existential Intelligence is the ability to ponder questions about life, death, and what lies beyond that.

Chat Bot


User Input

Programming a chat bot was the first task assigned to us. In order to make a chat bot I knew there had to be a lot of user input, and in order to do that I had to use a lot of "raw_input"'s in my code. Here is an example of a function in which the user inputs their name and how they are feeling.

Targeting specific words

You can also make the program target specific words an give responses that the coder has coded in. What you have to do is use these if and else-if statements that make it so if a specific word is in the user's response, the program will give a predetermined response. Here is an example of them:

Yes or No

The last thing that I programmed into the chat bot was a yes or no function. This is something that I will continue to use in many of my python programs that use user input. What this does is ask the user a question and depending on if they respond with 'y' or 'n' the program can do a predetermined action. This can be used to ask if a user wants to ask a question, or if a user would like to have the first move in a game.

Fact Bot

The next thing that I did was make a Fact bot. What the program did was ask the user for their question and give them back an answer if possible. This was accomplished by using something called Wolfram Alpha. My program could access the Wolfram Alpha database using an app i.d. that I got by signing up for an account on their website.

Using this code I was able to get the answers to most questions. If Wolfram Alpha was not able to answer the question, then I made my python program able to say that it didn't have an answer to the question. Here are some questions that the program did answer successfully though:

As you can see this is a pretty interesting program.

Rock, Paper, Scissors

Making the rock paper scissors program was not too hard to do. What the program would do was have the user input a number 1-3, each representing either rock, paper, or scissors. The computer would then pick a random number and then compare the two numbers to determine if the user won, lost, of if it was a tie.


This was based off of James Bamford's compact Rock, Paper, Scissors design.

Hangman


Making the hangman game was quite challenging. The first challenge was to make the board which I made using a combination of lines, dashes, and plus signs. The next thing was making it so when a letter was guessed, either a body part of the man would be added to the board or the letter would be added to the un-guessed word. The next thing was commingg up with a list of words. I used Mr. Farrell's list of words on his website . You can view the list of words here. Because all of the words relate to animals, at the beginnning of my python program I mention that the theme is animals to give the player a little bit better of a chance at winning the game. After eveery turn, the program checks and to see if either the word is guessed correctly (in which case the player wins) or if the entire man is filled (in which case the player would lose) and does the respective predetermined action which is either congratulating the player or telling the player that they lose and revealing the correct word that the computer chose. I have to say that making this was probably the most fun I've had making anything in python besides making the lego robot programs.

Here is a picture of the code in action:

I did not do very goo d but you can still see that the code works!

Tic Tac Toe

Even a simple game such as tic tac toe was really hard to make in python. The first thing I did was make a 2 player game.

Step 1:(Intro and drawboard)



The intro part was a simply intro to the game. The drawboard() function however is far more important. It is the game board for the game that will continually change as the game goes on and as the players choose spaces.

Step 2:(Getting the move)


This function asks the player for their move. It also checks to see if that space on the board is taken or if whatever the player typed is not a value between 1 and 9.

Step 3:(Applying the move)


While this function is not very lengthy, what it does is it applies the move that the player just inputted to the board that I mentioned in step 1.

Step 4:(CheckWin an CheckTie)


These two functions check if the game will be either a tie or a win for one of the players. In order to check if the game is a win for one of the players I had to create this list with all of the possible ways for a player to win and the computer would check those spaces and see if they were in the same state of 'X' or 'O'. The check tie function just checked to see if there were no blank spaces on the board after the check win function turned up false.

Step 5:(Replay)


All this function does is ask the user if they would like to play again, short and simple as that.

Step 6:(Putting it all together)

What this does is put together all of the functions in the correct order and make the game of tic tac toe work.

To adapt the two player to a single player game in which you play against a computer you need to replace the get move function for player two to a new one in which the computer ideally chooses intelligently and makes it impossible for the human player to win. Unfortunately I could never actually get this to work despite trying for many hours :(