Skip to content

Commit 6924bed

Browse files
committed
bugfix: half move clock resetting during castle
1 parent 45d3763 commit 6924bed

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

position.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (pos *Position) Update(m *Move) *Position {
8484
ncr := pos.updateCastleRights(m)
8585
p := pos.board.Piece(m.s1)
8686
halfMove := pos.halfMoveClock
87-
if p.Type() == Pawn || m.HasTag(Capture) || cr != ncr {
87+
if p.Type() == Pawn || isPureCapture(m) || cr != ncr {
8888
halfMove = 0
8989
} else {
9090
halfMove++
@@ -334,6 +334,12 @@ func decodeCastleRights(rights uint8) CastleRights {
334334
return CastleRights(cr)
335335
}
336336

337+
// returns true if the move is not a castle move
338+
func isPureCapture(m *Move) bool {
339+
return m.HasTag(Capture) && !m.HasTag(FarPawnCastle) &&
340+
!m.HasTag(ClosePawnCastle) && !m.HasTag(KnightCastle)
341+
}
342+
337343
func (pos *Position) copy() *Position {
338344
return &Position{
339345
board: pos.board.copy(),

0 commit comments

Comments
 (0)