Skip to content

This is the simple game of 'Tic Tac Toe' also known as 'Noughts & Crosses' which one can play against the computer that is equipped with several AI algorithms.

License

Notifications You must be signed in to change notification settings

ketan-lambat/Tic-Tac-Toe-using-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic Tac Toe using AI

This is the simple game of 'Tic Tac Toe' also known as 'Noughts & Crosses'.

forthebadge

GitHub Repo Link ketan-lambat/AI_Games

GitHub repo size


forthebadge

Gameplay Video URL TicTacToe with AI

YouTube Video Views YouTube Video Likes YouTube Video Comments


First to setup the game dependencies, you need to install pygame.

pip install pygame


To run the 3x3 varient

  1. Navigate to src/3x3 Tic Tac Toe/ directory in the terminal or command prompt.

  2. Enter the command python TicTacToe_AI.py to run the script.

  3. You should get the Hello message from the pygame community in the terminal and the game application window shall now open. 3x3Home

  4. Select the AI algorithm to use by clicking on the appropriate button and watch the terminal too for the output messages. Algo Selected

  5. The Tic Tac Toe game shall now start, and you can play by clicking on the box you want to make the next move on.

  6. Ensure you watch the terminal to get the time taken by the AI algo to decide the next move. AI Time Taken

  7. If either of the player wins, you can see that with the strike through line across the winning cells, or a Game Draw message if all the cells are filled (simple Tic Tac Toe rule). AI Wins

  8. The average time taken by the AI algo is printed in the console window after the game ends and the game application window closes. Game Draw

To run the Open Field Varient

  1. Navigate to src/Open Field Tic Tac Toe/ directory in the terminal or command prompt.
  2. Enter the command python TicTacToe_AI.py to run the script.
  3. You should get the Hello message from the pygame community in the terminal and the game application window shall now open.
  4. Select the size of the board you wish to play on. Open Field Home
  5. Select the AI_algo to use. Due to computational constraints, these algo might take longer to generate an output (or might not generate at all). So kindly use the ones mentioned. Grid Selected
  6. Next steps are same as the above game.

Algo Selected

User Wins

Notice the High Computation time required for Alpha-Beta Pruning algo for 4x4 grid

High Computational Time


(Optional) To build an executable file (if not already present), you will need cx_Freeze

python -m pip install cx_Freeze

  • Navigate to the project folder src/Open Field Tic Tac Toe/ or src/3x3 Tic Tac Toe/
  • The setup.py file contains the configuration for the build command
  • Run the command python setup.py build
  • This will create a build folder in the directory which should have a folder named ext.____
  • Within this folder will be an executable file eg. TicTacToe_AI.exe
  • Double-click on this and the console output window and the game application window will open and you can play the game as mentioned above.

Points to Note

  • Here we are sourcing the static files(images and fonts) from the same folder as the source code. We can also put them in a static folder and and access them using relative paths. But, this creates issues when building the executable file. So, to avoid that, the static folder method has not been used.
  • Each project has 3 python (.py) files, 2 are the source code and the setup.py file contains the instructions for building the executable.

forthebadge

GitHub followers

GitHub

About

This is the simple game of 'Tic Tac Toe' also known as 'Noughts & Crosses' which one can play against the computer that is equipped with several AI algorithms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages