This project is a Tic-Tac-Toe game that uses image recognition to detect the current state of the game board from an image. It also includes a minimax algorithm to determine the optimal move for the player. ๐
- โ Recognizes the Tic-Tac-Toe board from an image ๐ธ
- โ Detects the current state of the game ๐
- โ Uses the Minimax algorithm to find the best move ๐ค
- โ Draws the game board and the optimal move on the image ๐จ
- ๐ Python 3.12
- ๐ท OpenCV
- ๐ข NumPy
1๏ธโฃ Clone the repository:
git clone https://github.com/sofibrezden/TicTacToe-OpenCV.git
cd TicTacToe-OpenCV
2๏ธโฃ Install the required packages:
pip install -r requirements.txt
1๏ธโฃ Run the main.py script:
python main.py
2๏ธโฃ Follow the prompts to select an image to process.
- ๐
algo.py: Contains the minimax algorithm and game evaluation functions. - ๐
main.py: Contains the main logic for image recognition and game processing. - ๐
Tests: Folder to store the images of Tic-Tac-Toe boards.
isMovesLeft(board): Checks if there are any moves left on the board.evaluate(board): Evaluates the board and returns a score.minimax(board, depth, isMax): Minimax algorithm to find the best move.get_game_status(board): Returns the current status of the game.findBestMove(board): Finds the best move for the player.
draw_board_on_image(image, board): Draws the Tic-Tac-Toe board on the image.draw_move_on_image(image, best_move, cell_height, cell_width, symbol, color): Draws the optimal move on the image.average_angle(line): Calculates the average angle of a line.recognize_tic_tac_toe_board(image_path): Recognizes the Tic-Tac-Toe board from an image.process_images_in_folder(folder_path): Processes all images in the specified folder.
This project is licensed under the MIT License. See the LICENSE file for details.