module BishBosh.Evaluation.QuantifiedGame(
OpenInterval,
QuantifiedGame(
getGame,
getWeightedMeanAndCriterionValues
),
unboundedInterval,
compareFitness,
getFitness,
fromGame,
getLastTurn,
getLatestTurns,
negateFitness,
negateInterval
) where
import Control.Arrow((&&&))
import qualified BishBosh.Attribute.WeightedMeanAndCriterionValues as Attribute.WeightedMeanAndCriterionValues
import qualified BishBosh.Component.Move as Component.Move
import qualified BishBosh.Component.Turn as Component.Turn
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Evaluation.Fitness as Evaluation.Fitness
import qualified BishBosh.Input.EvaluationOptions as Input.EvaluationOptions
import qualified BishBosh.Model.Game as Model.Game
import qualified BishBosh.Notation.MoveNotation as Notation.MoveNotation
import qualified BishBosh.Property.Null as Property.Null
import qualified BishBosh.Text.ShowList as Text.ShowList
import qualified BishBosh.Types as T
import qualified Control.DeepSeq
import qualified Control.Exception
import qualified Data.Maybe
import qualified Data.Ord
data QuantifiedGame x y criterionValue weightedMean = MkQuantifiedGame {
QuantifiedGame x y criterionValue weightedMean -> Game x y
getGame :: Model.Game.Game x y,
QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues :: Attribute.WeightedMeanAndCriterionValues.WeightedMeanAndCriterionValues weightedMean criterionValue
} deriving (QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
(QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool)
-> (QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool)
-> Eq (QuantifiedGame x y criterionValue weightedMean)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Eq weightedMean,
Eq criterionValue) =>
QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
/= :: QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
$c/= :: forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Eq weightedMean,
Eq criterionValue) =>
QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
== :: QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
$c== :: forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Eq weightedMean,
Eq criterionValue) =>
QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Bool
Eq, Int -> QuantifiedGame x y criterionValue weightedMean -> ShowS
[QuantifiedGame x y criterionValue weightedMean] -> ShowS
QuantifiedGame x y criterionValue weightedMean -> String
(Int -> QuantifiedGame x y criterionValue weightedMean -> ShowS)
-> (QuantifiedGame x y criterionValue weightedMean -> String)
-> ([QuantifiedGame x y criterionValue weightedMean] -> ShowS)
-> Show (QuantifiedGame x y criterionValue weightedMean)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
Int -> QuantifiedGame x y criterionValue weightedMean -> ShowS
forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
[QuantifiedGame x y criterionValue weightedMean] -> ShowS
forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
QuantifiedGame x y criterionValue weightedMean -> String
showList :: [QuantifiedGame x y criterionValue weightedMean] -> ShowS
$cshowList :: forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
[QuantifiedGame x y criterionValue weightedMean] -> ShowS
show :: QuantifiedGame x y criterionValue weightedMean -> String
$cshow :: forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
QuantifiedGame x y criterionValue weightedMean -> String
showsPrec :: Int -> QuantifiedGame x y criterionValue weightedMean -> ShowS
$cshowsPrec :: forall x y criterionValue weightedMean.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y, Show weightedMean,
Show criterionValue) =>
Int -> QuantifiedGame x y criterionValue weightedMean -> ShowS
Show)
instance Control.DeepSeq.NFData weightedMean => Control.DeepSeq.NFData (QuantifiedGame x y criterionValue weightedMean) where
rnf :: QuantifiedGame x y criterionValue weightedMean -> ()
rnf MkQuantifiedGame { getWeightedMeanAndCriterionValues :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues = WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues } = WeightedMeanAndCriterionValues weightedMean criterionValue -> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues
instance (Enum x, Enum y, Real criterionValue, Real weightedMean) => Notation.MoveNotation.ShowNotationFloat (QuantifiedGame x y criterionValue weightedMean) where
showsNotationFloat :: MoveNotation
-> (Double -> ShowS)
-> QuantifiedGame x y criterionValue weightedMean
-> ShowS
showsNotationFloat MoveNotation
moveNotation Double -> ShowS
showsDouble QuantifiedGame x y criterionValue weightedMean
quantifiedGame = ShowS -> [(String, ShowS)] -> ShowS
Text.ShowList.showsAssociationList ShowS
Text.ShowList.showsSeparator ([(String, ShowS)] -> ShowS) -> [(String, ShowS)] -> ShowS
forall a b. (a -> b) -> a -> b
$ ((QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS))
-> (String, ShowS))
-> [QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS)]
-> [(String, ShowS)]
forall a b. (a -> b) -> [a] -> [b]
map ((QuantifiedGame x y criterionValue weightedMean -> (String, ShowS))
-> QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS)
forall a b. (a -> b) -> a -> b
$ QuantifiedGame x y criterionValue weightedMean
quantifiedGame) [
(,) String
Component.Move.tag (ShowS -> (String, ShowS))
-> (QuantifiedGame x y criterionValue weightedMean -> ShowS)
-> QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MoveNotation -> Turn x y -> ShowS
forall a. ShowNotation a => MoveNotation -> a -> ShowS
Notation.MoveNotation.showsNotation MoveNotation
moveNotation (Turn x y -> ShowS)
-> (QuantifiedGame x y criterionValue weightedMean -> Turn x y)
-> QuantifiedGame x y criterionValue weightedMean
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QuantifiedGame x y criterionValue weightedMean -> Turn x y
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Turn x y
getLastTurn,
(,) String
Attribute.WeightedMeanAndCriterionValues.weightedMeanTag (ShowS -> (String, ShowS))
-> (QuantifiedGame x y criterionValue weightedMean -> ShowS)
-> QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
showsDouble (Double -> ShowS)
-> (QuantifiedGame x y criterionValue weightedMean -> Double)
-> QuantifiedGame x y criterionValue weightedMean
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. weightedMean -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac (weightedMean -> Double)
-> (QuantifiedGame x y criterionValue weightedMean -> weightedMean)
-> QuantifiedGame x y criterionValue weightedMean
-> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QuantifiedGame x y criterionValue weightedMean -> weightedMean
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> weightedMean
getFitness,
(,) String
Attribute.WeightedMeanAndCriterionValues.criterionValuesTag (ShowS -> (String, ShowS))
-> (QuantifiedGame x y criterionValue weightedMean -> ShowS)
-> QuantifiedGame x y criterionValue weightedMean
-> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (criterionValue -> ShowS) -> [criterionValue] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
Text.ShowList.showsFormattedList' (Double -> ShowS
showsDouble (Double -> ShowS)
-> (criterionValue -> Double) -> criterionValue -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. criterionValue -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac) ([criterionValue] -> ShowS)
-> (QuantifiedGame x y criterionValue weightedMean
-> [criterionValue])
-> QuantifiedGame x y criterionValue weightedMean
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WeightedMeanAndCriterionValues weightedMean criterionValue
-> [criterionValue]
forall weightedMean criterionValue.
WeightedMeanAndCriterionValues weightedMean criterionValue
-> [criterionValue]
Attribute.WeightedMeanAndCriterionValues.getCriterionValues (WeightedMeanAndCriterionValues weightedMean criterionValue
-> [criterionValue])
-> (QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue)
-> QuantifiedGame x y criterionValue weightedMean
-> [criterionValue]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues
]
instance Property.Null.Null (QuantifiedGame x y criterionValue weightedMean) where
isNull :: QuantifiedGame x y criterionValue weightedMean -> Bool
isNull MkQuantifiedGame { getGame :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Game x y
getGame = Game x y
game } = Game x y -> Bool
forall a. Null a => a -> Bool
Property.Null.isNull Game x y
game
getFitness :: QuantifiedGame x y criterionValue weightedMean -> weightedMean
getFitness :: QuantifiedGame x y criterionValue weightedMean -> weightedMean
getFitness MkQuantifiedGame { getWeightedMeanAndCriterionValues :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues = WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues } = WeightedMeanAndCriterionValues weightedMean criterionValue
-> weightedMean
forall weightedMean criterionValue.
WeightedMeanAndCriterionValues weightedMean criterionValue
-> weightedMean
Attribute.WeightedMeanAndCriterionValues.getWeightedMean WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues
fromGame :: (
Enum x,
Enum y,
Fractional criterionValue,
Fractional pieceSquareValue,
Fractional rankValue,
Fractional weightedMean,
Ord x,
Ord y,
Real criterionValue,
Real criterionWeight,
Real pieceSquareValue,
Real rankValue,
Show x,
Show y
)
=> Maybe pieceSquareValue
-> Model.Game.Game x y
-> Input.EvaluationOptions.Reader criterionWeight pieceSquareValue rankValue x y (QuantifiedGame x y criterionValue weightedMean)
{-# SPECIALISE fromGame :: Maybe T.PieceSquareValue -> Model.Game.Game T.X T.Y -> Input.EvaluationOptions.Reader T.CriterionWeight T.PieceSquareValue T.RankValue T.X T.Y (QuantifiedGame T.X T.Y T.CriterionValue T.WeightedMean) #-}
fromGame :: Maybe pieceSquareValue
-> Game x y
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(QuantifiedGame x y criterionValue weightedMean)
fromGame Maybe pieceSquareValue
maybePieceSquareValue Game x y
game = Game x y
-> WeightedMeanAndCriterionValues weightedMean criterionValue
-> QuantifiedGame x y criterionValue weightedMean
forall x y criterionValue weightedMean.
Game x y
-> WeightedMeanAndCriterionValues weightedMean criterionValue
-> QuantifiedGame x y criterionValue weightedMean
MkQuantifiedGame Game x y
game (WeightedMeanAndCriterionValues weightedMean criterionValue
-> QuantifiedGame x y criterionValue weightedMean)
-> ReaderT
(EvaluationOptions criterionWeight pieceSquareValue rankValue x y)
Identity
(WeightedMeanAndCriterionValues weightedMean criterionValue)
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(QuantifiedGame x y criterionValue weightedMean)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Maybe pieceSquareValue
-> Game x y
-> ReaderT
(EvaluationOptions criterionWeight pieceSquareValue rankValue x y)
Identity
(WeightedMeanAndCriterionValues weightedMean criterionValue)
forall x y criterionValue pieceSquareValue rankValue weightedMean
criterionWeight.
(Enum x, Enum y, Fractional criterionValue,
Fractional pieceSquareValue, Fractional rankValue,
Fractional weightedMean, Ord x, Ord y, Real criterionValue,
Real criterionWeight, Real pieceSquareValue, Real rankValue,
Show x, Show y) =>
Maybe pieceSquareValue
-> Game x y
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
Evaluation.Fitness.evaluateFitness Maybe pieceSquareValue
maybePieceSquareValue Game x y
game
getLastTurn :: QuantifiedGame x y criterionValue weightedMean -> Component.Turn.Turn x y
getLastTurn :: QuantifiedGame x y criterionValue weightedMean -> Turn x y
getLastTurn MkQuantifiedGame { getGame :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Game x y
getGame = Game x y
game } = Turn x y -> Maybe (Turn x y) -> Turn x y
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe (
Exception -> Turn x y
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> Turn x y) -> Exception -> Turn x y
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkResultUndefined String
"BishBosh.Evaluation.QuantifiedGame.getLastTurn:\tzero turns have been made."
) (Maybe (Turn x y) -> Turn x y) -> Maybe (Turn x y) -> Turn x y
forall a b. (a -> b) -> a -> b
$ Game x y -> Maybe (Turn x y)
forall x y. Game x y -> Maybe (Turn x y)
Model.Game.maybeLastTurn Game x y
game
getLatestTurns
:: Component.Move.NPlies
-> QuantifiedGame x y criterionValue weightedMean
-> [Component.Turn.Turn x y]
getLatestTurns :: Int -> QuantifiedGame x y criterionValue weightedMean -> [Turn x y]
getLatestTurns Int
nPlies MkQuantifiedGame { getGame :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Game x y
getGame = Game x y
game } = Int -> [Turn x y] -> [Turn x y]
forall a. Int -> [a] -> [a]
drop Int
nPlies ([Turn x y] -> [Turn x y]) -> [Turn x y] -> [Turn x y]
forall a b. (a -> b) -> a -> b
$ Game x y -> [Turn x y]
forall x y. Game x y -> [Turn x y]
Model.Game.listTurnsChronologically Game x y
game
negateFitness :: Num weightedMean => QuantifiedGame x y criterionValue weightedMean -> QuantifiedGame x y criterionValue weightedMean
negateFitness :: QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
negateFitness quantifiedGame :: QuantifiedGame x y criterionValue weightedMean
quantifiedGame@MkQuantifiedGame { getWeightedMeanAndCriterionValues :: forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean
-> WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues = WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues } = QuantifiedGame x y criterionValue weightedMean
quantifiedGame { getWeightedMeanAndCriterionValues :: WeightedMeanAndCriterionValues weightedMean criterionValue
getWeightedMeanAndCriterionValues = WeightedMeanAndCriterionValues weightedMean criterionValue
-> WeightedMeanAndCriterionValues weightedMean criterionValue
forall weightedMean criterionValue.
Num weightedMean =>
WeightedMeanAndCriterionValues weightedMean criterionValue
-> WeightedMeanAndCriterionValues weightedMean criterionValue
Attribute.WeightedMeanAndCriterionValues.negateWeightedMean WeightedMeanAndCriterionValues weightedMean criterionValue
weightedMeanAndCriterionValues }
compareFitness
:: Ord weightedMean
=> QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
-> Ordering
compareFitness :: QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean -> Ordering
compareFitness = (QuantifiedGame x y criterionValue weightedMean -> weightedMean)
-> QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
Data.Ord.comparing QuantifiedGame x y criterionValue weightedMean -> weightedMean
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> weightedMean
getFitness
type OpenInterval x y criterionValue weightedMean = (Maybe (QuantifiedGame x y criterionValue weightedMean), Maybe (QuantifiedGame x y criterionValue weightedMean))
unboundedInterval :: OpenInterval x y criterionValue weightedMean
unboundedInterval :: OpenInterval x y criterionValue weightedMean
unboundedInterval = (Maybe (QuantifiedGame x y criterionValue weightedMean)
forall a. Maybe a
Nothing, Maybe (QuantifiedGame x y criterionValue weightedMean)
forall a. Maybe a
Nothing)
negateInterval :: Num weightedMean => OpenInterval x y criterionValue weightedMean -> OpenInterval x y criterionValue weightedMean
negateInterval :: OpenInterval x y criterionValue weightedMean
-> OpenInterval x y criterionValue weightedMean
negateInterval (Maybe (QuantifiedGame x y criterionValue weightedMean)
maybeAlpha, Maybe (QuantifiedGame x y criterionValue weightedMean)
maybeBeta) = ((Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ Maybe (QuantifiedGame x y criterionValue weightedMean)
maybeBeta) ((Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> ((Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> (Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> OpenInterval x y criterionValue weightedMean
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ((Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ Maybe (QuantifiedGame x y criterionValue weightedMean)
maybeAlpha) ((Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> OpenInterval x y criterionValue weightedMean)
-> (Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean))
-> OpenInterval x y criterionValue weightedMean
forall a b. (a -> b) -> a -> b
$ (QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
-> Maybe (QuantifiedGame x y criterionValue weightedMean)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
forall weightedMean x y criterionValue.
Num weightedMean =>
QuantifiedGame x y criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
negateFitness