Skip to content

Instantly share code, notes, and snippets.

@mizar
Last active May 28, 2022 09:18
Show Gist options
  • Save mizar/299fc1e78e17f694761e51714d9f562c to your computer and use it in GitHub Desktop.
Save mizar/299fc1e78e17f694761e51714d9f562c to your computer and use it in GitHub Desktop.
将棋AI:USIエンジン遷移遷移図(抄)

USIエンジン状態遷移図(抄)

graph LR;
flowstart((起動)) -->|usi| usioption[/option/] --> usiok[/usiok/] --> usimode((USIモード)) -->|isready| isready[初期化処理] --> readyok[/readyok/] --> ready((初期化済み))
--> |usinewgame| ingame((対局中));
usimode -->|setoption| setoption[オプション設定] --> usimode;
ingame -->|go| search((探索)) -->|"(探索完了)"| bestmove[/bestmove/] --> ingame;
ingame -->|position| setposition[局面設定] --> ingame;
search -->|stop| bestmove;
ingame -->|go ponder| ponder((先読み)) -->|ponderhit| search;
ponder -->|stop| bestmove;
release[対局終了処理] --> usimode;
ponder -->|gameover| release;
ingame -->|gameover| release;
ready -->|isready| isready;
usimode -->|quit| quit((終了));
ready -->|quit| quit((終了));
Loading
  • isready 後に setoption した時の挙動(即時設定が反映されるかどうか、設定反映のために改めて isready が必要かどうかはエンジンやオプション項目による)
    • 例えば検討モードのShogiGUIでは、候補手の表示数変更のために MultiPV エンジンオプションの設定を動的に変更しようとする。
  • 任意の段階で quit した時の挙動
  • 詰将棋エンジンの挙動

などについては上の図では省略しています。

ハマりポイントの例

  • 「先読み」状態
    • 「先読み」状態では、 ponderhit もしくは stop が入力されるまでは、たとえ詰みを読み切っていたとしても bestmove で指し手を返してはいけない。
    • 「先読み」状態で相手が投了や時間切れなどを起こした場合、gameover が入力される可能性を考慮した方が良い。(もし gameover の入力がされても先読み探索を中止できないと…)

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment