NAME
Game::Shogi::USI - the engine behind the Universal Shogi Interface
SYNOPSIS
Game::Shogi::USI->new->run; # what shogi --usi does
my $usi = Game::Shogi::USI->new(in => $in, out => $out, nodes => 60_000);
$usi->command('position startpos moves 7g7f');
print "$_\n" for $usi->go('nodes', 6000);
DESCRIPTION
Speaks USI on a pair of handles so a shogi GUI can drive the engine. It answers usi with its name and usiok, isready with readyok, takes usinewgame, position startpos|sfen ... [moves ...] and go, and stops at quit. Every other command (setoption, stop, ponderhit, gameover) is ignored, which U allows: the search has finished and answered before the next line is read.
go
go nodes N searches N nodes. go depth D searches to that depth, under a ceiling of 200,000,000 nodes (a depth with a clock is held to the clock). byoyomi, movetime, and the side's btime/wtime (a fortieth of it) and binc/winc are added up in milliseconds and turned into a node budget at 1,000 nodes a millisecond, about half of what the engine searches on the machine it was measured on, so a slower machine still answers in time. With none of them the budget is nodes from the constructor, or 300,000.
The answer is one info line with the depth reached, the nodes searched, the score (cp, or mate in plies as U asks) and the move, then bestmove. It is bestmove win when the side to move may declare the impasse, and bestmove resign when the game is over or there is no move. go mate answers checkmate notimplemented.
METHODS
new
Game::Shogi::USI->new(in => $fh, out => $fh, nodes => $n, seed => $s);
nodes
seed
The default node budget, and the search's tie-break seed.
run
Reads commands until quit or the end of input, and returns 0.
command
One line. False after quit.
position
The board a position command's words describe, or undef when the SFEN or a move is refused.
board
A copy of the current board.
budget
The node budget for a go's arguments.
go
The lines a go answers with.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)