facebook twitter hatena line email

将棋プログラム/技巧/usi

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

usi使い方

> bin/release
info string Unsupported Command:
> usi
id name Gikou 2 (v2.0.2)
id author Yosuke Demura
option name BookFile type filename default book.bin
option name BookMaxPly type spin default 20 min 0 max 50
option name ByoyomiMargin type spin default 100 min 0 max 10000
option name DepthLimit type spin default 100 min 1 max 100
option name DrawScore type spin default 0 min -200 max 200
option name FischerMargin type spin default 12000 min 0 max 60000
option name MinThinkingTime type spin default 1000 min 10 max 60000
option name MultiPV type spin default 1 min 1 max 700
option name NarrowBook type check default false
option name OwnBook type check default true
option name ResignScore type spin default -10000 min -32600 max -500
option name SuddenDeathMargin type spin default 60 min 0 max 600
option name Threads type spin default 4 min 1 max 64
option name TinyBook type check default false
usiok
> setoption name USI_Ponder value false
> setoption name USI_Hash value 256
> setoption name MultiPV value 1
> isready
readyok
> usinewgame
> position startpos moves 2g2f 8c8d 7g7f 4a3b 6i7h 8d8e 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a4b 3i3h 7a7b 4g4f 6c6d 3g3f 7b6c 5i6h 4b3c 3h4g 7c7d
> go btime 0 wtime 0 byoyomi 3000
info depth 1 seldepth 1 time 1 nodes 190 nps 190000 hashfull 142 score cp 151 multipv 1 pv 6h7i
info depth 2 seldepth 2 time 1 nodes 827 nps 827000 hashfull 142 score cp 227 multipv 1 pv 4i5h 6a5b
info depth 21 seldepth 22 time 2904 nodes 2092176 nps 720446 hashfull 176 score cp 104 multipv 1 pv 9g9f 9c9d 1g1f 1c1d 6h7i 6a5b 2i3g 8a7c 6g6f 5a4b 4g5f 6c5d 4f4e 4b3a 4i5h 5b6c 2h4h 6d6e 6f6e 5d6e
bestmove 9g9f

局面をsfenで入力する場合

> position sfen lnsgkgsnl/1r7/ppppppbpp/6p2/7P1/8P/PPPPPPP2/1B5R1/LNSGKGSNL w - 1
> go btime 0 wtime 0 byoyomi 3000
info depth 1 seldepth 1 time 1 nodes 2 nps 2000 hashfull 0 score mate -2 multipv 1 pv 8b4b
info depth 2 seldepth 3 time 1 nodes 5 nps 5000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 3 seldepth 3 time 1 nodes 8 nps 8000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 4 seldepth 3 time 1 nodes 11 nps 11000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 5 seldepth 3 time 1 nodes 14 nps 14000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 6 seldepth 3 time 1 nodes 17 nps 17000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 7 seldepth 3 time 1 nodes 20 nps 20000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 8 seldepth 3 time 1 nodes 23 nps 23000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
info depth 9 seldepth 3 time 1 nodes 26 nps 26000 hashfull 0 score mate -2 multipv 1 pv 8b4b 4f4b+
bestmove 8b4b

sfenパターン

初回局面

position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL w - 1

飛車先の歩をついただけの局面

position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/7P1/PPPPPPP1P/1B5R1/LNSGKGSNL w - 1

相手は角道をあけたが、先手は角道を開けてない

position sfen lnsgkgsnl/1r7/ppppppbpp/6p2/7P1/8P/PPPPPPP2/1B5R1/LNSGKGSNL w - 1

降参?

position sfen lnsg1k3/1r3+P3/p1ppp3p/7+B1/6p2/1+pP2L3/P2PPPP1P/9/LNSGKGSNL w BGSNP2r 1

usiのコマンド一覧

公式 http://www.geocities.jp/shogidokoro/usi.html

gikouオプション

BookFile             定跡ファイル(戦型選択用) (デフォルト:book.bin)
BookMaxPly           定跡を何手目まで使うか (デフォルト:20) min 0 max 50
ByoyomiMargin        秒読み時の余裕(ミリ秒) (デフォルト:100) min 0 max 10000
DrawScore            千日手の評価値 (デフォルト:0) min -200 max 200
DepthLimit           読みの深さ(強さのレベル調節用) (デフォルト:100) min 1 max 100
FischerMargin        フィッシャールール時の余裕(ミリ秒)  (デフォルト:12000) min 0 max 60000
MinThinkingTime      最小思考時間(ミリ秒) (デフォルト: 1000) min 10 max 60000
MultiPV              候補手の数  (デフォルト:1)  min 1 max 700
NarrowBook           勝率が相対的に低い定跡手を選ばない  (デフォルト:false) 
OwnBook              定跡を使う  (デフォルト:true) 
ResignScore          技巧が投了する評価値  (デフォルト: -10000)  min -32600 max -500
SuddenDeathMargin    切れ負けルール時の余裕(秒)  (デフォルト: 60)  min 0 max 600
Threads              スレッド数   (デフォルト: 4)  min 1 max 64
TinyBook             出現頻度の低い定跡手を選ばない  (デフォルト:false)

expectを使った実行コマンド

usi.sh

#!/usr/bin
expect -c "
spawn bin/release
expect \"info string Failed to open probability.bin.\"
send -- \"usi\n\"
expect \"usiok\"
send -- \"setoption name DepthLimit value 3\n\"
send -- \"isready\n\"
expect \"readyok\"
send -- \"usinewgame\n\"
send -- \"position sfen l3g2G1/1+B+Rskp3/p1pp4p/4GB1K1/5Gps1/1LPP1P1n1/P+n2PGP1P/9/+s3s1SNL w R2BSN2L2P4 1\n\"
send -- \"go btime 0 wtime 0 byoyomi 30\n\"
expect \"bestmove resign\"
send -- \"exit\n\"
"

phpでsh動かす

<?php
$val_return = shell_exec('sh '.__DIR__."/usi.sh");

定跡選択命令はエラーが出なかったので読み込めてるようだが正常動作はしなかった

send -- \"setoption name BookFile value /var/www/Gikou/jouseki_all.bin\n\"
send -- \"setoption name UseBook value true\n\"

敵が弱すぎる場合

学習ファイルのbinが適用されてない可能性がある。 ~.binファイルをbashファイルのある場所に置く。

棋力を抑える

レベル1(読みの深さ1手): 将棋倶楽部24の8級相当 (R 800程度)
レベル2(読みの深さ2手): 将棋倶楽部24の5級相当 (R 1100程度)
レベル3(読みの深さ3手): 将棋倶楽部24の2級相当 (R 1400程度)
レベル4(読みの深さ4手): 将棋倶楽部24の初段相当 (R 1600程度)
レベル5(読みの深さ5手): 将棋倶楽部24の2段相当 (R 1800程度)

レベル3の場合

setoption name DepthLimit value 3

読み込み速度up

book.binを読み込むと1秒ぐらいは遅延を体感する。

params.binを読みこんでも速度は変わらない。逆に入れないと急にアホになる