diff --git a/src/FEN.php b/src/FEN.php index 2f30192..dd2ac40 100644 --- a/src/FEN.php +++ b/src/FEN.php @@ -715,7 +715,7 @@ private function standard_move(Move &$move) : void $new_board->set_square($origin, ''); if ($move->get_promotion()) { - $new_board->set_square($target, $move->get_promotion()); + $new_board->set_square($target, Board::get_piece_of_color($move->get_promotion(), $this->get_active_color())); } else { $new_board->set_square($target, $piece); if ($move->get_piece_type() == 'P' && $target->export() == $this->get_en_passant()) { @@ -733,8 +733,9 @@ private function standard_move(Move &$move) : void private function set_new_board(Board $new_board) : void { - if ($new_board->is_check($this->get_active_color())) { - throw new RulesException('King is in check.'); + $active_color = $this->get_active_color(); + if ($new_board->is_check($active_color)) { + throw new RulesException('King is in check. ' . $new_board->export() . ' ' . $active_color); } $this->set_board($new_board); } diff --git a/tests/unit/FENTest.php b/tests/unit/FENTest.php index 4850b01..8591152 100644 --- a/tests/unit/FENTest.php +++ b/tests/unit/FENTest.php @@ -304,6 +304,10 @@ public function testPromotion() : void $fen->set_board('1q5k/P7/8/8/8/8/8/K7'); $fen->move('a8=Q'); $this->assertEquals('Qq5k/8/8/8/8/8/8/K7', $fen->get_board()); + + $fen = new FEN('2Q5/8/8/8/p3Q3/P7/7p/1K4k1 b - - 0 53'); + $fen->move('h1=Q'); + $this->assertEquals('2Q5/8/8/8/p3Q3/P7/8/1K4kq', $fen->get_board()); } public function testPromotionNotSpecified() : void