{"id":48362089,"url":"https://github.com/henrikstephensen/riichi_engine","last_synced_at":"2026-04-11T19:00:37.641Z","repository":{"id":349314946,"uuid":"1201856793","full_name":"HenrikStephensen/riichi_engine","owner":"HenrikStephensen","description":"Pure Ruby 実装のリーチ麻雀エンジン Gem です。局進行、役判定、点数計算を Rails 非依存で提供します。","archived":false,"fork":false,"pushed_at":"2026-04-05T10:47:01.000Z","size":115,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-05T13:02:12.693Z","etag":null,"topics":["gem","mahjong","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/riichi_engine","language":"Ruby","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/HenrikStephensen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-05T09:00:59.000Z","updated_at":"2026-04-05T11:07:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"2b08f4a0-91ee-4a9d-bd04-957bbf250de1","html_url":"https://github.com/HenrikStephensen/riichi_engine","commit_stats":null,"previous_names":["henrikstephensen/riichi_engine"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/HenrikStephensen/riichi_engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikStephensen%2Friichi_engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikStephensen%2Friichi_engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikStephensen%2Friichi_engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikStephensen%2Friichi_engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HenrikStephensen","download_url":"https://codeload.github.com/HenrikStephensen/riichi_engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikStephensen%2Friichi_engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31475202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["gem","mahjong","ruby"],"created_at":"2026-04-05T13:00:29.581Z","updated_at":"2026-04-06T14:00:54.675Z","avatar_url":"https://github.com/HenrikStephensen.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# riichi_engine\n\nPure Ruby 実装のリーチ麻雀エンジン Gem です。\n\n局進行・和了判定・役判定・点数計算・順位計算を Rails・ActiveRecord 非依存で提供します。  \nhost app から `RiichiEngine::API` を呼ぶだけで、麻雀の完全なドメインロジックを利用できます。\n\n---\n\n## 機能\n\n| カテゴリ | 内容 |\n|---|---|\n| 局進行管理 | 牌山構築・配牌・自摸・打牌・鳴き（ポン/チー/カン）・リーチ処理 |\n| 和了判定 | 通常和了形・七対子・国士無双 |\n| 役判定 | 一般役から役満まで全役対応 |\n| 点数計算 | 符・翻の計算、基本点・各プレイヤーへの支払い点算出 |\n| 順位計算 | ウマ・オカを含む最終スコア計算 |\n| CPU AI | Easy / Normal / Hard の3段階（host app 側での切り替え対応） |\n\n---\n\n## ドキュメント\n\n| ドキュメント | 内容 |\n|---|---|\n| [概念・用語集](docs/concepts.md) | 牌記法・麻雀用語・アクション種別の解説 |\n| [使用例](docs/usage_examples.md) | 局開始〜終了までのコード例 |\n| [局ステートマシン](docs/state_machine.md) | フェーズ遷移・アクション優先順位・特殊シーケンスの解説 |\n| [API リファレンス](docs/api_reference.md) | 公開メソッドの詳細仕様 |\n| [公開 API ポリシー](docs/public_api_policy.md) | 安定保証の範囲と方針 |\n| [Adapter 契約](docs/adapter_contract.md) | host app と gem の責務境界 |\n\n---\n\n## インストール\n\n```bash\nbundle add riichi_engine\n```\n\nまたは Gemfile に直接追加：\n\n```ruby\ngem \"riichi_engine\"\n```\n\n---\n\n## クイックスタート\n\n### 1. 局を開始する\n\n`RuleConfig` を作成し、局の初期情報を `GameSetupSnapshot` に詰めて `setup_round` を呼びます。\n\n```ruby\nrule = Mahjong::Config::RuleConfig.new  # デフォルトルール（東南戦・25000点持ち等）\n\nsnapshot = Mahjong::Snapshots::GameSetupSnapshot.new(\n  bakaze:    \"ton\",  # 東場\n  kyoku:     1,      # 1局目\n  honba:     0,\n  kyoutaku:  0,\n  oya_index: 0,      # seat 0 が親\n  scores: { 0 =\u003e 25_000, 1 =\u003e 25_000, 2 =\u003e 25_000, 3 =\u003e 25_000 }\n)\n\nstate = RiichiEngine::API.setup_round(\n  game_snapshot: snapshot,\n  rule:          rule,\n  seed:          \"round-001\"  # 牌山シード（省略可）\n)\n```\n\n### 2. 自摸・打牌を進める\n\nアクションを順に `apply_round_action` へ渡すことで局を進行させます。  \n選択可能なアクション一覧は `available_round_actions` で取得できます。\n\n```ruby\n# 自摸\nRiichiEngine::API.apply_round_action(\n  state:  state,\n  action: { type: :tsumo },\n  rule:   rule\n)\n\n# 現在の手番プレイヤーが選べるアクションを取得\nactions = RiichiEngine::API.available_round_actions(\n  state: state,\n  seat:  state.current_seat,\n  rule:  rule\n)\n\n# 打牌アクションを選んで適用\ndahai = actions.find { |a| a[:type] == :dahai }\n\nresult = RiichiEngine::API.apply_round_action(\n  state:  state,\n  action: { type: :dahai, seat: state.current_seat, tile: dahai[:tile] },\n  rule:   rule\n)\n```\n\n`result` は `Mahjong::Results::RoundFlowResult` です。  \n`result.round_end?` が `true` のとき局が終了しており、`result.round_end_info` に終了情報が入ります。\n\n### 3. 局終了後に次局かゲーム終了かを判定する\n\n```ruby\nflow_result = RiichiEngine::API.judge_next_game_round(\n  progress_snapshot: progress_snapshot,\n  round_end_info:    result.round_end_info,\n  rule:              rule\n)\n\n# flow_result.next_round? =\u003e true なら次局へ\n# flow_result.game_end?   =\u003e true ならゲーム終了\n```\n\n---\n\n## エラー\n\nエンジンが発生させる例外は2種類です。host app 側の adapter で rescue してください。\n\n```ruby\nRiichiEngine::API::InvalidActionError  # 不正なアクション（不正な打牌・存在しない鳴き等）\nRiichiEngine::API::EngineError         # エンジン内部エラー\n```\n\n---\n\n## ルール設定\n\n`RuleConfig.new` にハッシュを渡すことで細かい設定が可能です。\n\n```ruby\nrule = Mahjong::Config::RuleConfig.new(\n  \"game_type\"      =\u003e \"hanchan\",  # \"hanchan\"（東南戦）or \"tonpuu\"（東風戦）\n  \"initial_score\"  =\u003e 25_000,\n  \"uma\"            =\u003e [20_000, 10_000, -10_000, -20_000],\n  \"kuitan\"         =\u003e true,       # 食い断あり\n  \"double_ron\"     =\u003e true,       # ダブロン\n  \"tobi\"           =\u003e true        # トビあり\n)\n```\n\n設定項目の詳細は [API リファレンス](docs/api_reference.md#ruleconfigの設定項目) を参照してください。\n\n---\n\n## テスト実行\n\n```bash\nbundle install --local\nbundle exec rspec\n```\n\n---\n\n## ライセンス\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrikstephensen%2Friichi_engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrikstephensen%2Friichi_engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrikstephensen%2Friichi_engine/lists"}