sub one()

in pachi_py/pachi/tools/sgf-analyse.pl [28:60]


sub one {
	my ($move) = @_;

	# Move of the other color - supposedly.
	return if ($move % 2 == ($mcolor eq 'B' ? 0 : 1));

	# Get pachi output from GTP stream that contains the SGF up to
	# given move, with information about the originally made move
	# included.
	my $line = $move + 3; # board_size, clearboard, komi
	my $rest = $line + 1;
	open my $g, "tools/sgf2gtp.pl < \"$sgf\" | sed -e '$line s/play \\(.*\\) \\(.*\\)/1 echo \\1 \\2\\n2 genmove \\1\\n3 pachi-result/' -e '$rest,\$ d' | ./pachi @ARGV |" or die $!;

	# Parse the GTP output.
	my ($color, $realmove, $genmove, $winrate) = @_;
	while (<$g>) {
		chomp;
		if (/^=1 (.*) (.*)/) {
			$color = $1; $realmove = uc $2;
		} elsif (/^=2 (.*)/) {
			$genmove = $1;
		} elsif (/^=3 (.*) (.*) (.*) (.*)/) {
			$winrate = $mcolor eq $color ? $3 : 1.0 - $3;
		}
	}

	# Pass value is not interesting since Pachi might want
	# to clarify some groups yet.
	return if $realmove eq 'PASS';

	# Generate summary line.
	print join(', ', $move, $color, $realmove, $genmove, $winrate) . "\n";
}