Skip to content

Commit

Permalink
search: improve retrieving from transposition table
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Dec 4, 2023
1 parent fcd8c10 commit 92f0dd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/search/negamax.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/search/transposition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (t NodeType) String() string {
}

type TableEntry struct {
Hash uint64
Type NodeType
Move chess.Move
Score int
Expand All @@ -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,
Expand Down

0 comments on commit 92f0dd1

Please sign in to comment.