Parse checkmates but don't verify
This commit is contained in:
parent
c1ad076828
commit
392cf19ae6
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue