{"id":28778639,"url":"https://github.com/thyeem/bcf_ai","last_synced_at":"2025-06-25T07:33:11.078Z","repository":{"id":82386669,"uuid":"135244232","full_name":"thyeem/bcf_ai","owner":"thyeem","description":"Created my own game and its AIs as well","archived":false,"fork":false,"pushed_at":"2024-06-05T09:35:49.000Z","size":3659,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-06T02:04:02.219Z","etag":null,"topics":["game","gomoku-ai","gomoku-game","minimax-alpha-beta-pruning","monte-carlo-tree-search","mtcs","uct-bandit"],"latest_commit_sha":null,"homepage":"","language":"C++","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/thyeem.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":"2018-05-29T05:14:06.000Z","updated_at":"2024-06-05T09:35:53.000Z","dependencies_parsed_at":"2023-12-22T21:00:53.405Z","dependency_job_id":null,"html_url":"https://github.com/thyeem/bcf_ai","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thyeem/bcf_ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thyeem%2Fbcf_ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thyeem%2Fbcf_ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thyeem%2Fbcf_ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thyeem%2Fbcf_ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thyeem","download_url":"https://codeload.github.com/thyeem/bcf_ai/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thyeem%2Fbcf_ai/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260400621,"owners_count":23003440,"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":["game","gomoku-ai","gomoku-game","minimax-alpha-beta-pruning","monte-carlo-tree-search","mtcs","uct-bandit"],"created_at":"2025-06-17T16:42:28.696Z","updated_at":"2025-06-25T07:33:11.068Z","avatar_url":"https://github.com/thyeem.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"BCF Game and its AI gaming\n===\n\n## What\n\n![dsfsdf](media/demo_neo.gif)\n\nBCF stands for **B**itten **C**onnect-**F**ive and I created this game — in fact, just a variation on a East-Asian board game, \"Gomoku\" or \"Five-in-a-row\" — to make [Gomoku](https://en.wikipedia.org/wiki/Gomoku) a more complex rule. (In reality, sometimes Gomoku make us feel a little boring compared to its complexity of the game tree.) I just wanted a game that people could learn and enjoy time easily but not spending much time like [Go](https://en.wikipedia.org/wiki/Go_(game)).\n\nI named it BCF, but it is actually closer to [Gomoku](https://en.wikipedia.org/wiki/Gomoku) rather than [Connect Five](https://en.wikipedia.org/wiki/Connect_Four). I just added some basic rules into the Gomoku so that I made it more complicated.\n\n\n\n## How to build \n\n```bash\n$ git clone https://github.com/thyeem/bcf_ai\n$ cd bcf_ai\n\n# there's almost no dependencies on other libs. \n# Here, 'ncurses' is the only external library used.\n\n$ make\n$ ./bcf_ai\n\n# or simply build and run at the same time\n$ make run\n```\n\n\n\n## Rule\n\nIn [Gomoku](https://en.wikipedia.org/wiki/Gomoku), a player who firstly makes five stones in a row in any direction wins. (not broken chain of five stones in horizontal, vertical, or diagonal direction) In addition to this, I defined two simple basic rules below:\n\n* If your last move can clamp your opponent's *two successive* stones, you can capture them. Multi-directional capturing is possible with a move so theretically, up to 16 captures are possible with only a move.\n\n* 10 points (10 captured stones) are equivalent to \"the five stone in a row\", meaning firstly winning 10 points is a victory. \n\n\n\n## BCF AIs: Sofiai and Mariai\n\nI implemented two game AIs for BCF, called **Sofiai** and **Mariai**. Very weird name, but it originated from my two daughters, Sofia and Maria. (Sofiai = Sofia + AI, and Mariai = Maria + AI. Blame my naming skills :$)\n\nFor now, my second princess Maria is much, much stronger, but that does not mean I love her more. ;-)\n\nI'd like to highlight a few backgrounds of **Sofiai** and **Mariai**.\n\n\n* [Minimax algorithm](https://en.wikipedia.org/wiki/Minimax) was used in **Sofiai**. By default, Sofiai tries to search only 4-depth (4 plies). It's because that the ponding time would grow exponentially if we increase the depth of searching tree a little. With `~30` of branching factor, the depth of this level is the threshold of a typical PC.\n* [MTCS (Monte-Carlo Tree Search)](https://en.wikipedia.org/wiki/Monte_Carlo_tree_search) and [UCT(Upper Confidence Bound applied to trees)](https://www.chessprogramming.org/UCT) method was used in **Mariai**. \n  That is, simply, each step of MCTS *1)select*, *2)expand*, *3)play-out (simulation)*, *4)update (backpropagation)* of the game tree is governed by the exploitation(doing more searches promising, *Q-value*) and the exploration(doing searches not frequently explored, *visit count N*).\n* With the full tree search of 4-depth, **Sofiai** is quite fast and responsive, coping well with near futures, but not looking far ahead like **Mariai**.\n* Right after Mariai's move, the *EWP(Estimated Winning Probability)* is updated. It indicates Mariai's odds, winning probability obtained by the most promising move (the most visited node in the game tree) throughout the play-outs. If Mariai's overall situation becomes better after a move, it will be increasing, otherwise, it will be dropped.\n  \n\nAll the configurable parameters are defined in `common.h` such as *UCB constants*, *self-playout number* and *node expansion threshold* when searching trees at expansion stage (refer to `common.h`)\n\nOne can even change the given *board size (default: 19x19)*, *winning point (default: 10)*, and *BCF mode (default: 1)*. Those are because I was very curious how much it would affect the winning probabilities among the AIs from each different algorithm. \n\nTurning on \"*BCF mode*\" means literally to use the definition of BCF gaming rule. If you turn off the flag, you can enjoy game with the original rule, Gomoku!\n\nWhen entering the game, one can access each gaming mode with shortcuts (`1`,` 2`, .. and `q`) as shown below.\n\n![game intro](media/bcf_game.png)\n\n\n\n## Todo\n\nWhen playing with Mariai, long ponding time due to 1-million playouts is a little bit annoying (moreover, I did not introduce any parallel MCTS). One of big problems when searching BCF game tress is the huge *branching factor(b)* of `~20` and *average game length(d)* of `30 ~ 40`. Roughly, the game-tree complexity of `20^30 ~ 20^40 = 1e39 ~ 1e52` is gigantic indeed and it is comparable to Chess. (*Chess* is known as ~`1e47` and *Go* is `~1e170`)  \n\n___Altough **Mariai** seems to be already beyond competent human players___, guessing next candidate moves well (*reduction of branching factor*) and estimating the current state or score better (*reduction of search depth*) are still challenging and a lot of room for improvement. So I decided to introduce neural networks here. I am not going to use the supervised training method because, as you know, there's no history or good game logs related to this game. Rather, now I am working on the reinforce training to do this. \n\nIt would be the first BCF engine with no human-provided knowledge like AlphaGo-zero and Leela-zero.  \nIt also would be fun and great if we can compare moves from the ___BCF-zero___ with moves from ***Mariai***.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthyeem%2Fbcf_ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthyeem%2Fbcf_ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthyeem%2Fbcf_ai/lists"}