{"id":21113378,"url":"https://github.com/edwardchhun/unbeatable-ai-tictactoe","last_synced_at":"2026-07-04T06:03:21.803Z","repository":{"id":228305902,"uuid":"773618057","full_name":"EdwardChhun/Unbeatable-Ai-TicTacToe","owner":"EdwardChhun","description":"Unbeatable Ai Tic Tac Toe Game using Python, this uses a minimax algorithm that ties into game theory. Inspired by lec0 of CS50AI.","archived":false,"fork":false,"pushed_at":"2024-03-25T22:31:41.000Z","size":223,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-21T04:27:54.576Z","etag":null,"topics":["artificial-intelligence","game","machine-learning","minimax-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EdwardChhun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-18T04:50:10.000Z","updated_at":"2024-03-19T22:44:06.000Z","dependencies_parsed_at":"2024-03-25T23:43:04.648Z","dependency_job_id":null,"html_url":"https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe","commit_stats":null,"previous_names":["edwardchhun/unbeatable-ai-tictactoe"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EdwardChhun%2FUnbeatable-Ai-TicTacToe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EdwardChhun%2FUnbeatable-Ai-TicTacToe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EdwardChhun%2FUnbeatable-Ai-TicTacToe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EdwardChhun%2FUnbeatable-Ai-TicTacToe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EdwardChhun","download_url":"https://codeload.github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243558484,"owners_count":20310574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","game","machine-learning","minimax-algorithm"],"created_at":"2024-11-20T01:43:13.726Z","updated_at":"2025-10-28T14:46:23.380Z","avatar_url":"https://github.com/EdwardChhun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unbeatable AI Tic Tac Toe\n\nWelcome to Unbeatable AI Tic Tac Toe! This is a Tic Tac Toe game played on an external window using [PyGame's](https://www.pygame.org/docs/) GUI feature where you can play against an unbeatable AI opponent. The AI uses the [Minimax algorithm](https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-1-introduction/) to determine its moves, ensuring that the computer plays optimally and never loses. Keep in mind, that this program makes X go first.\n\n## How to Play\n\n1. Clone or download this repository to your local machine.\n2. Open a terminal or command prompt.\n3. Navigate to the directory where you cloned or downloaded the repository.\n4. Run the `runner.py` file with Python 3 to start the game:\n    ```bash\n    python runner.py\n    ```\n5. Follow the prompts to choose whether you'd want to play as \"X\" or \"O\".\n6. Make your moves by pressing in either box on the GUI.\n7. Watch as the AI opponent makes its moves.\n8. The game ends when one player wins or the board is full (a tie).\n\n## Features\n\n- **Unbeatable AI**: The AI opponent uses the Minimax algorithm to ensure optimal gameplay. It analyzes all possible future moves to make the best decision each turn.\n- **Interactive Gameplay**: The game provides an interactive interface where players can move by using their pointer.\n- **Tie Detection**: The game detects ties when the board is full and declares a tie if there's no winner.\n- **Player Choice**: Players can choose to play as \"X\" or \"O\" at the start of the game.\n\n## Requirements\n\n- Python 3.x\n- PyGame\n\n# Install Requirements\n- Run this in your console\n```\npip3 install -r requirements.txt\n```\n\n## Implementation Details\n\n- The game is implemented in Python.\n- The AI opponent uses the Minimax algorithm, a recursive algorithm commonly used in two-player games like Tic Tac Toe and chess, to determine the best moves.\n- The game state is represented by a 3x3 grid, with each cell either empty, \"X\", or \"O\".\n\n## Future Improvements\n\n- Video Demo\n- Difficulty Levels: Add options for different difficulty levels, allowing players to choose the AI's playing strength.\n- Online Multiplayer: Implement online multiplayer functionality to allow players to compete against each other over the internet.\n- Faster optimization for computer, implementing Depth-Limited Minimax Algorithm.\n- Make X always start in the middle, we know it's the best move.\n  \n## Credits\n\n- The Minimax algorithm implementation for the AI opponent is based on concepts from artificial intelligence and game theory.\n- Developed by Edward Chhun.\n- Inspired by [CS50AI](https://cs50.harvard.edu/ai/2024/), Introduction to AI with Python 2024\n\n## Questions\n\n- If there are any questions or if you need any help, contact [Edwardchhun3@gmail.com]\n\n## Screenshots\n\n![Main Window](https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/blob/main/images/play-ttt.png)\n![Play as O](https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/blob/main/images/play-O.png)\n![Computer Thinking](https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/blob/main/images/ttt-computer-thinking.png)\n![Tie](https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/blob/main/images/ttt-tie.png)\n![X Wins](https://github.com/EdwardChhun/Unbeatable-Ai-TicTacToe/blob/main/images/ttt-X-Wins.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedwardchhun%2Funbeatable-ai-tictactoe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedwardchhun%2Funbeatable-ai-tictactoe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedwardchhun%2Funbeatable-ai-tictactoe/lists"}