This project implements a console-based Tic-Tac-Toe game where the player competes against an agent. The game dynamically updates the board, checks for winners, and ensures valid moves.
The agent uses a Minimax algorithm to determine the best move. It will be always playing as 'O', while the player plays as 'X'. The agent evaluates all possible moves and chooses the one that maximizes its chances of winning while minimizing the player's chances.
The agent will play the move that minimizes the score.
- Agent win: -10 + depth
- Agent tie: 0
- Player win: 10 - depth
Note that by using this, the smallest value will be the best chance for the agent winning. Using this scoring system turns the agent into a better player if compared to an agent that only uses -1,0,1 as scores.
- A C++ compiler (e.g., g++, clang++).
Clone or Download: Ensure all required files (Source.cpp, Board.cpp, Board.h, Bot.cpp, Bot.h, Node.cpp, Node.h) are in the same directory.
If you want to install the game to your local bin, you can use the following commands:
./install.shAfter the intallation, you can run the game from anywhere in your terminal by simply typing:
tttTo see the help message, you can run:
ttt -hCompile the Program:
./compile.shThis script compiles the source files into an executable named TicTacToe.
Run:
./TicTacToeTo see the help message, you can run:
./TicTacToe -h- Start the game, and the board will be displayed.
- Enter your move from 1 to 9 corresponding to the board positions:
1 | 2 | 3 --------- 4 | 5 | 6 --------- 7 | 8 | 9 - The agent will make its move after yours.
- The game continues until a player wins or the board is full (resulting in a tie).
- The game will announce the winner or if it's a tie.
- Invalid moves are ignored.