{"id":21938495,"url":"https://github.com/roberthue/mcts-connectfour","last_synced_at":"2026-05-09T17:45:20.886Z","repository":{"id":170963673,"uuid":"91190958","full_name":"RobertHue/MCTS-ConnectFour","owner":"RobertHue","description":"Implementation of an AI in the game Connect-Four using Monte Carlo Tree Search (MCTS) and QT.","archived":false,"fork":false,"pushed_at":"2023-11-01T21:36:31.000Z","size":1480,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T13:50:21.518Z","etag":null,"topics":["ai","cpp","game-connectfour","mcts-algorithm","mcts-connectfour"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobertHue.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":"2017-05-13T17:22:28.000Z","updated_at":"2024-08-05T19:56:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"440fd008-00df-4d53-9d81-4e8594cb28ec","html_url":"https://github.com/RobertHue/MCTS-ConnectFour","commit_stats":null,"previous_names":["roberthue/mcts_connectfour","roberthue/mcts-connectfour"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertHue%2FMCTS-ConnectFour","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertHue%2FMCTS-ConnectFour/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertHue%2FMCTS-ConnectFour/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertHue%2FMCTS-ConnectFour/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobertHue","download_url":"https://codeload.github.com/RobertHue/MCTS-ConnectFour/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244968954,"owners_count":20540231,"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","cpp","game-connectfour","mcts-algorithm","mcts-connectfour"],"created_at":"2024-11-29T01:31:33.426Z","updated_at":"2026-05-09T17:45:15.837Z","avatar_url":"https://github.com/RobertHue.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCTS_ConnectFour\n\n![example workflow](https://github.com/RobertHue/MCTS_ConnectFour/actions/workflows/build_and_test.yml/badge.svg)\n\nImplementation of an Connect-Four AI using the MCTS algorithm.\n\n![mcts-gui](resources/mcts-gui.png)\n\n## Table of contents\n\n- [MCTS\\_ConnectFour](#mcts_connectfour)\n  - [Table of contents](#table-of-contents)\n  - [Pre-requisites](#pre-requisites)\n  - [Compilation](#compilation)\n  - [MCTS-Algorithm](#mcts-algorithm)\n  - [UML-class diagram](#uml-class-diagram)\n  - [GUI-Design](#gui-design)\n  - [Sources and Literature](#sources-and-literature)\n  - [MIT](#mit)\n    - [The MIT License](#the-mit-license)\n\n## Pre-requisites\n\nThe installation pre-requisites are as follows:\n\n- [CMake 3.20](https://cmake.org/download/)\n- [Conan 2.0](https://docs.conan.io/1/installation.html)\n\nAs explained [here](https://doc.qt.io/qt-6/linux-requirements.html), on Linux the xcb platform plugin is used. It provides basic features to run against X11. To install the following development libraries run the following command::\n\n```bash\nsudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-cursor-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-util-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev\n```\n\n## Compilation\n\nTo compile this project with the tests and the game itself execute the following commands:\n\n```bash\nmkdir -p build\ncd build\nconan install .. --output-folder=. --build=missing --profile:build=../conan-profile.txt --profile:host=../conan-profile.txt\ncmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release\ncmake --build . -j 4\n```\n\nTo clean, use the following:\n\n```bash\ncmake --build . --target clean\n```\n\nTo execute the tests do the following:\n\n```bash\n../bin/MCTS_ConnectFour_tests\n```\n\nTo execute the game do the following:\n\n```bash\n../bin/MCTS_ConnectFour\n```\n\nTo clear all the whole conan cache, use the following command:\n\n```bash\n../bin/MCTS_ConnectFour\n```\n\n\n## MCTS-Algorithm\n\nThe algorithm works by finding the next best move the AI can do.\nIt does that by book-keeping information about a search tree (here called: game tree).\nThe root of that tree is the enemies turn and current state of the board.\nThe connections from that root to childNodes are the moves the current player can do.\n\nMCTS process:\n\n1. expand all childNodes from the root and assign a very large random initial UCTB-value\n2. Repeat an iteration of Selection, Expansion, Simulation and Backpropagation as many times (here set to 10,000, but a time treshold can be chosen too)\n3. Select an action to perfom (here: most visited robust childNode from root)\n\n\u0026nbsp;\n\u0026nbsp;\n![MCTS](https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/MCTS_%28English%29_-_Updated_2017-11-19.svg/1920px-MCTS_%28English%29_-_Updated_2017-11-19.svg.png)\n\nShows what the iteration in step 2. has to do (from wikipedia with CC BY-SA 4.0 licence).\n\nSteps are explained below:\n\n**Selection:**\n\nThe MCTS tries to traverses through the game tree always following paths with highest UCTB - doesn't matter whether enemy nodes or personal ones, because it needs to take into account that the enemy is also tries to maximize its winrate. This traversal stops, when some unexpanded Leaf-Nodes (L) is found.\n\n**Expansion:**\n\nExpand one or more Leaf-Nodes (L), unless leaf-node L ended the game.\n\n**Simulation:**\n\nSimulate a playout until game ended in a WIN / LOOSE / DRAW.\n\n**Backpropagation:**\n\nIncrease visit count of every node along the followed path until the root node is reached (included) and do the following for those nodes:\n\n- DRAW =\u003e every nodes along the path is increased by Value::DRAW\n- WIN =\u003e every AI node along the path is increased by Value::WIN, whereas every enemy node is increased by Value::LOOSE\n- LOOSE =\u003e every AI node along the path is increased by Value::LOOSE, whereas every enemy node is increased by Value::WIN\n\n## UML-class diagram\n\n![UML-class diagram](resources/UML_class_dia.png)\n\nShows the class structure and assoziation between the classes used. Including signal and slots for the QT-based GUI.\n\n## GUI-Design\n\nIn this project I used a rather simple GUI design consisting of a TableView. When you click in a non-empty column for edit and click somewhere else again, the TableView receives an update and it's going to place your token in that column. When it's not your turn, you cannot place any tokens. The game is stopped when a modal dialog pops up, indicating the winner.\n![GUI design](resources/GUI.PNG)\n\n## Sources and Literature\n\n- \u003chttps://dke.maastrichtuniversity.nl/m.winands/documents/pMCTS.pdf\u003e\n- \u003chttps://de.slideshare.net/ftgaic/mcts-ai\u003e\n- \u003chttp://jeffbradberry.com/posts/2015/09/intro-to-monte-carlo-tree-search/\u003e\n- \u003chttps://en.wikipedia.org/wiki/Monte_Carlo_tree_search\u003e\n\n## MIT\n\n### The MIT License\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberthue%2Fmcts-connectfour","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froberthue%2Fmcts-connectfour","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberthue%2Fmcts-connectfour/lists"}