This project implements Connect4 and TicTacToe games with various player types, including human, random, algorithmic, minimax, and Q-learning agents.
- Python 3.12 or later
- Required Python packages:
readchar,tqdm
You can install the required packages using pip:
pip install readchar tqdmTo run the Connect4 game, use the following command:
python connect4.py [options]To run the TicTacToe game, use the following command:
python tictactoe.py [options]-p1 <player1>: Set the type of player 1. Default isminimax.-p2 <player2>: Set the type of player 2. Default isalgo.-g <number of games>: Set the number of games to play. Default is1.-d <max depth>: Set the maximum depth for the minimax algorithm. Default is the size of the board.-v: Enable visual mode.-w <width>: Set the width of the board (Connect4 only). Must be between4and9. Default is7.-h <height>: Set the height of the board (Connect4 only). Must be between4and9. Default is6.-train <batches>: Train Q-learning agents for the specified number of batches.-b <batch size>: Set the batch size for training. Default is50000.-s <seed>: Set the random seed for training. Default is a random integer.-o <order>: Set the training order (first,second, orboth). Default isboth.
human: Human player.random: Player that chooses moves randomly.algo: Player that uses a custom algorithm to choose moves.minimax: Player that uses the minimax algorithm to choose moves.minimax_ab: Player that uses the minimax algorithm with alpha-beta pruning.qlearn: Player that uses Q-learning to choose moves.
To play a game between a human and a minimax player:
python connect4.py -p1 human -p2 minimaxTo play a game between a human and a minimax player:
python tictactoe.py -p1 human -p2 minimax -vTo train Q-learning agents for 10 batches with a batch size of 50000:
python connect4.py -train 10 -b 50000To train Q-learning agents for 10 batches with a batch size of 50000:
python tictactoe.py -train 10 -b 50000- The game will display instructions and the board if a human player is involved.
- The Q-learning agents will save their Q-tables after training.
- The Connect4 board size can be customized using the
-wand-hoptions, but must be between4and9for both dimensions.