diff --git a/fixtures/valid_notation_tests.json b/fixtures/valid_notation_tests.json index 2daa2ae..a1487dd 100644 --- a/fixtures/valid_notation_tests.json +++ b/fixtures/valid_notation_tests.json @@ -17,7 +17,7 @@ }, { "pos1" : "r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B1K2R w KQkq - 1 9", - "pos2" : "r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 0 9", + "pos2" : "r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 2 9", "algText" : "O-O", "longAlgText" : "O-O", "uciText" : "e1g1", @@ -73,7 +73,7 @@ }, { "pos1" : "rnbk1b1r/p3pppp/5n2/2p1p3/5B2/2N2P2/PPP3PP/R3KBNR w KQ - 0 10", - "pos2" : "rnbk1b1r/p3pppp/5n2/2p1p3/5B2/2N2P2/PPP3PP/2KR1BNR b - - 0 10", + "pos2" : "rnbk1b1r/p3pppp/5n2/2p1p3/5B2/2N2P2/PPP3PP/2KR1BNR b - - 1 10", "algText" : "O-O-O+", "longAlgText" : "O-O-O+", "uciText" : "e1c1", diff --git a/move_test.go b/move_test.go index ceccb99..bde6b37 100644 --- a/move_test.go +++ b/move_test.go @@ -133,7 +133,7 @@ var ( { m: &Move{s1: E1, s2: G1, tags: KingSideCastle}, pos: unsafeFEN("r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1"), - postPos: unsafeFEN("r3k2r/8/8/8/8/8/8/R4RK1 b kq - 0 1"), + postPos: unsafeFEN("r3k2r/8/8/8/8/8/8/R4RK1 b kq - 1 1"), }, { m: &Move{s1: A4, s2: B3, tags: EnPassant}, @@ -143,7 +143,49 @@ var ( { m: &Move{s1: E1, s2: G1, tags: KingSideCastle}, pos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B1K2R w KQkq - 1 9"), - postPos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 0 9"), + postPos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 2 9"), + }, + // half move clock - knight move to f3 from starting position + { + m: &Move{s1: G1, s2: F3}, + pos: unsafeFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"), + postPos: unsafeFEN("rnbqkbnr/pppppppp/8/8/8/5N2/PPPPPPPP/RNBQKB1R b KQkq - 1 1"), + }, + // half move clock - king side castle + { + m: &Move{s1: E1, s2: G1, tags: KingSideCastle}, + pos: unsafeFEN("r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1"), + postPos: unsafeFEN("r3k2r/8/8/8/8/8/8/R4RK1 b kq - 1 1"), + }, + // half move clock - queen side castle + { + m: &Move{s1: E1, s2: C1, tags: QueenSideCastle}, + pos: unsafeFEN("r3k2r/ppqn1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P2B1PPP/R3K2R w KQkq - 3 10"), + postPos: unsafeFEN("r3k2r/ppqn1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P2B1PPP/2KR3R b kq - 4 10"), + }, + // half move clock - pawn push + { + m: &Move{s1: E2, s2: E4}, + pos: unsafeFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"), + postPos: unsafeFEN("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"), + }, + // half move clock - pawn capture + { + m: &Move{s1: E4, s2: D5, tags: Capture}, + pos: unsafeFEN("r1bqkbnr/ppp1pppp/2n5/3p4/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3"), + postPos: unsafeFEN("r1bqkbnr/ppp1pppp/2n5/3P4/8/5N2/PPPP1PPP/RNBQKB1R b KQkq - 0 3"), + }, + // half move clock - en passant + { + m: &Move{s1: E5, s2: F6, tags: EnPassant}, + pos: unsafeFEN("r1bqkbnr/ppp1p1pp/2n5/3pPp2/8/5N2/PPPP1PPP/RNBQKB1R w KQkq f6 0 4"), + postPos: unsafeFEN("r1bqkbnr/ppp1p1pp/2n2P2/3p4/8/5N2/PPPP1PPP/RNBQKB1R b KQkq - 0 4"), + }, + // half move clock - piece captured by knight + { + m: &Move{s1: C6, s2: D4, tags: Capture}, + pos: unsafeFEN("r1bqkbnr/ppp1p1pp/2n5/3pPp2/3N4/8/PPPP1PPP/RNBQKB1R b KQkq - 1 4"), + postPos: unsafeFEN("r1bqkbnr/ppp1p1pp/8/3pPp2/3n4/8/PPPP1PPP/RNBQKB1R w KQkq - 0 5"), }, } ) diff --git a/notation_test.go b/notation_test.go index c005904..d528a4f 100644 --- a/notation_test.go +++ b/notation_test.go @@ -51,7 +51,8 @@ func TestValidDecoding(t *testing.T) { } postPos := test.Pos1.Update(m) if test.Pos2.String() != postPos.String() { - t.Fatalf("starting from board \n%s\n after move %s\n expected board to be %s\n%s\n but was %s\n%s\n", + t.Fatalf("starting from board \n%s%s\n after move %s\n expected board to be %s\n%s\n but was %s\n%s\n", + test.Pos1.String(), test.Pos1.board.Draw(), m.String(), test.Pos2.String(), test.Pos2.board.Draw(), postPos.String(), postPos.board.Draw()) } @@ -86,7 +87,7 @@ var ( N: AlgebraicNotation{}, Pos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B1K2R w KQkq - 1 9"), Text: "O-O-O-O", - PostPos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 0 9"), + PostPos: unsafeFEN("r2qk2r/pp1n1ppp/2pbpn2/3p4/2PP4/1PNQPN2/P4PPP/R1B2RK1 b kq - 2 9"), }, { // http://en.lichess.org/W91M4jms#23 diff --git a/position.go b/position.go index ad3548c..ee67fa9 100644 --- a/position.go +++ b/position.go @@ -74,11 +74,10 @@ func (pos *Position) Update(m *Move) *Position { if pos.turn == Black { moveCount++ } - cr := pos.CastleRights() ncr := pos.updateCastleRights(m) p := pos.board.Piece(m.s1) halfMove := pos.halfMoveClock - if p.Type() == Pawn || m.HasTag(Capture) || cr != ncr { + if p.Type() == Pawn || m.HasTag(Capture) { halfMove = 0 } else { halfMove++