diff --git a/chess/board.go b/chess/board.go index 06f4eeb..bef7ee5 100644 --- a/chess/board.go +++ b/chess/board.go @@ -360,7 +360,7 @@ func (b *Board) Move(move string) error { } // make sure the move is marked as a check if it was - if b.InCheck() && !strings.HasSuffix(move, "+") { + if b.InCheck() && !strings.HasSuffix(move, "+") && !strings.HasSuffix(move, "#") { move += "+" } @@ -379,6 +379,7 @@ func parseMove(move string) (string, int, int, string, error) { ) move = strings.TrimSuffix(move, "+") + move = strings.TrimSuffix(move, "#") if move == "O-O" { return "K", 5, 7, "g1", nil diff --git a/chess/board_test.go b/chess/board_test.go index 01af420..989eee6 100644 --- a/chess/board_test.go +++ b/chess/board_test.go @@ -472,6 +472,22 @@ func TestBoardCheck(t *testing.T) { assertParse(t, b, "Kxf7") } +func TestBoardCheckmate(t *testing.T) { + t.Parallel() + + b := chess.NewBoard() + + assert.False(t, b.InCheck()) + + // fool's mate + assertParse(t, b, "f3 e6 g4 Qh4#") + + assert.True(t, b.InCheck()) + assert.True(t, strings.HasSuffix(b.Moves[len(b.Moves)-1], "#"), "checkmate move should end with #") + + assertMoveError(t, b, "a3", "invalid move a3: king is in check") +} + func TestBoardPin(t *testing.T) { t.Parallel()