module BishBosh.Search.Transpositions (
Transformation,
Transpositions(),
find,
insert
) where
import qualified BishBosh.Property.Empty as Property.Empty
import qualified BishBosh.Search.EphemeralData as Search.EphemeralData
import qualified BishBosh.Search.TranspositionValue as Search.TranspositionValue
import qualified Data.Map
import qualified Data.Maybe
newtype Transpositions move positionHash = MkTranspositions {
deconstruct :: Data.Map.Map positionHash (Search.TranspositionValue.Value move)
}
instance Property.Empty.Empty (Transpositions move positionHash) where
empty = MkTranspositions Data.Map.empty
instance Search.EphemeralData.EphemeralData (Transpositions move positionHash) where
getSize MkTranspositions { deconstruct = byPositionHash } = Data.Map.size byPositionHash
euthanise nPlies MkTranspositions { deconstruct = byPositionHash } = MkTranspositions $ Data.Map.filter ((> nPlies) . Search.TranspositionValue.getNPlies) byPositionHash
find
:: Ord positionHash
=> positionHash
-> Transpositions move positionHash
-> Maybe (Search.TranspositionValue.Value move)
find positionHash MkTranspositions { deconstruct = byPositionHash } = Data.Map.lookup positionHash byPositionHash
type Transformation move positionHash = Transpositions move positionHash -> Transpositions move positionHash
insert
:: (Ord positionHash, Ord weightedMean)
=> Search.TranspositionValue.FindFitness move weightedMean
-> positionHash
-> Search.TranspositionValue.Value move
-> Transformation move positionHash
insert findFitness positionHash proposedValue MkTranspositions { deconstruct = byPositionHash } = MkTranspositions $ Data.Map.alter (
Data.Maybe.maybe (Just proposedValue) $ \incumbentValue -> if Search.TranspositionValue.isBetter findFitness proposedValue incumbentValue
then Just proposedValue
else Nothing
) positionHash byPositionHash