This is an implementation of the classic tic tac toe game in Python. The game can be played on the command line. Instructions for how to play are written below.
The computer side for the tic tac toe game uses the minimax algorithm to calculate the next best move. The pseudocode used to do this is below.
Additionally, I have implemented the tic tac toe game using alpha beta pruning, with the following pseudocode.
To run the program, you must use the command line. The program accepts 3 command line arguments, so the code can be executed with
python cs480_P01_AXXXXXXXX.py ALGO FIRST MODE
where:
■ cs480_P01_AXXXXXXXX.py is your python code file name,
■ ALGO specifies which algorithm the computer player will use:
◆ 1 – MiniMax,
◆ 2 – MiniMax with alpha-beta pruning,
■ FIRST specifies who begins the game:
◆ X
◆ O
■ MODE is mode in which your program should operate:
◆ 1 – human (X) versus computer (O),
◆ 2 – computer (X) versus computer (O)
Example:
python cs480_P01_A11111111.py 2 X 1
The above command will run the program with the minimax alpha beta pruning algorithm where the player who begins the game is X and the mode is human versus computer.
If the number of arguments provided is NOT three (none, one, two or more than three) or arguments are invalid (incorrect ALGO, FIRST or MODE) the program displays the following error: ERROR: Not enough/too many/illegal input arguments. and exits.
■ The Tic-Tac-Toe game board is represented by 3 x 3 grid with cells numbered as follows
■ Possible moves/actions for both players match cell numbers (if a player wants to place an ‘X’ in the middle of the board, the move/action is ‘5’,