X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Board.pm;h=8565c845c279860abf9e029b2abbc50b5b597398;hp=783aef09df46c2ef2674c390eca3d861ead36e85;hb=b4059a786029132eb27769a42ca52eca6d8b44cc;hpb=3ba7d7aa2f94b7be3cc1d4b6b19f11cb390ae77f diff --git a/Board.pm b/Board.pm index 783aef0..8565c84 100644 --- a/Board.pm +++ b/Board.pm @@ -43,57 +43,55 @@ sub make_move { } if ($piece eq 'K') { + # Convert to Chess960 king-takes-rook. + $to_col = 7 if ($move eq 'e1g1'); + $to_col = 0 if ($move eq 'e1c1'); + my $dst_piece = $board->[$to_row][$to_col]; - # White short castling (regular or Chess960 king-takes-rook) - if ($move eq 'e1g1' || $dst_piece eq 'R') { + # White short castling. + if ($dst_piece eq 'R' && $to_col > $from_col) { # king $nb->[7][$from_col] = '-'; - $nb->[7][6] = $piece; - - # rook $nb->[7][$to_col] = '-'; + $nb->[7][6] = 'K'; $nb->[7][5] = 'R'; return $nb; } - # White long castling (regular or Chess960 king-takes-rook) - if ($move eq 'e1c1' || $dst_piece eq 'R') { - # king + # Black short castling. + if ($dst_piece eq 'R' && $to_col < $from_col) { $nb->[7][$from_col] = '-'; - $nb->[7][2] = $piece; - - # rook $nb->[7][$to_col] = '-'; + $nb->[7][2] = 'K'; $nb->[7][3] = 'R'; return $nb; } } elsif ($piece eq 'k') { - my $dst_piece = $board->[$to_row][$to_col]; + # Convert to Chess960 king-takes-rook. + $to_col = 7 if ($move eq 'e8g8'); + $to_col = 0 if ($move eq 'e8c8'); - # Black short castling (regular or Chess960 king-takes-rook) - if ($move eq 'e8g8' || $dst_piece eq 'r') { - # king - $nb->[0][$from_col] = '-'; - $nb->[0][6] = $piece; + my $dst_piece = $board->[$to_row][$to_col]; - # rook + # Black short castling. + if ($dst_piece eq 'r' && $to_col > $from_col) { $nb->[0][$from_col] = '-'; + $nb->[0][$to_col] = '-'; + $nb->[0][6] = 'k'; $nb->[0][5] = 'r'; return $nb; } - # black long castling - if ($move eq 'e8c8' || $dst_piece eq 'r') { + # Black long castling. + if ($dst_piece eq 'r' && $to_col < $from_col) { # king $nb->[0][$from_col] = '-'; - $nb->[0][2] = $piece; - - # rook $nb->[0][$to_col] = '-'; + $nb->[0][2] = 'k'; $nb->[0][3] = 'r'; return $nb;