Skip to content

Latest commit

 

History

History
30 lines (30 loc) · 1.86 KB

README.md

File metadata and controls

30 lines (30 loc) · 1.86 KB

Tic-Tac-Toe

Here is the Tic Tac Toe game with an artificial intelligence using "Alpha Beta Purning" algorithm.
This little project has 2 files ("main.py" and "game_class.py") that "main.py" is just a fast test for the main written algorithm ("game_class.py").

main.py

Just run this file by python3 main.py to see how the algorithm works.

game_class.py

Our main code is here.
I declared 7 diffrent classes that are like this:

  • Environment Class
  • Board Class
  • Node Class
  • Nut Class
  • Colors Class

Environment Class

The biggest class in the project.
This class involves the solving algorithm using Alpha Beta Purning.
There are three functions named "start_solve", "maximum" and "minimum" that "start_solve" is a functionality that changes turns between the bot and the player ("maximum" and "minimum" functions are used for decisions that the bot takes).
"maximum" and "minimum" functions returns a value and recursively, "start_solve" function by those values decides what to do next.

Board Class

Board Class is the second biggest class after Environment Class.
This class has a 3x3 dictionary attribute named "nodes" with keys like (x, y) and values of Node object.
Also with printing a board object, you can see the actual graphical autogenerated board and if the game is done, you can see the answer ofcourse.\

Node Class

Just a simple class that has less functions and handles less of the work but has x, y, nut and green attribute.
x and y attributes are the place of the node in nodes attribute of board.
nut can have two diffrent values of Nut Class.

Nut Class

An Enum Class that Used to set Nut.X or Nut.O values on nut attribute of Node class.

Colors Class

An Enum Class that has some color codes used for beauty of Board.