majiang_algorithm
High-performance Mahjong win detection, waiting-hand calculation and AI discard algorithm based on lookup tables, with behavior-identical Java / Go / C++ implem
What is majiang_algorithm?
High-performance Mahjong win detection, waiting-hand calculation and AI discard algorithm based on lookup tables, with behavior-identical Java / Go / C++ implementations and a live web demo.
Overview of majiang_algorithm
What it is
majiang_algorithm is a high-performance Mahjong win detection, waiting-hand calculation and AI discard algorithm based on lookup tables. It provides three behavior-identical implementations in Java, Go, and C++17, all sharing the same pre-computed lookup tables under the data/ directory. The project also includes a live web demo and a FakeLua-based web battle server.
Key features
- Win detection: millisecond-level check for winning hands, supports any number of wildcard tiles
- Waiting-hand calculation: quickly lists all tiles that complete the current hand
- AI discard: score-model-driven auto decision for discarding, ponging, and konging
- Lookup table: offline pre-computation; runtime does hash lookups only — extremely fast
- Full tile coverage: Characters (Wan), Circles (Tong), Bamboo (Tiao), Wind tiles (East/South/West/North), Arrow tiles (Zhong/Fa/Bai)
- Three implementations: Java, Go and C++17 load the same lookup tables; 2000+ fixed-seed deals are replayed by every CI to pin identical behavior (including bit-exact scores)
Use cases
This library is suitable for building Mahjong game engines, AI opponents, or analysis tools that require fast and accurate win detection, waiting-hand enumeration, and discard decision-making. It can be integrated into Java, Go, or C++ projects, and the web server provides a ready-to-use multiplayer platform.
Getting started
See the repository README for detailed instructions on Maven dependency, Go module import, C++ CMake build, and table generation commands.
License and pricing
License: MIT. Pricing: open source (free).
這是什麼
majiang_algorithm 是一個高效能的麻將胡牌偵測、聽牌計算與 AI 出牌演算法,基於查表技術。它提供 Java、Go 與 C++17 三種行為完全一致的實作,共用 data/ 目錄下的預先計算查表。專案同時包含一個即時網頁展示與基於 FakeLua 的網頁對戰伺服器。
主要功能
- 胡牌偵測:毫秒級檢查手牌是否胡牌,支援任意數量的花牌
- 聽牌計算:快速列出所有能讓當前手牌胡牌的牌
- AI 出牌:基於分數模型的自動出牌、碰牌與槓牌決策
- 查表技術:離線預先計算,執行時僅進行雜湊查詢,速度極快
- 完整牌型覆蓋:萬、筒、條、風牌(東南西北)、箭牌(中發白)
- 三種實作:Java、Go 與 C++17 載入相同查表;2000 多個固定種子牌局由每個 CI 重播以確保行為一致(包含位元精確的分數)
使用情境
此函式庫適用於建構麻將遊戲引擎、AI 對手或分析工具,需要快速且準確的胡牌偵測、聽牌列舉與出牌決策。它可以整合到 Java、Go 或 C++ 專案中,而網頁伺服器則提供一個可直接使用的多人平台。
快速開始
請參閱儲存庫 README 以取得 Maven 依賴、Go 模組匯入、C++ CMake 建置與表格產生指令的詳細說明。
授權與價格
授權:MIT。價格:開源(免費)。
Based on the project's public README and repository metadata.