{"id":17228501,"url":"https://github.com/lazocoder/tic-tac-toe","last_synced_at":"2025-02-24T11:31:21.815Z","repository":{"id":44577739,"uuid":"73644122","full_name":"LazoCoder/Tic-Tac-Toe","owner":"LazoCoder","description":"An unbeatable game of Tic Tac Toe.","archived":false,"fork":false,"pushed_at":"2017-03-15T00:09:07.000Z","size":558,"stargazers_count":77,"open_issues_count":1,"forks_count":42,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-08T10:27:50.144Z","etag":null,"topics":["ai","alpha-beta-pruning","artificial-intelligence","game","minimax","unbeatable","unbeatable-game"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LazoCoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-13T21:27:40.000Z","updated_at":"2023-02-27T12:03:29.000Z","dependencies_parsed_at":"2022-09-07T07:40:15.864Z","dependency_job_id":null,"html_url":"https://github.com/LazoCoder/Tic-Tac-Toe","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazoCoder%2FTic-Tac-Toe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazoCoder%2FTic-Tac-Toe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazoCoder%2FTic-Tac-Toe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazoCoder%2FTic-Tac-Toe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LazoCoder","download_url":"https://codeload.github.com/LazoCoder/Tic-Tac-Toe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219845002,"owners_count":16556452,"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":["ai","alpha-beta-pruning","artificial-intelligence","game","minimax","unbeatable","unbeatable-game"],"created_at":"2024-10-15T04:44:18.425Z","updated_at":"2024-10-15T04:44:18.969Z","avatar_url":"https://github.com/LazoCoder.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tic-Tac-Toe\nAn unbeatable game of Tic Tac Toe. The AI uses a tweaked \u003ca href=\"https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning\"\u003eAlpha-Beta Pruning\u003c/a\u003e algorithm for the decision making.\n\n# Gameplay\n\nThe AI cannot be defeated. Every game either ends in a draw or the AI winning.\n\n![alt-tag](gifs/sample_game.gif)\n\n# What I Learned\n\n## Alpha-Beta Pruning has a \"Flaw\"\n\nVanilla Alpha-Beta Pruning sometimes leads to unexpected results such as the following:\n\n![alt-tag](gifs/AB_pruning_vanilla.gif)\n\nYou can see in the above gif that the AI could have won by playing an *O* in the bottom left corner but it instead chose the middle cell in the first column. This may seem a little strange but no matter what move I choose afterwards, it still wins.\n\nWhat I found was that even though Alpha-Beta Pruning based AI plays perfect games, occassionally it chooses to make a move where the outcome will be a slower victory or a quicker loss. By tweaking the algorithm a little bit and including search depth in its board evaluation I was able to get it to always choose the quickest victory or the slowest loss.\n\nThe following is what the tweaked Alpha-Beta Pruning algorithm does:\n\n![alt-tag](gifs/AB_pruning_tweaked.gif)\n\nAs you can tell, this time it chooses the path of quickest victory.\n\n## Quantity of Boards Evaluated\n\nWhen using a regular MiniMax algorithm the AI checks **59,704** possible board combinations for its first move (this number obviously decreases throughout the game as less cells are available). The Alpha-Beta Pruning on the other hand brings this number down to **2,337**. Adding the tweak that I mentioned above brings the number up slightly to **2,787**. This increase is miniscule in comparison to the advantages that the algorithm brings to the table.\n\n# Instructions\nAfter downloading, navigate into the folder that contains the packages *ArtificalIntelligence*, *Assets*, *TicTacToe*, and *Results.txt*. Then type the following commands to run the game in Window mode:\n```\njavac Window.java\njava TicTacToe.Window\n```\nTyping in any parameter will run the game in Player vs. Player mode. Example:\n```\njava TicTacToe.Window -pvp\n```\nTo run the game in the console, without a GUI, type:\n```\njava TicTacToe.Console\n```\nThe console version takes in the player input by index. This means that to select position (1, 1), the index would be 4 since it is the 5th square but we are using zero based indexing.\n\n![alt-tag](gifs/sample_game_console.png)\n\nConsole mode does not support Player vs. Player.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazocoder%2Ftic-tac-toe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flazocoder%2Ftic-tac-toe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazocoder%2Ftic-tac-toe/lists"}