diff --git a/internal/search/negamax.go b/internal/search/negamax.go index 2a17714..7b42a5e 100644 --- a/internal/search/negamax.go +++ b/internal/search/negamax.go @@ -152,20 +152,20 @@ func (s *NegamaxSearcher) doSearch(position *chess.Position, alpha int, beta int entry, ok := s.ttable.Get(position.Hash()) if ok { - if entry.Depth >= depth { + if entry.Depth >= depth && entry.Hash == position.Hash() && ply != 0 { switch entry.Type { case ExactNode: s.pvlength[ply] = ply + 1 s.pvtable[ply][ply] = entry.Move return entry.Score case UpperNode: - if entry.Score < alpha { + if entry.Score <= alpha { return alpha } break case LowerNode: - if entry.Score > beta { + if entry.Score >= beta { return beta } @@ -253,7 +253,7 @@ func (s *NegamaxSearcher) doSearch(position *chess.Position, alpha int, beta int } if !s.stop { - entry := NewTableEntry(nodeType, bestMove, bestScore, depth, position.Plies()) + entry := NewTableEntry(position.Hash(), nodeType, bestMove, bestScore, depth, position.Plies()) s.ttable.Insert(position.Hash(), entry) } diff --git a/internal/search/transposition.go b/internal/search/transposition.go index e1e33b0..8c1e6f0 100644 --- a/internal/search/transposition.go +++ b/internal/search/transposition.go @@ -28,6 +28,7 @@ func (t NodeType) String() string { } type TableEntry struct { + Hash uint64 Type NodeType Move chess.Move Score int @@ -46,8 +47,9 @@ const ( ) // NewTableEntry creates a new TableEntry. -func NewTableEntry(nodeType NodeType, move chess.Move, score, depth int, age int) TableEntry { +func NewTableEntry(hash uint64, nodeType NodeType, move chess.Move, score, depth int, age int) TableEntry { return TableEntry{ + Hash: hash, Type: nodeType, Move: move, Score: score,