{-
Copyright (C) 2018 Dr. Alistair Ward
This file is part of BishBosh.
BishBosh is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BishBosh is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BishBosh. If not, see .
-}
{- |
[@AUTHOR@] Dr. Alistair Ward
[@DESCRIPTION@] Static tests based on .
-}
module BishBosh.Test.HUnit.Search.Search (
-- * Constants
-- evaluationOptions,
-- searchOptions,
testCases
) where
import qualified BishBosh.Attribute.CaptureMoveSortAlgorithm as Attribute.CaptureMoveSortAlgorithm
import qualified BishBosh.Attribute.CriterionWeight as Attribute.CriterionWeight
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Evaluation.PositionHashQuantifiedGameTree as Evaluation.PositionHashQuantifiedGameTree
import qualified BishBosh.Evaluation.QuantifiedGame as Evaluation.QuantifiedGame
import qualified BishBosh.Input.CriteriaWeights as Input.CriteriaWeights
import qualified BishBosh.Input.EvaluationOptions as Input.EvaluationOptions
import qualified BishBosh.Input.SearchOptions as Input.SearchOptions
import qualified BishBosh.Notation.MoveNotation as Notation.MoveNotation
import qualified BishBosh.Property.Empty as Property.Empty
import qualified BishBosh.Property.ForsythEdwards as Property.ForsythEdwards
import qualified BishBosh.Search.Search as Search.Search
import qualified BishBosh.Search.SearchState as Search.SearchState
import qualified BishBosh.Types as T
import qualified Control.Exception
import qualified Control.Monad.Reader
import qualified Data.Default
import qualified Data.List
import qualified Test.HUnit
import Test.HUnit((~?))
-- | Constant.
evaluationOptions :: (
Eq pieceSquareValue,
Fractional pieceSquareValue,
Fractional criterionWeight,
Fractional rankValue,
Integral x,
Integral y,
Ord criterionWeight,
Ord rankValue,
Show criterionWeight,
Show rankValue
) => Input.EvaluationOptions.EvaluationOptions criterionWeight pieceSquareValue rankValue x y
evaluationOptions = Input.EvaluationOptions.mkEvaluationOptions Data.Default.def {-rankValues-} Data.Default.def {
Input.CriteriaWeights.getWeightOfMobility = Attribute.CriterionWeight.mkCriterionWeight $ recip 100
} False Nothing
-- | Constant.
searchOptions :: Input.SearchOptions.SearchOptions
searchOptions = Data.Default.def {
Input.SearchOptions.getMaybeCaptureMoveSortAlgorithm = Just Attribute.CaptureMoveSortAlgorithm.MVVLVA,
Input.SearchOptions.getMaybeRetireKillerMovesAfter = Just 3,
Input.SearchOptions.getMaybeUseTranspositions = Just (1, 2)
}
-- | Check the sanity of the implementation, by validating a list of static test-cases.
testCases :: Test.HUnit.Test
testCases = Test.HUnit.test $ map (
\(searchDepth, fen, moveOptions) -> let
turnString = Notation.MoveNotation.showNotation Data.Default.def {-Smith-} $ case Search.Search.getQuantifiedGames $ Control.Monad.Reader.runReader (
Search.Search.search searchDepth $ Search.SearchState.initialise (
Evaluation.PositionHashQuantifiedGameTree.mkPositionHashQuantifiedGameTree (
evaluationOptions :: Input.EvaluationOptions.EvaluationOptions T.CriterionWeight T.PieceSquareValue T.RankValue T.X T.Y
) searchOptions Data.Default.def {-Zobrist-} Property.Empty.empty {-MoveFrequency-} (
Property.ForsythEdwards.readFEN fen -- Game.
) :: Evaluation.PositionHashQuantifiedGameTree.PositionHashQuantifiedGameTree T.X T.Y T.PositionHash T.CriterionValue T.WeightedMean
)
) searchOptions of
quantifiedGame : _ -> Evaluation.QuantifiedGame.getLastTurn quantifiedGame
_ -> Control.Exception.throw $ Data.Exception.mkNullDatum "BishBosh.Test.HUnit.Search.Search.testCases:\tfailed."
moveStrings = words moveOptions
in elem turnString moveStrings ~? showString "Bratko-Kopec:\t" (
shows turnString . showString " !~ /" $ showString (Data.List.intercalate "|" moveStrings) "/."
)
) [
-- FEN Accepted moves Observed move, at various search-depths.
-- 4 5
(4, "1k1r4/pp1b1R2/3q2pp/4p3/2B5/4Q3/PPP2B2/2K5 w - -", "e3a7p"),
(4, "3r1k2/4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