Skip to content

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.

Notifications You must be signed in to change notification settings

sofibrezden/TicTacToe-OpenCV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tic-Tac-Toe Game with Image Recognition ๐Ÿง ๐Ÿ”

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. ๐Ÿš€

โœจ Features

  • โœ… 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 ๐ŸŽจ

๐Ÿ“Œ Requirements

  • ๐Ÿ Python 3.12
  • ๐Ÿ“ท OpenCV
  • ๐Ÿ”ข NumPy

๐Ÿ”ง Installation

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

Usage

1๏ธโƒฃ Run the main.py script:

python main.py

2๏ธโƒฃ Follow the prompts to select an image to process.

๐Ÿ“‚ Project Structure

  • ๐Ÿ“œ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.

๐Ÿ› ๏ธ Functions

๐Ÿงฉ algo.py

  • 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.

๐ŸŽจ main.py

  • 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.

๐Ÿ“œLicense

This project is licensed under the MIT License. See the LICENSE file for details.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages