module BishBosh.Component.PieceSquareArray(
InterpolatedPieceSquareValues,
FindPieceSquareValue,
PieceSquareArray,
findPieceSquareValue,
mkPieceSquareArray
) where
import BishBosh.Data.Bool()
import Data.Array.IArray((!))
import qualified BishBosh.Attribute.LogicalColour as Attribute.LogicalColour
import qualified BishBosh.Attribute.Rank as Attribute.Rank
import qualified BishBosh.Cartesian.Coordinates as Cartesian.Coordinates
import qualified BishBosh.Component.Piece as Component.Piece
import qualified BishBosh.Property.Reflectable as Property.Reflectable
import qualified Control.DeepSeq
import qualified Data.Array.IArray
type InterpolatedPieceSquareValues pieceSquareValue = Either pieceSquareValue (Data.Array.IArray.Array Component.Piece.NPieces pieceSquareValue)
type InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue = Cartesian.Coordinates.ByCoordinates x y (InterpolatedPieceSquareValues pieceSquareValue)
newtype PieceSquareArray x y pieceSquareValue = MkPieceSquareArray {
PieceSquareArray x y pieceSquareValue
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
deconstruct :: Attribute.Rank.ByRank (InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
} deriving (PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
(PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool)
-> (PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool)
-> Eq (PieceSquareArray x y pieceSquareValue)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Eq pieceSquareValue) =>
PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
/= :: PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
$c/= :: forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Eq pieceSquareValue) =>
PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
== :: PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
$c== :: forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Eq pieceSquareValue) =>
PieceSquareArray x y pieceSquareValue
-> PieceSquareArray x y pieceSquareValue -> Bool
Eq, Int -> PieceSquareArray x y pieceSquareValue -> ShowS
[PieceSquareArray x y pieceSquareValue] -> ShowS
PieceSquareArray x y pieceSquareValue -> String
(Int -> PieceSquareArray x y pieceSquareValue -> ShowS)
-> (PieceSquareArray x y pieceSquareValue -> String)
-> ([PieceSquareArray x y pieceSquareValue] -> ShowS)
-> Show (PieceSquareArray x y pieceSquareValue)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
Int -> PieceSquareArray x y pieceSquareValue -> ShowS
forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
[PieceSquareArray x y pieceSquareValue] -> ShowS
forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
PieceSquareArray x y pieceSquareValue -> String
showList :: [PieceSquareArray x y pieceSquareValue] -> ShowS
$cshowList :: forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
[PieceSquareArray x y pieceSquareValue] -> ShowS
show :: PieceSquareArray x y pieceSquareValue -> String
$cshow :: forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
PieceSquareArray x y pieceSquareValue -> String
showsPrec :: Int -> PieceSquareArray x y pieceSquareValue -> ShowS
$cshowsPrec :: forall x y pieceSquareValue.
(Enum x, Enum y, Ord x, Ord y, Show x, Show y,
Show pieceSquareValue) =>
Int -> PieceSquareArray x y pieceSquareValue -> ShowS
Show)
instance (
Control.DeepSeq.NFData pieceSquareValue,
Control.DeepSeq.NFData x,
Control.DeepSeq.NFData y
) => Control.DeepSeq.NFData (PieceSquareArray x y pieceSquareValue) where
rnf :: PieceSquareArray x y pieceSquareValue -> ()
rnf MkPieceSquareArray { deconstruct :: forall x y pieceSquareValue.
PieceSquareArray x y pieceSquareValue
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
deconstruct = ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
byRank } = ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
byRank
mkPieceSquareArray :: (Attribute.Rank.Rank -> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue) -> PieceSquareArray x y pieceSquareValue
mkPieceSquareArray :: (Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> PieceSquareArray x y pieceSquareValue
mkPieceSquareArray = ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> PieceSquareArray x y pieceSquareValue
forall x y pieceSquareValue.
ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> PieceSquareArray x y pieceSquareValue
MkPieceSquareArray (ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> PieceSquareArray x y pieceSquareValue)
-> ((Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue))
-> (Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> PieceSquareArray x y pieceSquareValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue]
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
forall (a :: * -> * -> *) e. IArray a e => [e] -> a Rank e
Attribute.Rank.listArrayByRank ([InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue]
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue))
-> ((Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> [InterpolatedPieceSquareValuesByCoordinates
x y pieceSquareValue])
-> (Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> [Rank]
-> [InterpolatedPieceSquareValuesByCoordinates
x y pieceSquareValue]
forall a b. (a -> b) -> [a] -> [b]
`map` [Rank]
Attribute.Rank.range)
type FindPieceSquareValue x y pieceSquareValue
= Attribute.LogicalColour.LogicalColour
-> Attribute.Rank.Rank
-> Cartesian.Coordinates.Coordinates x y
-> pieceSquareValue
findPieceSquareValue :: (
Enum x,
Enum y,
Ord x,
Ord y
)
=> Component.Piece.NPieces
-> Attribute.LogicalColour.LogicalColour
-> Attribute.Rank.Rank
-> Cartesian.Coordinates.Coordinates x y
-> PieceSquareArray x y pieceSquareValue
-> pieceSquareValue
{-# INLINE findPieceSquareValue #-}
findPieceSquareValue :: Int
-> LogicalColour
-> Rank
-> Coordinates x y
-> PieceSquareArray x y pieceSquareValue
-> pieceSquareValue
findPieceSquareValue Int
nPieces LogicalColour
logicalColour Rank
rank Coordinates x y
coordinates MkPieceSquareArray { deconstruct :: forall x y pieceSquareValue.
PieceSquareArray x y pieceSquareValue
-> ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
deconstruct = ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
byRank } = (pieceSquareValue -> pieceSquareValue)
-> (Array Int pieceSquareValue -> pieceSquareValue)
-> Either pieceSquareValue (Array Int pieceSquareValue)
-> pieceSquareValue
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either pieceSquareValue -> pieceSquareValue
forall a. a -> a
id (Array Int pieceSquareValue -> Int -> pieceSquareValue
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! Int
nPieces) (Either pieceSquareValue (Array Int pieceSquareValue)
-> pieceSquareValue)
-> Either pieceSquareValue (Array Int pieceSquareValue)
-> pieceSquareValue
forall a b. (a -> b) -> a -> b
$ ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
byRank ByRank
(InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue)
-> Rank
-> InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! Rank
rank InterpolatedPieceSquareValuesByCoordinates x y pieceSquareValue
-> Coordinates x y
-> Either pieceSquareValue (Array Int pieceSquareValue)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
! (
if LogicalColour -> Bool
Attribute.LogicalColour.isBlack LogicalColour
logicalColour
then Coordinates x y -> Coordinates x y
forall a. ReflectableOnX a => a -> a
Property.Reflectable.reflectOnX
else Coordinates x y -> Coordinates x y
forall a. a -> a
id
) Coordinates x y
coordinates