{"id":20812232,"url":"https://github.com/curegit/reversi-ai-dll","last_synced_at":"2025-12-24T12:17:49.385Z","repository":{"id":135783778,"uuid":"157516412","full_name":"curegit/reversi-ai-dll","owner":"curegit","description":"Heuristic Reversi AI implemented as a Windows native DLL","archived":false,"fork":false,"pushed_at":"2025-04-10T06:06:22.000Z","size":884,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-10T21:47:47.582Z","etag":null,"topics":["classical-ai","console","dynamic-link-library","ffi","game-ai","reversi","visual-cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/curegit.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-14T08:32:34.000Z","updated_at":"2025-04-10T05:17:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0cb3cff-e22d-4d02-81a9-ef88d2c14839","html_url":"https://github.com/curegit/reversi-ai-dll","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/curegit/reversi-ai-dll","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Freversi-ai-dll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Freversi-ai-dll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Freversi-ai-dll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Freversi-ai-dll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curegit","download_url":"https://codeload.github.com/curegit/reversi-ai-dll/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Freversi-ai-dll/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28002295,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["classical-ai","console","dynamic-link-library","ffi","game-ai","reversi","visual-cpp"],"created_at":"2024-11-17T20:51:23.262Z","updated_at":"2025-12-24T12:17:49.379Z","avatar_url":"https://github.com/curegit.png","language":"C++","readme":"# Reversi AI DLL\r\n\r\nHeuristic Reversi AI implemented as a Windows native DLL\r\n\r\nThis AI uses heuristic algorithms to determine the most effective move in any given scenario within a game of Reversi, also known as Othello.\r\nIt is designed with efficiency, speed, and complexity in mind, capable of making intricate decisions based on the current state of the game board.\r\n\r\nA ported version of this project is also available in Rust: \u003chttps://github.com/curegit/reversi-ai\u003e.\r\n\r\n## Features\r\n\r\n- Simple API using only primitive types for effortless FFI\r\n- Easily callable from C#, Python, etc.\r\n- Multithread supported\r\n- Moderate AI Strength\r\n\r\n## Dependencies\r\n\r\nYou may need Microsoft Visual C++ Redistributable to use `ReversiAiDll.dll`.\r\n\r\n- KERNEL32.dll\r\n- MSVCP140.dll\r\n- VCRUNTIME140.dll\r\n- api-ms-win-crt-heap-l1-1-0.dll\r\n- api-ms-win-crt-runtime-l1-1-0.dll\r\n\r\n## API\r\n\r\nThe DLL has simple API.\r\nFor instance, a board state is given, the API function returns a move you should choose next.\r\n\r\n### Bit Board\r\n\r\nBit Board is expression of a Reversi board.\r\nBy Bit Board, a board state is expressed by a pair of 64-bit unsigned integers.\r\nThey each have bit flags where each players' disks are placed.\r\nFor example, an initial board of Reversi is expressed like `0x0000_0008_1000_0000` and `0x0000_0010_0800_0000`.\r\n\r\n### Functions\r\n\r\n#### int heuristic_search(unsigned long long self, unsigned long long opponent, int depth)\r\n\r\nReturns an approximately good move that `self` player should do next by doing a partial search.\r\n\r\n`self` and `opponent` are Bit Board.\r\n`depth` is anticipation steps the same as the depth of recursion.\r\nIt must be positive.\r\nThe returned value is a bit number expressing a disk position.\r\nThe bit number is 0 to 63.\r\nSearch time depends on the depth of recursion.\r\n\r\n#### int heuristic_search_parallel(unsigned long long self, unsigned long long opponent, int depth)\r\n\r\nThe multithreaded version of `heuristic_search`.\r\n\r\nIt's faster than the non-multithreaded version in most cases if the CPU is good enough for parallel calculation.\r\n\r\n#### int heuristic_search_parallel_with(unsigned long long self, unsigned long long opponent, int depth, int concurrency)\r\n\r\nSame as `heuristic_search_parallel` except you can specify the number of threads.\r\n\r\n#### int full_search(unsigned long long self, unsigned long long opponent)\r\n\r\nReturns the best move that `self` player should do next by doing a full search.\r\n\r\nThis can be used if the game is in its final stages.\r\n`self` and `opponent` are Bit Board.\r\nThe returned value is a bit number expressing a disk position.\r\nThe bit number is 0 to 63.\r\n\r\n#### int full_search_parallel(unsigned long long self, unsigned long long opponent)\r\n\r\nThe multithreaded version of `full_search`.\r\n\r\nIt's faster than the non-multithreaded version in most cases if the CPU is good enough for parallel calculation.\r\n\r\n#### int full_search_parallel_with(unsigned long long self, unsigned long long opponent, int concurrency)\r\n\r\nSame as `full_search_parallel` except you can specify the number of threads.\r\n\r\n#### int choose_move(unsigned long long self, unsigned long long opponent)\r\n\r\nReturns a move that `self` player should do next.\r\n\r\nThis function is a wrapper of `heuristic_search` and `full_search`.\r\nIt switches between them considering search time.\r\n`self` and `opponent` are Bit Board.\r\nThe returned value is a bit number expressing a disk position.\r\nThe bit number is 0 to 63.\r\nSearch time will be less than a few seconds usually.\r\n\r\n#### int choose_move_parallel(unsigned long long self, unsigned long long opponent)\r\n\r\nThe multithreaded version of `choose_move`.\r\n\r\nThanks to speeding up by parallel calculation, this function tries to search deeper than the non-multithreaded version.\r\nMoreover, it switches to full search earlier.\r\nUse this multithreaded version instead to make AI stronger.\r\n\r\n#### int choose_move_parallel_with(unsigned long long self, unsigned long long opponent, int concurrency)\r\n\r\nSame as `choose_move_parallel` except you can specify the number of threads.\r\n\r\n#### int position_to_index(int i, int j)\r\n\r\nReturns a bit number from a horizontal position and a vertical position.\r\n\r\n`i` and `j` are 0 to 7.\r\nThe returned bit number is 0 to 63.\r\n\r\n#### unsigned long long position_to_bit(int i, int j)\r\n\r\nReturns a 64-bit unsigned integer having a one-bit flag at a given board position.\r\n\r\n`i` and `j` are 0 to 7.\r\nThis function can be used to compose a Bit Board from other data types.\r\n\r\n#### int index_to_position_i(int n)\r\n\r\nReturns a horizontal position from a bit number.\r\n\r\nThe bit number is 0 to 63.\r\nThe returned index is 0 to 7.\r\nUse this function for the conversion of a bit number as AI result, to a disk position.\r\n\r\n#### int index_to_position_j(int n)\r\n\r\nReturns a vertical position from a bit number.\r\n\r\nThe bit number is 0 to 63.\r\nThe returned index is 0 to 7.\r\nUse this function for the conversion of a bit number as AI result, to a disk position.\r\n\r\n[See all functions (Header file)](ReversiAiDll/ReversiAiDll.h)\r\n\r\n## Use with Unity\r\n\r\n### Import the DLL\r\n\r\nCopy each DLL of target architectures into an architecture-specified plugin folder inside of `Assets`.\r\n\r\n- Win32 DLL into `Plugins/x86`\r\n- x64 DLL into `Plugins/x86_64`\r\n\r\nConfigure platform settings of the DLLs in Inspector to enable them in Editor for debugging (Windows only).\r\n\r\n### Coding\r\n\r\nFirst, import `System.Runtime.InteropServices` namespace for calling DLL functions.\r\n\r\n```cs\r\nusing System.Runtime.InteropServices;\r\n```\r\n\r\nNext, import external functions from the DLL.\r\n\r\nDefine static methods with the `extern` modifier and `DllImport(\"ReversiAiDll\")` attribute.\r\nDeclare them with the same names as DLL functions, or indicate function names to be imported by the `EntryPoint` parameter of `DllImport`.\r\nMake sure their type signatures match.\r\nIt is not necessary to use the same parameter names.\r\n\r\n```cs\r\n[DllImport(\"ReversiAiDll\")]\r\nprivate static extern int index_to_position_i(int n);\r\n\r\n[DllImport(\"ReversiAiDll\")]\r\nprivate static extern int index_to_position_j(int n);\r\n\r\n[DllImport(\"ReversiAiDll\")]\r\nprivate static extern ulong position_to_bit(int i, int j);\r\n\r\n[DllImport(\"ReversiAiDll\", EntryPoint = \"choose_move_parallel\")]\r\nprivate static extern int ChooseMove(ulong self, ulong opponent);\r\n```\r\n\r\nNow these functions are able to be called.\r\n\r\nFinally, write codes that call AI functions.\r\n\r\n```cs\r\n// Prepare Bit Boards from collections of disk positions\r\nulong self = darkPositions.Aggregate(0ul, (a, p) =\u003e a | position_to_bit(p.x, p.y));\r\nulong opponent = lightPositions.Aggregate(0ul, (a, p) =\u003e a | position_to_bit(p.x, p.y));\r\n\r\n// Use AI to decide the next move\r\nint decision = ChooseMove(self, opponent);\r\n\r\n// Extract answers\r\nint x = index_to_position_i(decision);\r\nint y = index_to_position_j(decision);\r\n```\r\n\r\nIt takes a few seconds for AI to return an answer, so please use asynchronous methods.\r\n\r\n## Unity Application\r\n\r\nAn illustrative Unity application (binary build) is available on [the release page](https://github.com/curegit/reversi-ai-dll/releases/latest).\r\n\r\n![Unity Reversi](Unity.png)\r\n\r\n## Console Application\r\n\r\nThis solution also includes a Windows console application to try on the AI.\r\n\r\n### Usage\r\n\r\n`ReversiConsole.exe [dark|light]`\r\n\r\nThe positional argument is your side.\r\nIt is dark by default.\r\n\r\n![Console Reversi](Console.png)\r\n\r\n## License\r\n\r\n[Apache License 2.0](LICENSE)\r\n\r\nCopyright (C) 2025 curegit\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuregit%2Freversi-ai-dll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuregit%2Freversi-ai-dll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuregit%2Freversi-ai-dll/lists"}