module BishBosh.Input.Options(
RandomSeed,
Options(
getMaybeMaximumPlies,
getMaybeRandomSeed,
getEvaluationOptions,
getSearchOptions,
getIOOptions
),
tag,
maximumPliesTag,
randomSeedTag,
mkOptions,
setMaybeOutputConfigFilePath,
setMaybeRandomSeed,
setMaybePersistence,
setVerbosity,
setEitherNativeUIOrCECPOptions,
setMaybePrintMoveTree,
swapSearchDepth
) where
import BishBosh.Data.Bool()
import BishBosh.Data.Integral()
import qualified BishBosh.Component.Move as Component.Move
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Input.EvaluationOptions as Input.EvaluationOptions
import qualified BishBosh.Input.IOOptions as Input.IOOptions
import qualified BishBosh.Input.SearchOptions as Input.SearchOptions
import qualified BishBosh.Input.UIOptions as Input.UIOptions
import qualified BishBosh.Property.ShowFloat as Property.ShowFloat
import qualified BishBosh.Property.Tree as Property.Tree
import qualified BishBosh.Text.ShowList as Text.ShowList
import qualified Control.DeepSeq
import qualified Control.Exception
import qualified Data.Default
import qualified Data.Maybe
import qualified Distribution.Verbosity
import qualified System.FilePath
import qualified Text.XML.HXT.Arrow.Pickle as HXT
tag :: String
tag = "options"
maximumPliesTag :: String
maximumPliesTag = "maximumPlies"
randomSeedTag :: String
randomSeedTag = "randomSeed"
type RandomSeed = Int
data Options column criterionWeight pieceSquareValue rankValue row x y = MkOptions {
getMaybeMaximumPlies :: Maybe Component.Move.NMoves,
getMaybeRandomSeed :: Maybe RandomSeed,
getEvaluationOptions :: Input.EvaluationOptions.EvaluationOptions criterionWeight pieceSquareValue rankValue x y,
getSearchOptions :: Input.SearchOptions.SearchOptions,
getIOOptions :: Input.IOOptions.IOOptions row column
} deriving (Eq, Show)
instance (
Control.DeepSeq.NFData column,
Control.DeepSeq.NFData criterionWeight,
Control.DeepSeq.NFData pieceSquareValue,
Control.DeepSeq.NFData rankValue,
Control.DeepSeq.NFData row,
Control.DeepSeq.NFData x,
Control.DeepSeq.NFData y
) => Control.DeepSeq.NFData (Options column criterionWeight pieceSquareValue rankValue row x y) where
rnf MkOptions {
getMaybeMaximumPlies = maybeMaximumPlies,
getMaybeRandomSeed = maybeRandomSeed,
getEvaluationOptions = evaluationOptions,
getSearchOptions = searchOptions,
getIOOptions = ioOptions
} = Control.DeepSeq.rnf (maybeMaximumPlies, maybeRandomSeed, evaluationOptions, searchOptions, ioOptions)
instance (
Enum x,
Enum y,
Ord x,
Ord y,
Real criterionWeight,
Real pieceSquareValue,
Real rankValue,
Show column,
Show pieceSquareValue,
Show row
) => Property.ShowFloat.ShowFloat (Options column criterionWeight pieceSquareValue rankValue row x y) where
showsFloat fromDouble MkOptions {
getMaybeMaximumPlies = maybeMaximumPlies,
getMaybeRandomSeed = maybeRandomSeed,
getEvaluationOptions = evaluationOptions,
getSearchOptions = searchOptions,
getIOOptions = ioOptions
} = Text.ShowList.showsAssociationList' . Data.Maybe.maybe id (
(:) . (,) maximumPliesTag . shows
) maybeMaximumPlies $ Data.Maybe.maybe id (
(:) . (,) randomSeedTag . shows
) maybeRandomSeed [
(
Input.EvaluationOptions.tag,
Property.ShowFloat.showsFloat fromDouble evaluationOptions
), (
Input.SearchOptions.tag,
shows searchOptions
), (
Input.IOOptions.tag,
shows ioOptions
)
]
instance (
Fractional rankValue,
Num criterionWeight,
Num column,
Num row,
Ord rankValue,
Show rankValue
) => Data.Default.Default (Options column criterionWeight pieceSquareValue rankValue row x y) where
def = MkOptions {
getMaybeMaximumPlies = Nothing,
getMaybeRandomSeed = Nothing,
getEvaluationOptions = Data.Default.def,
getSearchOptions = Data.Default.def,
getIOOptions = Data.Default.def
}
instance (
Enum x,
Enum y,
Fractional pieceSquareValue,
Fractional rankValue,
HXT.XmlPickler column,
HXT.XmlPickler criterionWeight,
HXT.XmlPickler rankValue,
HXT.XmlPickler row,
Integral column,
Integral row,
Num criterionWeight,
Ord pieceSquareValue,
Ord rankValue,
Ord x,
Ord y,
Real criterionWeight,
Real pieceSquareValue,
Show column,
Show criterionWeight,
Show pieceSquareValue,
Show rankValue,
Show row
) => HXT.XmlPickler (Options column criterionWeight pieceSquareValue rankValue row x y) where
xpickle = HXT.xpElem tag . HXT.xpWrap (
\(a, b, c, d, e) -> mkOptions a b c d e,
\MkOptions {
getMaybeMaximumPlies = maybeMaximumPlies,
getMaybeRandomSeed = maybeRandomSeed,
getEvaluationOptions = evaluationOptions,
getSearchOptions = searchOptions,
getIOOptions = ioOptions
} -> (
maybeMaximumPlies,
maybeRandomSeed,
evaluationOptions,
searchOptions,
ioOptions
)
) $ HXT.xp5Tuple (
HXT.xpAttrImplied maximumPliesTag HXT.xpInt
) (
HXT.xpAttrImplied randomSeedTag HXT.xpInt
) HXT.xpickle HXT.xpickle HXT.xpickle
mkOptions
:: Maybe Component.Move.NMoves
-> Maybe RandomSeed
-> Input.EvaluationOptions.EvaluationOptions criterionWeight pieceSquareValue rankValue x y
-> Input.SearchOptions.SearchOptions
-> Input.IOOptions.IOOptions row column
-> Options column criterionWeight pieceSquareValue rankValue row x y
mkOptions maybeMaximumPlies maybeRandomSeed evaluationOptions searchOptions ioOptions
| Just maximumPlies <- maybeMaximumPlies
, maximumPlies <= 0 = Control.Exception.throw . Data.Exception.mkOutOfBounds . showString "BishBosh.Input.Options.mkOptions:\t" . showString maximumPliesTag . Text.ShowList.showsAssociation $ shows maximumPlies " must exceed zero."
| otherwise = MkOptions {
getMaybeMaximumPlies = maybeMaximumPlies,
getMaybeRandomSeed = maybeRandomSeed,
getEvaluationOptions = evaluationOptions,
getSearchOptions = searchOptions,
getIOOptions = ioOptions
}
type Transformation column criterionWeight pieceSquareValue rankValue row x y = Options column criterionWeight pieceSquareValue rankValue row x y -> Options column criterionWeight pieceSquareValue rankValue row x y
setMaybeOutputConfigFilePath :: Maybe System.FilePath.FilePath -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setMaybeOutputConfigFilePath maybeOutputConfigFilePath options@MkOptions { getIOOptions = ioOptions } = options {
getIOOptions = Input.IOOptions.setMaybeOutputConfigFilePath maybeOutputConfigFilePath ioOptions
}
setMaybeRandomSeed :: Maybe RandomSeed -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setMaybeRandomSeed maybeRandomSeed options = options {
getMaybeRandomSeed = maybeRandomSeed
}
setMaybePersistence :: Maybe (System.FilePath.FilePath, Bool) -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setMaybePersistence maybePersistence options@MkOptions { getIOOptions = ioOptions } = options {
getIOOptions = ioOptions {
Input.IOOptions.getMaybePersistence = maybePersistence
}
}
setVerbosity :: Distribution.Verbosity.Verbosity -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setVerbosity verbosity options@MkOptions { getIOOptions = ioOptions } = options {
getIOOptions = Input.IOOptions.setVerbosity verbosity ioOptions
}
setEitherNativeUIOrCECPOptions :: Input.UIOptions.EitherNativeUIOrCECPOptions row column -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setEitherNativeUIOrCECPOptions eitherNativeUIOrCECPOptions options@MkOptions { getIOOptions = ioOptions } = options {
getIOOptions = Input.IOOptions.setEitherNativeUIOrCECPOptions eitherNativeUIOrCECPOptions ioOptions
}
setMaybePrintMoveTree :: Maybe Property.Tree.Depth -> Transformation column criterionWeight pieceSquareValue rankValue row x y
setMaybePrintMoveTree maybePrintMoveTree options@MkOptions { getIOOptions = ioOptions } = options {
getIOOptions = Input.IOOptions.setMaybePrintMoveTree maybePrintMoveTree ioOptions
}
swapSearchDepth :: Transformation column criterionWeight pieceSquareValue rankValue row x y
swapSearchDepth options@MkOptions { getSearchOptions = searchOptions } = options {
getSearchOptions = Input.SearchOptions.swapSearchDepth searchOptions
}