Skip to content

Commit d4044a9

Browse files
committed
small refactoring, -2 LOC, same speed, easier on the eye
1 parent 2d1a66d commit d4044a9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

MinimalChess/Transpositions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static int Index(in ulong hash)
5454
if (e1.Hash == hash)
5555
return index ^ 1;
5656

57-
//raise age of both and chose the older, shallower one!
58-
return (e0.Depth - ++e0.Age) < (e1.Depth - ++e1.Age) ? index : index ^ 1;
57+
//raise age of both and choose the older, shallower entry!
58+
return (++e0.Age - e0.Depth) > (++e1.Age - e1.Depth) ? index : index ^ 1;
5959
}
6060

6161
static Transpositions()
@@ -76,16 +76,14 @@ public static void Clear()
7676

7777
public static void Store(ulong zobristHash, int depth, SearchWindow window, int score, Move bestMove)
7878
{
79-
depth = Math.Max(depth, 0);
80-
int index = Index(zobristHash);
81-
ref HashEntry entry = ref _table[index];
79+
ref HashEntry entry = ref _table[Index(zobristHash)];
8280

8381
//don't overwrite a bestmove with 'default' unless it's a new position
8482
if (entry.Hash != zobristHash || bestMove != default)
8583
entry.BestMove = bestMove;
8684

8785
entry.Hash = zobristHash;
88-
entry.Depth = (byte)depth;
86+
entry.Depth = depth < 0 ? default : (byte)depth;
8987
entry.Age = 0;
9088

9189
if (score >= window.Ceiling)

0 commit comments

Comments
 (0)