{-# LANGUAGE ScopedTypeVariables #-}
module BishBosh.Evaluation.Fitness(
maximumDefended,
measurePieceSquareValue,
measurePieceSquareValueIncrementally,
measureValueOfMaterial,
measureValueOfCastlingPotential,
measureValueOfDefence,
measureValueOfDoubledPawns,
measureValueOfIsolatedPawns,
measureValueOfPassedPawns,
evaluateFitness
) where
import Control.Applicative((<|>))
import Control.Arrow((&&&))
import Data.Array.IArray((!))
import qualified BishBosh.Attribute.CriterionValue as Attribute.CriterionValue
import qualified BishBosh.Attribute.Direction as Attribute.Direction
import qualified BishBosh.Attribute.LogicalColour as Attribute.LogicalColour
import qualified BishBosh.Attribute.MoveType as Attribute.MoveType
import qualified BishBosh.Attribute.RankValues as Attribute.RankValues
import qualified BishBosh.Attribute.WeightedMeanAndCriterionValues as Attribute.WeightedMeanAndCriterionValues
import qualified BishBosh.Cartesian.Abscissa as Cartesian.Abscissa
import qualified BishBosh.Cartesian.Coordinates as Cartesian.Coordinates
import qualified BishBosh.Cartesian.Ordinate as Cartesian.Ordinate
import qualified BishBosh.Component.Move as Component.Move
import qualified BishBosh.Component.Piece as Component.Piece
import qualified BishBosh.Component.PieceSquareArray as Component.PieceSquareArray
import qualified BishBosh.Component.QualifiedMove as Component.QualifiedMove
import qualified BishBosh.Component.Turn as Component.Turn
import qualified BishBosh.Input.CriteriaWeights as Input.CriteriaWeights
import qualified BishBosh.Input.EvaluationOptions as Input.EvaluationOptions
import qualified BishBosh.Model.Game as Model.Game
import qualified BishBosh.Model.GameTerminationReason as Model.GameTerminationReason
import qualified BishBosh.Property.Opposable as Property.Opposable
import qualified BishBosh.State.Board as State.Board
import qualified BishBosh.State.CastleableRooksByLogicalColour as State.CastleableRooksByLogicalColour
import qualified BishBosh.Types as T
import qualified Control.Monad.Reader
import qualified Data.Array.IArray
import qualified Data.List
import qualified Data.Map
import qualified Data.Maybe
mkPieceSquareCriterionValue :: (
Fractional criterionValue,
Ord criterionValue,
Real pieceSquareValue
) => pieceSquareValue -> Attribute.CriterionValue.CriterionValue criterionValue
mkPieceSquareCriterionValue :: pieceSquareValue -> CriterionValue criterionValue
mkPieceSquareCriterionValue = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (pieceSquareValue -> criterionValue)
-> pieceSquareValue
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
Component.Piece.nPiecesPerSide
) (criterionValue -> criterionValue)
-> (pieceSquareValue -> criterionValue)
-> pieceSquareValue
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. pieceSquareValue -> criterionValue
forall a b. (Real a, Fractional b) => a -> b
realToFrac
measurePieceSquareValue :: (
Enum x,
Enum y,
Num pieceSquareValue,
Ord x,
Ord y
)
=> Component.PieceSquareArray.PieceSquareArray x y pieceSquareValue
-> Model.Game.Game x y
-> pieceSquareValue
{-# SPECIALISE measurePieceSquareValue :: Component.PieceSquareArray.PieceSquareArray T.X T.Y T.PieceSquareValue -> Model.Game.Game T.X T.Y -> T.PieceSquareValue #-}
measurePieceSquareValue :: PieceSquareArray x y pieceSquareValue
-> Game x y -> pieceSquareValue
measurePieceSquareValue PieceSquareArray x y pieceSquareValue
pieceSquareArray Game x y
game
| LogicalColour -> Bool
Attribute.LogicalColour.isBlack (LogicalColour -> Bool) -> LogicalColour -> Bool
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game = pieceSquareValue
difference
| Bool
otherwise = pieceSquareValue -> pieceSquareValue
forall a. Num a => a -> a
negate pieceSquareValue
difference
where
[pieceSquareValue
blacksPieceSquareValue, pieceSquareValue
whitesPieceSquareValue] = Array LogicalColour pieceSquareValue -> [pieceSquareValue]
forall (a :: * -> * -> *) e i. (IArray a e, Ix i) => a i e -> [e]
Data.Array.IArray.elems (Array LogicalColour pieceSquareValue -> [pieceSquareValue])
-> (Board x y -> Array LogicalColour pieceSquareValue)
-> Board x y
-> [pieceSquareValue]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PieceSquareArray x y pieceSquareValue
-> Board x y -> Array LogicalColour pieceSquareValue
forall x y pieceSquareValue.
(Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) =>
PieceSquareArray x y pieceSquareValue
-> Board x y -> ByLogicalColour pieceSquareValue
State.Board.sumPieceSquareValueByLogicalColour PieceSquareArray x y pieceSquareValue
pieceSquareArray (Board x y -> [pieceSquareValue])
-> Board x y -> [pieceSquareValue]
forall a b. (a -> b) -> a -> b
$ Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game
difference :: pieceSquareValue
difference = pieceSquareValue
whitesPieceSquareValue pieceSquareValue -> pieceSquareValue -> pieceSquareValue
forall a. Num a => a -> a -> a
- pieceSquareValue
blacksPieceSquareValue
measurePieceSquareValueIncrementally :: (
Enum x,
Enum y,
Num pieceSquareValue,
Ord x,
Ord y
)
=> pieceSquareValue
-> Component.PieceSquareArray.PieceSquareArray x y pieceSquareValue
-> Model.Game.Game x y
-> pieceSquareValue
{-# SPECIALISE measurePieceSquareValueIncrementally :: T.PieceSquareValue -> Component.PieceSquareArray.PieceSquareArray T.X T.Y T.PieceSquareValue -> Model.Game.Game T.X T.Y -> T.PieceSquareValue #-}
measurePieceSquareValueIncrementally :: pieceSquareValue
-> PieceSquareArray x y pieceSquareValue
-> Game x y
-> pieceSquareValue
measurePieceSquareValueIncrementally pieceSquareValue
previousPieceSquareValue PieceSquareArray x y pieceSquareValue
pieceSquareArray Game x y
game
| MoveType -> Bool
Attribute.MoveType.isQuiet (MoveType -> Bool) -> MoveType -> Bool
forall a b. (a -> b) -> a -> b
$ QualifiedMove x y -> MoveType
forall x y. QualifiedMove x y -> MoveType
Component.QualifiedMove.getMoveType QualifiedMove x y
qualifiedMove = let
findPieceSquareValue :: Coordinates x y -> pieceSquareValue
findPieceSquareValue Coordinates x y
coordinates = NPieces
-> LogicalColour
-> Rank
-> Coordinates x y
-> PieceSquareArray x y pieceSquareValue
-> pieceSquareValue
forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y) =>
NPieces
-> LogicalColour
-> Rank
-> Coordinates x y
-> PieceSquareArray x y pieceSquareValue
-> pieceSquareValue
Component.PieceSquareArray.findPieceSquareValue (
Board x y -> NPieces
forall x y. Board x y -> NPieces
State.Board.getNPieces (Board x y -> NPieces) -> Board x y -> NPieces
forall a b. (a -> b) -> a -> b
$ Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game
) (
LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite (LogicalColour -> LogicalColour) -> LogicalColour -> LogicalColour
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game
) (
Turn x y -> Rank
forall x y. Turn x y -> Rank
Component.Turn.getRank Turn x y
turn
) Coordinates x y
coordinates PieceSquareArray x y pieceSquareValue
pieceSquareArray
in (pieceSquareValue -> pieceSquareValue -> pieceSquareValue)
-> (pieceSquareValue, pieceSquareValue) -> pieceSquareValue
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) (
Coordinates x y -> pieceSquareValue
findPieceSquareValue (Coordinates x y -> pieceSquareValue)
-> (Move x y -> Coordinates x y) -> Move x y -> pieceSquareValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Move x y -> Coordinates x y
forall x y. Move x y -> Coordinates x y
Component.Move.getDestination (Move x y -> pieceSquareValue)
-> (Move x y -> pieceSquareValue)
-> Move x y
-> (pieceSquareValue, pieceSquareValue)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Coordinates x y -> pieceSquareValue
findPieceSquareValue (Coordinates x y -> pieceSquareValue)
-> (Move x y -> Coordinates x y) -> Move x y -> pieceSquareValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Move x y -> Coordinates x y
forall x y. Move x y -> Coordinates x y
Component.Move.getSource (Move x y -> (pieceSquareValue, pieceSquareValue))
-> Move x y -> (pieceSquareValue, pieceSquareValue)
forall a b. (a -> b) -> a -> b
$ QualifiedMove x y -> Move x y
forall x y. QualifiedMove x y -> Move x y
Component.QualifiedMove.getMove QualifiedMove x y
qualifiedMove
) pieceSquareValue -> pieceSquareValue -> pieceSquareValue
forall a. Num a => a -> a -> a
- pieceSquareValue
previousPieceSquareValue
| Bool
otherwise = PieceSquareArray x y pieceSquareValue
-> Game x y -> pieceSquareValue
forall x y pieceSquareValue.
(Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) =>
PieceSquareArray x y pieceSquareValue
-> Game x y -> pieceSquareValue
measurePieceSquareValue PieceSquareArray x y pieceSquareValue
pieceSquareArray Game x y
game
where
Just Turn x y
turn = Game x y -> Maybe (Turn x y)
forall x y. Game x y -> Maybe (Turn x y)
Model.Game.maybeLastTurn Game x y
game
qualifiedMove :: QualifiedMove x y
qualifiedMove = Turn x y -> QualifiedMove x y
forall x y. Turn x y -> QualifiedMove x y
Component.Turn.getQualifiedMove Turn x y
turn
measureValueOfMaterial :: (
Fractional criterionValue,
Fractional rankValue,
Ord criterionValue,
Real rankValue
)
=> Attribute.RankValues.RankValues rankValue
-> Model.Game.Game x y
-> Attribute.CriterionValue.CriterionValue criterionValue
measureValueOfMaterial :: RankValues rankValue -> Game x y -> CriterionValue criterionValue
measureValueOfMaterial RankValues rankValue
rankValues Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (Board x y -> criterionValue)
-> Board x y
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
Component.Piece.nPiecesPerSide
) (criterionValue -> criterionValue)
-> (Board x y -> criterionValue) -> Board x y -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rankValue -> criterionValue
forall a b. (Real a, Fractional b) => a -> b
realToFrac (rankValue -> criterionValue)
-> (Board x y -> rankValue) -> Board x y -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
if LogicalColour -> Bool
Attribute.LogicalColour.isBlack (LogicalColour -> Bool) -> LogicalColour -> Bool
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game
then rankValue -> rankValue
forall a. a -> a
id
else rankValue -> rankValue
forall a. Num a => a -> a
negate
) (rankValue -> rankValue)
-> (Board x y -> rankValue) -> Board x y -> rankValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (rankValue -> (Rank, NPieces) -> rankValue)
-> rankValue -> [(Rank, NPieces)] -> rankValue
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Data.List.foldl' (
\rankValue
acc (Rank
rank, NPieces
nPieces) -> if NPieces
nPieces NPieces -> NPieces -> Bool
forall a. Eq a => a -> a -> Bool
== NPieces
0
then rankValue
acc
else rankValue
acc rankValue -> rankValue -> rankValue
forall a. Num a => a -> a -> a
+ Rank -> RankValues rankValue -> rankValue
forall rankValue. Rank -> RankValues rankValue -> rankValue
Attribute.RankValues.findRankValue Rank
rank RankValues rankValue
rankValues rankValue -> rankValue -> rankValue
forall a. Num a => a -> a -> a
* NPieces -> rankValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
nPieces
) rankValue
0 ([(Rank, NPieces)] -> rankValue)
-> (Board x y -> [(Rank, NPieces)]) -> Board x y -> rankValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array Rank NPieces -> [(Rank, NPieces)]
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> [(i, e)]
Data.Array.IArray.assocs (Array Rank NPieces -> [(Rank, NPieces)])
-> (Board x y -> Array Rank NPieces)
-> Board x y
-> [(Rank, NPieces)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Board x y -> Array Rank NPieces
forall x y. Board x y -> Array Rank NPieces
State.Board.getNPiecesDifferenceByRank (Board x y -> CriterionValue criterionValue)
-> Board x y -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game
measureValueOfMobility :: (
Enum x,
Enum y,
Fractional criterionValue,
Ord criterionValue,
Ord x,
Ord y,
Show x,
Show y
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
{-# SPECIALISE measureValueOfMobility :: Model.Game.Game T.X T.Y -> Attribute.CriterionValue.CriterionValue T.CriterionValue #-}
measureValueOfMobility :: Game x y -> CriterionValue criterionValue
measureValueOfMobility Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (criterionValue -> criterionValue -> criterionValue)
-> (criterionValue, criterionValue) -> criterionValue
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((criterionValue, criterionValue) -> criterionValue)
-> (LogicalColour -> (criterionValue, criterionValue))
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> criterionValue
forall c. Fractional c => LogicalColour -> c
measureConstriction (LogicalColour -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> (criterionValue, criterionValue)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& LogicalColour -> criterionValue
forall c. Fractional c => LogicalColour -> c
measureConstriction (LogicalColour -> criterionValue)
-> (LogicalColour -> LogicalColour)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite
) (LogicalColour -> CriterionValue criterionValue)
-> LogicalColour -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game where
measureConstriction :: LogicalColour -> c
measureConstriction LogicalColour
logicalColour = c -> c
forall a. Fractional a => a -> a
recip (c -> c) -> (NPieces -> c) -> NPieces -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> c
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> c) -> (NPieces -> NPieces) -> NPieces -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> NPieces
forall a. Enum a => a -> a
succ (NPieces -> c) -> NPieces -> c
forall a b. (a -> b) -> a -> b
$ LogicalColour -> Game x y -> NPieces
forall x y.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y) =>
LogicalColour -> Game x y -> NPieces
Model.Game.countMovesAvailableTo LogicalColour
logicalColour Game x y
game
measureValueOfCastlingPotential :: (
Fractional criterionValue,
Ord criterionValue
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
measureValueOfCastlingPotential :: Game x y -> CriterionValue criterionValue
measureValueOfCastlingPotential Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (criterionValue -> criterionValue -> criterionValue)
-> (criterionValue, criterionValue) -> criterionValue
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((criterionValue, criterionValue) -> criterionValue)
-> (LogicalColour -> (criterionValue, criterionValue))
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> criterionValue
castlingPotential (LogicalColour -> criterionValue)
-> (LogicalColour -> LogicalColour)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite (LogicalColour -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> (criterionValue, criterionValue)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& LogicalColour -> criterionValue
castlingPotential
) (LogicalColour -> CriterionValue criterionValue)
-> LogicalColour -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game where
castlingPotential :: LogicalColour -> criterionValue
castlingPotential = criterionValue
-> ([x] -> criterionValue) -> Maybe [x] -> criterionValue
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe criterionValue
1 (
(criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ criterionValue
2) (criterionValue -> criterionValue)
-> ([x] -> criterionValue) -> [x] -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> criterionValue)
-> ([x] -> NPieces) -> [x] -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [x] -> NPieces
forall (t :: * -> *) a. Foldable t => t a -> NPieces
length
) (Maybe [x] -> criterionValue)
-> (LogicalColour -> Maybe [x]) -> LogicalColour -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> CastleableRooksByLogicalColour x -> Maybe [x]
forall x.
LogicalColour -> CastleableRooksByLogicalColour x -> Maybe [x]
`State.CastleableRooksByLogicalColour.locateForLogicalColour` Game x y -> CastleableRooksByLogicalColour x
forall x y. Game x y -> CastleableRooksByLogicalColour x
Model.Game.getCastleableRooksByLogicalColour Game x y
game
)
measureValueOfDoubledPawns :: (
Fractional criterionValue,
Ord criterionValue
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
measureValueOfDoubledPawns :: Game x y -> CriterionValue criterionValue
measureValueOfDoubledPawns Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ criterionValue
6
) (criterionValue -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> criterionValue)
-> (LogicalColour -> NPieces) -> LogicalColour -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NPieces -> NPieces -> NPieces) -> (NPieces, NPieces) -> NPieces
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((NPieces, NPieces) -> NPieces)
-> (LogicalColour -> (NPieces, NPieces))
-> LogicalColour
-> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> NPieces
countDoubledPawns (LogicalColour -> NPieces)
-> (LogicalColour -> NPieces)
-> LogicalColour
-> (NPieces, NPieces)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& LogicalColour -> NPieces
countDoubledPawns (LogicalColour -> NPieces)
-> (LogicalColour -> LogicalColour) -> LogicalColour -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite
) (LogicalColour -> CriterionValue criterionValue)
-> LogicalColour -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game where
countDoubledPawns :: LogicalColour -> NPieces
countDoubledPawns LogicalColour
logicalColour = (NPieces -> NPieces -> NPieces) -> (NPieces, NPieces) -> NPieces
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((NPieces, NPieces) -> NPieces)
-> (Map x NPieces -> (NPieces, NPieces))
-> Map x NPieces
-> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
(NPieces -> NPieces -> NPieces)
-> NPieces -> Map x NPieces -> NPieces
forall a b k. (a -> b -> a) -> a -> Map k b -> a
Data.Map.foldl' NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
(+) NPieces
0 (Map x NPieces -> NPieces)
-> (Map x NPieces -> NPieces)
-> Map x NPieces
-> (NPieces, NPieces)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Map x NPieces -> NPieces
forall k a. Map k a -> NPieces
Data.Map.size
) (Map x NPieces -> NPieces) -> Map x NPieces -> NPieces
forall a b. (a -> b) -> a -> b
$ Board x y -> NPiecesByFileByLogicalColour x
forall x y. Board x y -> NPiecesByFileByLogicalColour x
State.Board.getNPawnsByFileByLogicalColour (Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game) NPiecesByFileByLogicalColour x -> LogicalColour -> Map x NPieces
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! LogicalColour
logicalColour
measureValueOfIsolatedPawns :: (
Enum x,
Fractional criterionValue,
Ord criterionValue,
Ord x
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
{-# SPECIALISE measureValueOfIsolatedPawns :: Model.Game.Game T.X T.Y -> Attribute.CriterionValue.CriterionValue T.CriterionValue #-}
measureValueOfIsolatedPawns :: Game x y -> CriterionValue criterionValue
measureValueOfIsolatedPawns Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
Cartesian.Abscissa.xLength
) (criterionValue -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> criterionValue)
-> (LogicalColour -> NPieces) -> LogicalColour -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NPieces -> NPieces -> NPieces) -> (NPieces, NPieces) -> NPieces
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((NPieces, NPieces) -> NPieces)
-> (LogicalColour -> (NPieces, NPieces))
-> LogicalColour
-> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> NPieces
countIsolatedPawns (LogicalColour -> NPieces)
-> (LogicalColour -> NPieces)
-> LogicalColour
-> (NPieces, NPieces)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& LogicalColour -> NPieces
countIsolatedPawns (LogicalColour -> NPieces)
-> (LogicalColour -> LogicalColour) -> LogicalColour -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite
) (LogicalColour -> CriterionValue criterionValue)
-> LogicalColour -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game where
countIsolatedPawns :: Attribute.LogicalColour.LogicalColour -> Component.Piece.NPieces
countIsolatedPawns :: LogicalColour -> NPieces
countIsolatedPawns LogicalColour
logicalColour = (NPieces -> x -> NPieces -> NPieces)
-> NPieces -> Map x NPieces -> NPieces
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Data.Map.foldlWithKey' (
\NPieces
acc x
x NPieces
nPawns -> (
if (x -> Map x NPieces -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`Data.Map.notMember` Map x NPieces
nPawnsByFile) (x -> Bool) -> [x] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
`all` x -> [x]
forall x. (Enum x, Eq x) => x -> [x]
Cartesian.Abscissa.getAdjacents x
x
then (NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
+ NPieces
nPawns)
else NPieces -> NPieces
forall a. a -> a
id
) NPieces
acc
) NPieces
0 Map x NPieces
nPawnsByFile where
nPawnsByFile :: Map x NPieces
nPawnsByFile = Board x y -> NPiecesByFileByLogicalColour x
forall x y. Board x y -> NPiecesByFileByLogicalColour x
State.Board.getNPawnsByFileByLogicalColour (Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game) NPiecesByFileByLogicalColour x -> LogicalColour -> Map x NPieces
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! LogicalColour
logicalColour
measureValueOfPassedPawns :: forall x y criterionValue. (
Enum y,
Fractional criterionValue,
Ord criterionValue
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
{-# SPECIALISE measureValueOfPassedPawns :: Model.Game.Game T.X T.Y -> Attribute.CriterionValue.CriterionValue T.CriterionValue #-}
measureValueOfPassedPawns :: Game x y -> CriterionValue criterionValue
measureValueOfPassedPawns Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
Cartesian.Abscissa.xLength
) (criterionValue -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (criterionValue -> criterionValue -> criterionValue)
-> (criterionValue, criterionValue) -> criterionValue
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((criterionValue, criterionValue) -> criterionValue)
-> (LogicalColour -> (criterionValue, criterionValue))
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
LogicalColour -> criterionValue
valuePassedPawns (LogicalColour -> criterionValue)
-> (LogicalColour -> LogicalColour)
-> LogicalColour
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite (LogicalColour -> criterionValue)
-> (LogicalColour -> criterionValue)
-> LogicalColour
-> (criterionValue, criterionValue)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& LogicalColour -> criterionValue
valuePassedPawns
) (LogicalColour -> CriterionValue criterionValue)
-> LogicalColour -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game where
valuePassedPawns :: Attribute.LogicalColour.LogicalColour -> criterionValue
valuePassedPawns :: LogicalColour -> criterionValue
valuePassedPawns LogicalColour
logicalColour = (criterionValue -> Coordinates x y -> criterionValue)
-> criterionValue -> [Coordinates x y] -> criterionValue
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Data.List.foldl' (
\criterionValue
acc -> (criterionValue
acc criterionValue -> criterionValue -> criterionValue
forall a. Num a => a -> a -> a
+) (criterionValue -> criterionValue)
-> (Coordinates x y -> criterionValue)
-> Coordinates x y
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. criterionValue -> criterionValue
forall a. Fractional a => a -> a
recip (criterionValue -> criterionValue)
-> (Coordinates x y -> criterionValue)
-> Coordinates x y
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> criterionValue)
-> (Coordinates x y -> NPieces)
-> Coordinates x y
-> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> NPieces
forall a. Num a => a -> a
abs (NPieces -> NPieces)
-> (Coordinates x y -> NPieces) -> Coordinates x y -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
+ y -> NPieces
forall a. Enum a => a -> NPieces
fromEnum (
LogicalColour -> y
forall y. Enum y => LogicalColour -> y
Cartesian.Ordinate.lastRank LogicalColour
logicalColour :: y
)
) (NPieces -> NPieces)
-> (Coordinates x y -> NPieces) -> Coordinates x y -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> NPieces
forall a. Num a => a -> a
negate (NPieces -> NPieces)
-> (Coordinates x y -> NPieces) -> Coordinates x y -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. y -> NPieces
forall a. Enum a => a -> NPieces
fromEnum (y -> NPieces)
-> (Coordinates x y -> y) -> Coordinates x y -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coordinates x y -> y
forall x y. Coordinates x y -> y
Cartesian.Coordinates.getY
) criterionValue
0 ([Coordinates x y] -> criterionValue)
-> [Coordinates x y] -> criterionValue
forall a b. (a -> b) -> a -> b
$ Board x y -> CoordinatesByLogicalColour x y
forall x y. Board x y -> CoordinatesByLogicalColour x y
State.Board.getPassedPawnCoordinatesByLogicalColour (Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game) CoordinatesByLogicalColour x y
-> LogicalColour -> [Coordinates x y]
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! LogicalColour
logicalColour
maximumDefended :: Component.Piece.NPieces
maximumDefended :: NPieces
maximumDefended = (NPieces
9 NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
+ NPieces
1 NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
+ NPieces
2 NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
+ NPieces
2 ) NPieces -> NPieces -> NPieces
forall a. Num a => a -> a -> a
* NPieces
Attribute.Direction.nDistinctDirections
measureValueOfDefence :: (
Fractional criterionValue,
Ord criterionValue
) => Model.Game.Game x y -> Attribute.CriterionValue.CriterionValue criterionValue
measureValueOfDefence :: Game x y -> CriterionValue criterionValue
measureValueOfDefence Game x y
game = criterionValue -> CriterionValue criterionValue
forall criterionValue.
(Num criterionValue, Ord criterionValue) =>
criterionValue -> CriterionValue criterionValue
Attribute.CriterionValue.mkCriterionValue (criterionValue -> CriterionValue criterionValue)
-> (Board x y -> criterionValue)
-> Board x y
-> CriterionValue criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
criterionValue -> criterionValue -> criterionValue
forall a. Fractional a => a -> a -> a
/ NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral NPieces
maximumDefended
) (criterionValue -> criterionValue)
-> (Board x y -> criterionValue) -> Board x y -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPieces -> criterionValue
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NPieces -> criterionValue)
-> (Board x y -> NPieces) -> Board x y -> criterionValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NPieces -> NPieces -> NPieces) -> (NPieces, NPieces) -> NPieces
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) ((NPieces, NPieces) -> NPieces)
-> (Board x y -> (NPieces, NPieces)) -> Board x y -> NPieces
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
(Array LogicalColour NPieces -> LogicalColour -> NPieces
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite LogicalColour
nextLogicalColour) (Array LogicalColour NPieces -> NPieces)
-> (Array LogicalColour NPieces -> NPieces)
-> Array LogicalColour NPieces
-> (NPieces, NPieces)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& (Array LogicalColour NPieces -> LogicalColour -> NPieces
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! LogicalColour
nextLogicalColour)
) (Array LogicalColour NPieces -> (NPieces, NPieces))
-> (Board x y -> Array LogicalColour NPieces)
-> Board x y
-> (NPieces, NPieces)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Board x y -> Array LogicalColour NPieces
forall x y. Board x y -> Array LogicalColour NPieces
State.Board.summariseNDefendersByLogicalColour (Board x y -> CriterionValue criterionValue)
-> Board x y -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Game x y -> Board x y
forall x y. Game x y -> Board x y
Model.Game.getBoard Game x y
game where
nextLogicalColour :: LogicalColour
nextLogicalColour = Game x y -> LogicalColour
forall x y. Game x y -> LogicalColour
Model.Game.getNextLogicalColour Game x y
game
evaluateFitness :: (
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 (
Attribute.WeightedMeanAndCriterionValues.WeightedMeanAndCriterionValues weightedMean criterionValue
)
{-# SPECIALISE evaluateFitness :: Maybe T.PieceSquareValue -> Model.Game.Game T.X T.Y -> Input.EvaluationOptions.Reader T.CriterionWeight T.PieceSquareValue T.RankValue T.X T.Y (Attribute.WeightedMeanAndCriterionValues.WeightedMeanAndCriterionValues T.WeightedMean T.CriterionValue) #-}
evaluateFitness :: Maybe pieceSquareValue
-> Game x y
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
evaluateFitness Maybe pieceSquareValue
maybePieceSquareValue Game x y
game
| Just GameTerminationReason
gameTerminationReason <- Game x y -> Maybe GameTerminationReason
forall x y. Game x y -> Maybe GameTerminationReason
Model.Game.getMaybeTerminationReason Game x y
game = WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
forall (m :: * -> *) a. Monad m => a -> m a
return (WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue))
-> WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
forall a b. (a -> b) -> a -> b
$ weightedMean
-> [criterionValue]
-> WeightedMeanAndCriterionValues weightedMean criterionValue
forall weightedMean criterionValue.
weightedMean
-> [criterionValue]
-> WeightedMeanAndCriterionValues weightedMean criterionValue
Attribute.WeightedMeanAndCriterionValues.mkWeightedMeanAndCriterionValues (
if GameTerminationReason -> Bool
Model.GameTerminationReason.isCheckMate GameTerminationReason
gameTerminationReason
then weightedMean
1
else weightedMean
0
) []
| Bool
otherwise = do
CriteriaWeights criterionWeight
criteriaWeights <- (EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> CriteriaWeights criterionWeight)
-> ReaderT
(EvaluationOptions criterionWeight pieceSquareValue rankValue x y)
Identity
(CriteriaWeights criterionWeight)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Control.Monad.Reader.asks EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> CriteriaWeights criterionWeight
forall criterionWeight pieceSquareValue rankValue x y.
EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> CriteriaWeights criterionWeight
Input.EvaluationOptions.getCriteriaWeights
RankValues rankValue
rankValues <- (EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> RankValues rankValue)
-> ReaderT
(EvaluationOptions criterionWeight pieceSquareValue rankValue x y)
Identity
(RankValues rankValue)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Control.Monad.Reader.asks EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> RankValues rankValue
forall criterionWeight pieceSquareValue rankValue x y.
EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> RankValues rankValue
Input.EvaluationOptions.getRankValues
Maybe (PieceSquareArray x y pieceSquareValue)
maybePieceSquareArray <- (EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> Maybe (PieceSquareArray x y pieceSquareValue))
-> ReaderT
(EvaluationOptions criterionWeight pieceSquareValue rankValue x y)
Identity
(Maybe (PieceSquareArray x y pieceSquareValue))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Control.Monad.Reader.asks EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> Maybe (PieceSquareArray x y pieceSquareValue)
forall criterionWeight pieceSquareValue rankValue x y.
EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> Maybe (PieceSquareArray x y pieceSquareValue)
Input.EvaluationOptions.getMaybePieceSquareArray
WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
forall (m :: * -> *) a. Monad m => a -> m a
return (WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue))
-> WeightedMeanAndCriterionValues weightedMean criterionValue
-> Reader
criterionWeight
pieceSquareValue
rankValue
x
y
(WeightedMeanAndCriterionValues weightedMean criterionValue)
forall a b. (a -> b) -> a -> b
$ CriteriaWeights criterionWeight
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> WeightedMeanAndCriterionValues weightedMean criterionValue
forall weightedMean criterionValue criterionWeight.
(Fractional weightedMean, Real criterionValue,
Real criterionWeight) =>
CriteriaWeights criterionWeight
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> CriterionValue criterionValue
-> WeightedMeanAndCriterionValues weightedMean criterionValue
Input.CriteriaWeights.calculateWeightedMean CriteriaWeights criterionWeight
criteriaWeights (
RankValues rankValue -> Game x y -> CriterionValue criterionValue
forall criterionValue rankValue x y.
(Fractional criterionValue, Fractional rankValue,
Ord criterionValue, Real rankValue) =>
RankValues rankValue -> Game x y -> CriterionValue criterionValue
measureValueOfMaterial RankValues rankValue
rankValues Game x y
game
) (
Game x y -> CriterionValue criterionValue
forall x y criterionValue.
(Enum x, Enum y, Fractional criterionValue, Ord criterionValue,
Ord x, Ord y, Show x, Show y) =>
Game x y -> CriterionValue criterionValue
measureValueOfMobility Game x y
game
) (
CriterionValue criterionValue
-> (pieceSquareValue -> CriterionValue criterionValue)
-> Maybe pieceSquareValue
-> CriterionValue criterionValue
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe CriterionValue criterionValue
forall criterionValue.
Num criterionValue =>
CriterionValue criterionValue
Attribute.CriterionValue.zero pieceSquareValue -> CriterionValue criterionValue
forall criterionValue pieceSquareValue.
(Fractional criterionValue, Ord criterionValue,
Real pieceSquareValue) =>
pieceSquareValue -> CriterionValue criterionValue
mkPieceSquareCriterionValue (Maybe pieceSquareValue -> CriterionValue criterionValue)
-> Maybe pieceSquareValue -> CriterionValue criterionValue
forall a b. (a -> b) -> a -> b
$ Maybe pieceSquareValue
maybePieceSquareValue Maybe pieceSquareValue
-> Maybe pieceSquareValue -> Maybe pieceSquareValue
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (PieceSquareArray x y pieceSquareValue -> pieceSquareValue)
-> Maybe (PieceSquareArray x y pieceSquareValue)
-> Maybe pieceSquareValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (
PieceSquareArray x y pieceSquareValue
-> Game x y -> pieceSquareValue
forall x y pieceSquareValue.
(Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) =>
PieceSquareArray x y pieceSquareValue
-> Game x y -> pieceSquareValue
`measurePieceSquareValue` Game x y
game
) Maybe (PieceSquareArray x y pieceSquareValue)
maybePieceSquareArray
) (
Game x y -> CriterionValue criterionValue
forall criterionValue x y.
(Fractional criterionValue, Ord criterionValue) =>
Game x y -> CriterionValue criterionValue
measureValueOfCastlingPotential Game x y
game
) (
Game x y -> CriterionValue criterionValue
forall criterionValue x y.
(Fractional criterionValue, Ord criterionValue) =>
Game x y -> CriterionValue criterionValue
measureValueOfDefence Game x y
game
) (
Game x y -> CriterionValue criterionValue
forall criterionValue x y.
(Fractional criterionValue, Ord criterionValue) =>
Game x y -> CriterionValue criterionValue
measureValueOfDoubledPawns Game x y
game
) (
Game x y -> CriterionValue criterionValue
forall x criterionValue y.
(Enum x, Fractional criterionValue, Ord criterionValue, Ord x) =>
Game x y -> CriterionValue criterionValue
measureValueOfIsolatedPawns Game x y
game
) (
Game x y -> CriterionValue criterionValue
forall x y criterionValue.
(Enum y, Fractional criterionValue, Ord criterionValue) =>
Game x y -> CriterionValue criterionValue
measureValueOfPassedPawns Game x y
game
)