# any fun on the UCI channel?
if ($nfound > 0 && vec($rout, fileno($engine->{'read'}), 1) == 1) {
- #
- # Read until we've got a full line -- if the engine sends part of
- # a line and then stops we're pretty much hosed, but that should
- # never happen.
- #
- my $line = '';
- while ($line !~ /\n/) {
- my $tmp;
- my $ret = sysread $engine->{'read'}, $tmp, 1;
-
- if (!defined($ret)) {
- next if ($!{EINTR});
- die "error in reading from the UCI engine: $!";
- } elsif ($ret == 0) {
- die "EOF from UCI engine";
- }
-
- $line .= $tmp;
- }
-
- $line =~ tr/\r\n//d;
+ my $line = read_line($engine->{'read'});
handle_uci($line);
$sleep = 0;
return (can_reach($board, 'R', $from_row, $from_col, $to_row, $to_col) ||
can_reach($board, 'B', $from_row, $from_col, $to_row, $to_col));
}
+
+ # TODO: en passant
if ($piece eq 'p') {
# black pawn
if ($to_col == $from_col && $to_row == $from_row + 1) {
return ($dest_piece eq '-');
}
+ if ($to_col == $from_col && $from_row == 1 && $to_row == 3) {
+ my $middle_piece = substr($board->[2], $to_col, 1);
+ return ($dest_piece eq '-' && $middle_piece eq '-');
+ }
if (abs($to_col - $from_col) == 1 && $to_row == $from_row + 1) {
return ($dest_piece ne '-');
}
if ($to_col == $from_col && $to_row == $from_row - 1) {
return ($dest_piece eq '-');
}
+ if ($to_col == $from_col && $from_row == 6 && $to_row == 4) {
+ my $middle_piece = substr($board->[5], $to_col, 1);
+ return ($dest_piece eq '-' && $middle_piece eq '-');
+ }
if (abs($to_col - $from_col) == 1 && $to_row == $from_row - 1) {
return ($dest_piece ne '-');
}
return $engine;
}
+
+sub read_line {
+ my $fh = shift;
+
+ #
+ # Read until we've got a full line -- if the engine sends part of
+ # a line and then stops we're pretty much hosed, but that should
+ # never happen.
+ #
+ my $line = '';
+ while ($line !~ /\n/) {
+ my $tmp;
+ my $ret = sysread $engine->{'read'}, $tmp, 1;
+
+ if (!defined($ret)) {
+ next if ($!{EINTR});
+ die "error in reading from the UCI engine: $!";
+ } elsif ($ret == 0) {
+ die "EOF from UCI engine";
+ }
+
+ $line .= $tmp;
+ }
+
+ $line =~ tr/\r\n//d;
+ return $line;
+}