module BishBosh.UI.SetObject (
SetObject(..),
searchDepthTag,
autoComplete,
mkEPD,
mkSearchDepth
) where
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Input.SearchOptions as Input.SearchOptions
import qualified BishBosh.Model.Game as Model.Game
import qualified BishBosh.Property.ExtendedPositionDescription as Property.ExtendedPositionDescription
import qualified BishBosh.Text.AutoComplete as Text.AutoComplete
import qualified BishBosh.Type.Count as Type.Count
import qualified Control.Arrow
import qualified Control.DeepSeq
import qualified Control.Exception
import qualified Data.List.Extra
searchDepthTag :: String
searchDepthTag :: String
searchDepthTag = String
Input.SearchOptions.searchDepthTag
data SetObject
= EPD Model.Game.Game
| SearchDepth Type.Count.NPlies
deriving SetObject -> SetObject -> Bool
(SetObject -> SetObject -> Bool)
-> (SetObject -> SetObject -> Bool) -> Eq SetObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetObject -> SetObject -> Bool
$c/= :: SetObject -> SetObject -> Bool
== :: SetObject -> SetObject -> Bool
$c== :: SetObject -> SetObject -> Bool
Eq
instance Control.DeepSeq.NFData SetObject where
rnf :: SetObject -> ()
rnf (EPD Game
epd) = Game -> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf Game
epd
rnf (SearchDepth NPlies
searchDepth) = NPlies -> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf NPlies
searchDepth
instance Show SetObject where
showsPrec :: NPlies -> SetObject -> ShowS
showsPrec NPlies
_ (EPD Game
epd) = String -> ShowS
showString String
Property.ExtendedPositionDescription.tag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Game -> ShowS
forall a. ShowsEPD a => a -> ShowS
Property.ExtendedPositionDescription.showsEPD Game
epd
showsPrec NPlies
_ (SearchDepth NPlies
searchDepth) = String -> ShowS
showString String
searchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
searchDepth
instance Read SetObject where
readsPrec :: NPlies -> ReadS SetObject
readsPrec NPlies
precedence String
s = case ShowS -> (String, String) -> (String, String)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Control.Arrow.first ShowS
Data.List.Extra.lower ((String, String) -> (String, String))
-> [(String, String)] -> [(String, String)]
forall a b. (a -> b) -> [a] -> [b]
`map` ReadS String
lex String
s of
[(String
"epd", String
epd)] -> (Game -> SetObject) -> (Game, String) -> (SetObject, String)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Control.Arrow.first Game -> SetObject
EPD ((Game, String) -> (SetObject, String))
-> [(Game, String)] -> [(SetObject, String)]
forall a b. (a -> b) -> [a] -> [b]
`map` ReadS Game
forall a. ReadsEPD a => ReadS a
Property.ExtendedPositionDescription.readsEPD String
epd
[(String
"searchdepth", String
s')] -> (Integer -> SetObject) -> (Integer, String) -> (SetObject, String)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Control.Arrow.first (NPlies -> SetObject
mkSearchDepth (NPlies -> SetObject)
-> (Integer -> NPlies) -> Integer -> SetObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NPlies
forall a. Num a => Integer -> a
fromInteger) ((Integer, String) -> (SetObject, String))
-> [(Integer, String)] -> [(SetObject, String)]
forall a b. (a -> b) -> [a] -> [b]
`map` NPlies -> ReadS Integer
forall a. Read a => NPlies -> ReadS a
readsPrec NPlies
precedence String
s'
[(String, String)]
_ -> []
mkEPD :: Model.Game.Game -> SetObject
mkEPD :: Game -> SetObject
mkEPD = Game -> SetObject
EPD
mkSearchDepth :: Type.Count.NPlies -> SetObject
mkSearchDepth :: NPlies -> SetObject
mkSearchDepth NPlies
searchDepth
| NPlies
searchDepth NPlies -> NPlies -> Bool
forall a. Ord a => a -> a -> Bool
< NPlies
Input.SearchOptions.minimumSearchDepth = Exception -> SetObject
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SetObject)
-> (String -> Exception) -> String -> SetObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkOutOfBounds (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.UI.SetObject.mkSearchDepth:\t" (String -> SetObject) -> String -> SetObject
forall a b. (a -> b) -> a -> b
$ String -> ShowS
forall a. Show a => a -> ShowS
shows String
Input.SearchOptions.searchDepthTag String
" must be positive."
| Bool
otherwise = NPlies -> SetObject
SearchDepth NPlies
searchDepth
autoComplete :: ShowS
autoComplete :: ShowS
autoComplete = [String] -> ShowS
Text.AutoComplete.autoComplete [String
Property.ExtendedPositionDescription.tag, String
searchDepthTag]