Sign in

    moonqipai

    Unified board & card game rules foundation for MoonBit: Go, Xiangqi, Chess, Gomoku, Othello, Blackjack, Five-card Draw and UNO behind one interface, with shared GameInfo/Rng abstractions

    board-game
    card-game
    go
    weiqi
    baduk
    xiangqi
    chess
    poker
    rules-engine
    sgf
    gtp
    Download zip
    Author
    Version
    0.3.1
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    27

    #moonqipai

    Unified board & card game rules foundation for MoonBit: eight games behind shared abstractions — Go, Xiangqi (Chinese chess), International Chess, Gomoku, Othello, Checkers, Blackjack, Five-card Draw and UNO.

    This is a reusable infrastructure library, not a game. It gives tool builders — GUI clients, tournament servers, teaching software, AI harnesses, data pipelines — one consistent model for rules adjudication, legal-action enumeration, undo, hidden-information views and result reporting across games.

    #Game coverage

    GamePackageImplementationType
    Go (Weiqi/Baduk)core enginedelegated to wbgxiaosu/moonbadukturn-based, perfect info
    Xiangqi (Chinese chess)core enginedelegated to wbgxiaosu/xiangqiturn-based, perfect info
    International chesscore enginedelegated to L76148/moonchessturn-based, perfect info
    Gomoku (free-style)gomokuoriginal — 2..=26 boards, four-direction line scan, undoturn-based, perfect info
    Othello (Reversi)othellooriginal — eight-direction bracketing flips, pass flow, majority scoringturn-based, perfect info
    Blackjackblackjackoriginal — seeded shoe, dealer hole card hidden, 3:2 naturals, dealer-stands-on-17chance + hidden info
    Five-card drawfivedraworiginal — 2..=6 players, two betting rounds, discards, showdownchance + hidden info + multi-player
    Checkers (English draughts)checkersoriginal — mandatory captures, jump chains, crowning, kingsturn-based, perfect info
    UNOunooriginal — 108-card deck, action cards, colour choice, draw-window discipline, 2..=8 playerschance + hidden info + multi-player
    Generic poker evaluationcardsoriginal — 52-card deck, seeded splitmix64 shuffle, 5..7-card hand evaluationutilities

    Six of the nine entries (plus all shared abstractions) are original code written for this project; the three classical board-game rule cores are delegated to published mooncakes packages instead of being reimplemented.

    #Shared abstractions

    • core.Engine — one facade for all five board games (Go, Xiangqi, chess, Gomoku, Othello): apply / legal_moves / undo / turn / is_over / outcome / render, with per-game native notation (GTP vertices, ICCS, UCI, coordinates).
    • core.GameInfo — structural metadata in the spirit of OpenSpiel's game type: player-count range, perfect/imperfect information, chance involvement, sequential turns. Tools branch on this instead of hard-coding rules.
    • core.Rng — seeded splitmix64 source; every chance-driven game is fully reproducible from its seed.
    • Hidden information — engines only expose what the acting player may see: blackjack hides the dealer hole card until settlement, five-card draw exposes hands solely through hand_of(seat) for the seat's owner and publishes a textual action log for everyone else.
    • Outcome — normalised terminal results with record strings ("1-0") and game-conventional margins ("B+24.5"), plus structured settlement (payout multipliers in blackjack, pot collection in five-card draw).

    #Usage

    // one interface for all board games
    let c : @core.Engine = @core.Engine::make(@core.Chess)
    let _ = c.apply("e2e4")
    let moves : Array[String] = c.legal_moves()

    // original gomoku
    let g : @gomoku.Gomoku = @gomoku.Gomoku::standard()
    let _ = g.play(7, 7)

    // blackjack with a reproducible shoe
    let bj : @blackjack.Blackjack = @blackjack.Blackjack::new(42UL)
    let _ = bj.act(@blackjack.Hit)

    // complete five-card draw hand, 2..=6 players
    let p : @fivedraw.DrawPoker = @fivedraw.DrawPoker::new(4, 7UL)
    let _ = p.bet(0, @fivedraw.Call)

    See cmd/main for a runnable example of every game family. The example binary is documentation only — the deliverable is the library.

    #Building and testing

    moon check moon test moon run cmd/main

    CI runs moon check and moon test on the wasm, wasm-gc and native backends.

    #Roadmap

    • more card games on the shared betting skeleton (stud, hearts);
    • simultaneous-action and repeated-play metadata extensions to GameInfo;
    • backgammon on the seeded-Rng chance model.

    #Scope statement

    moonqipai is an original MoonBit codebase. The Go, Xiangqi and chess rule cores are delegated to the published mooncakes packages listed above (moonbaduk and xiangqi by the same author; moonchess by L76148, Apache-2.0) — moonqipai's contribution is the unified engine layer (now covering all five board games), the normalised outcome model, the GameInfo/Rng abstractions, the poker utilities and five fully original game engines (gomoku, othello, checkers, blackjack, five-card draw, UNO). Rules semantics follow the public SGF FF[4], GTP v2, ICCS, UCI, FIDE/Xiangqi rule documents and standard casino rules.