Intelligence Games

Intelligence Games

We have learned about games, and we have learned about A.I. This week, we are learning about intelligence games. Today, created a number guessing game on python. My game will choose a number inbetween 1 and 1000. You will have 10 guesses. My game starts out with an intro, and then goes into the guessing. Here is my code.

Here are a few images from the game.

While coding this game, I used a different methood than before. instead of having all the code one after another, I made a bunch of functions The great thing about this, is you can test individual parts of your program just by testing out your function. I found this method to be far more effective. When I programmed my chatbot, it was code after code. If I wanted to test out a code that was towards the end of the program, I would hae to go through the entire program. Using functions like this makes programming a lot easier.

Hangman

Today, we programmed hangman on Python. For me the hardest part, was making it so that the underscores would change any correctly guessed letters. But after that everything was easy-ish. I still couldn't make the game understand whe you won so after you guess all the letters, it will keep asking for letters. Here is the code.

The first picture shows the list of words, the intro, and the code to display the blanks. The second picture shows the code for checking if the letters are in the word or not. Below are a few snapshots of the gameplay.

I finnaly managed to get the hangman, to know when you win

I was finally able to do this with some of Mr Farrell's help. He helped me with this code.

This code helps the A.I. know when you have guessed all the correct letters, ultimetly letting you know when the game has been won. This has become really helpful for me, because I have been sruggling with this ever since yesterday.

Tic-Tac-Toe

Today, we started coding for Tic-Tac-Toe. We first started out with functions. Some of these functions included printing the board, asking if you wanted to go first, etc. etc. Then we began coding the functions.

One of the functions was slightly larger than the others. This function checked the board, to see of anyone had won the game yet. This code actually checked all of the possible ways to win, and if there was one, it would return true.

Here is the finished product, that I was able to make with the help of Mr. Farrell.

Before I made this Tic-Tac-Toe program, I attempted at making one of my own, but it didn't work out so well. When I first started out, I made a few list. One was for human chosen boxes, computer chosen boxes, and not chosen boxes.

I made it so that after a box was chosen, it would remove that nunmber from the not chosen yet list. But I ran into a problem. Sometimes the program would say there was nothing in the list, and just end everything.

The error is saying that my input "2", was not part of my list, but it is.

I feel like these intelligence games are rather difficult to program, but having a finished product is very satisfying.

Today we worked more on our Tic-Tac-Toe. We improved our fuction, so that you can only input valid moves. We also included a computer that chooses squares at random, but it seems to have some intelligence. It has even managed to win a few games.

Here is some of the game play woth the new code

Next, we gave the computer some A.I. The code for this new A.I. will see if there are any possible wins. If the computer can win, it will go for that square. If the human can win, he computer will block it.

Here is the computer blocking

Here is the computer making the winning move