Skip to content

Commit

Permalink
Add hashfull in last info command using an approx. value
Browse files Browse the repository at this point in the history
Aprox: non-default items in the first 1k TT entries
  • Loading branch information
eduherminio committed Sep 12, 2023
1 parent 47ddffe commit 2f872c1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/Lynx/Model/TranspositionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static int PopulatedItemsCount(this TranspositionTable transpositionTable
}

/// <summary>
/// TT occupancy per mill
/// Exact TT occupancy per mill
/// </summary>
/// <param name="transpositionTable"></param>
/// <returns></returns>
Expand All @@ -216,6 +216,27 @@ public static int PopulatedItemsCount(this TranspositionTable transpositionTable
? (int)(1000L * transpositionTable.PopulatedItemsCount() / transpositionTable.LongLength)
: 0;

/// <summary>
/// Orders of magnitude faster than <see cref="HashfullPermill(TranspositionTableElement[])"/>
/// </summary>
/// <param name="transpositionTable"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int HashfullPermillApprox(this TranspositionTable transpositionTable)
{
int items = 0;
for (int i = 0; i < 1000; ++i)
{
if (transpositionTable[i].Key != default)
{
++items;
}
}

//Console.WriteLine($"Real: {HashfullPermill(transpositionTable)}, estimated: {items}");
return items;
}

[Conditional("DEBUG")]
internal static void Stats(this TranspositionTable transpositionTable)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/Search/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SearchResult

public bool IsCancelled { get; set; }

public int HashfullPermill { get; set; }
public int HashfullPermill { get; set; } = -1;

public SearchResult(Move bestMove, double evaluation, int targetDepth, List<Move> moves, int alpha, int beta, int mate = default)
{
Expand Down
1 change: 1 addition & 0 deletions src/Lynx/Search/IDDFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public sealed partial class Engine
finalSearchResult.Nodes = _nodes;
finalSearchResult.Time = _stopWatch.ElapsedMilliseconds;
finalSearchResult.NodesPerSecond = Utils.CalculateNps(_nodes, _stopWatch.ElapsedMilliseconds);
finalSearchResult.HashfullPermill = _tt.HashfullPermillApprox();

if (isMateDetected && finalSearchResult.Mate + Game.HalfMovesWithoutCaptureOrPawnMove < 96)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Lynx/Search/OnlineTablebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public sealed partial class Engine
DepthReached = 0,
Nodes = 666, // In case some guis proritize the info command with biggest depth
Time = stopWatch.ElapsedMilliseconds,
NodesPerSecond = 0
NodesPerSecond = 0,
HashfullPermill = _tt.HashfullPermillApprox()
};

await _engineWriter.WriteAsync(InfoCommand.SearchResultInfo(searchResult));
Expand Down
1 change: 1 addition & 0 deletions src/Lynx/UCI/Commands/Engine/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static string SearchResultInfo(SearchResult searchResult)
$" nodes {searchResult.Nodes}" +
$" nps {searchResult.NodesPerSecond}" +
$" time {searchResult.Time}" +
(searchResult.HashfullPermill != -1 ? $" hashfull {searchResult.HashfullPermill}" : string.Empty) +
$" pv {string.Join(" ", searchResult.Moves.Select(move => move.UCIString()))}";
#pragma warning restore RCS1214 // Unnecessary interpolated string.
}
Expand Down

0 comments on commit 2f872c1

Please sign in to comment.