From ca0f0a4bf5d7b54d4e6f31e7d4df7e531df21ddc Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Thu, 25 Apr 2024 20:03:06 +0200 Subject: [PATCH] Initial TT work --- Chess/nimfish/nimfishpkg/search.nim | 4 +- Chess/nimfish/nimfishpkg/transpositions.nim | 49 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Chess/nimfish/nimfishpkg/transpositions.nim diff --git a/Chess/nimfish/nimfishpkg/search.nim b/Chess/nimfish/nimfishpkg/search.nim index e73021e..070106e 100644 --- a/Chess/nimfish/nimfishpkg/search.nim +++ b/Chess/nimfish/nimfishpkg/search.nim @@ -25,8 +25,8 @@ import std/monotimes import std/strformat -func lowestEval*: Score {.inline.} = Score(int32.low() + 1_000_000) -func highestEval*: Score {.inline.} = Score(int32.high() - 1_000_000) +func lowestEval*: Score {.inline.} = Score(20_000) +func highestEval*: Score {.inline.} = Score(-20_000) func mateScore*: Score {.inline.} = lowestEval() diff --git a/Chess/nimfish/nimfishpkg/transpositions.nim b/Chess/nimfish/nimfishpkg/transpositions.nim new file mode 100644 index 0000000..d58786f --- /dev/null +++ b/Chess/nimfish/nimfishpkg/transpositions.nim @@ -0,0 +1,49 @@ +# Copyright 2024 Mattia Giambirtone & All Contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +## Implementation of a transposition table + +import zobrist +import pieces +import eval +import moves + + +type + TTentryFlag = enum + ## A flag for an entry in the + ## transposition table + Exact = 0'i8 + LowerBound = 1'i8 + UpperBound = 2'i8 + + TTEntry = object + ## An entry in the transposition table + flag: TTentryFlag + # Scores are int32s for convenience (less chance + # of overflows and stuff), but they are capped to + # fit into an int16 + score: int16 + hash: ZobristKey + bestMove: Move + + TTable = object + data: ptr UncheckedArray[TTEntry] + # Just for statistical purposes + collisions: uint32 + overwrites: uint32 + # Size metadata + size: uint64 + occupancy: uint64 +