50 lines
1.4 KiB
Nim
50 lines
1.4 KiB
Nim
# 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
|
|
|