There are 2 files, that are used in our project. They are: main.py and hum_rob.py. The first file is designed to be played by two people, the second - by human and robot.
- Basic conditions:
The file consists of 2 functions: game and victory.
- The game function accepts 4 parameters as input:
This function is designed to handle player's actions. It returns new board, counter, last_move, previous_move.
- The victory function accepts 3 parameters as input:
This function is used to check the move for a victory condition. It returns True, if the last move was victorious, and returns False, if it wasn't.
Here is a table of variables with their descriptions
| param | descrription | type |
| player | which player's move are we considering | str ('X', 'O') |
| board | the current state of the playing field | array |
| counter | counter for the number of moves | int |
| last_move | the ordinal number of the cell that the opponent was in during the last move | int |
| previous_move | the ordinal number of the cell that the player made a move to during the last move | int |
To run the code, just enter the number of the cell to which you want to make a move.
The file consists of 4 functions: game, victory, minimax and optimal_move.
- The game function accepts 4 parameters as input:
This function is designed to handle human actions. It returns board, counter, last_move and previous_move.
- The victory function accepts 3 parameters as input:
This function is used to check the move for a victory condition. It returns True, if the last move was victorious, and returns False, if it wasn't.
- The minimax function accepts 4 parameters as input:
This function is used to evaluate moves for a robot. It returns best_score.
- The optimal_move function accepts 3 parameters as input:
This function is used to select the best action for the robot. It returns best_move.
To understand what each variable is responsible for, I made a table
| param | descrription | type |
| player | which player's move are we considering | str ('X','O') |
| board | the current state of the playing field | array |
| counter | counter for the number of moves | int |
| last_move | the ordinal number of the cell that the opponent was in during the last move | int |
| previous_move | the ordinal number of the cell that the player made a move to during the last move | int |
| is_maximizing | provided that the move in question is made by a human, then among the following values it is necessary to look for the maximum and vice versa | bool |
| depth | you can use this parameter to adjust the complexity of the model. The greater the depth, the more moves the robot calculates in advance, the more difficult it is to play against it | int |
| prev | is the same as previous_move, but it used in functions minimax and optimal_move | int |
To run the code, just enter the number of the cell to which you want to make a move.