{-
	Copyright (C) 2018 Dr. Alistair Ward

	This file is part of BishBosh.

	BishBosh is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	BishBosh is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with BishBosh.  If not, see <http://www.gnu.org/licenses/>.
-}
{- |
 [@AUTHOR@]	Dr. Alistair Ward

 [@DESCRIPTION@]	Defines configurable options related to the process of searching for the optimal move.
-}

module BishBosh.Input.SearchOptions(
-- * Types
-- ** Type-synonyms
	SortOnStandardOpeningMoveFrequency,
	HammingDistance,
--	Transformation,
--	RecordKillerMoves,
	MaybeRetireAfterNMoves,
	TrapRepeatedPositions,
--	UsePondering,
	MaybeUseTranspositions,
--	StandardOpeningOptions,
--	SearchDepthByLogicalColour,
	Reader,
-- ** Data-types
	SearchOptions(
--		MkSearchOptions,
		getSortOnStandardOpeningMoveFrequency,
		getMaybeCaptureMoveSortAlgorithm,
		getMaybeMinimumHammingDistance,
		getMaybeRetireKillerMovesAfter,
		getTrapRepeatedPositions,
		getUsePondering,
		getMaybeUseTranspositions,
		getStandardOpeningOptions,
		getSearchDepthByLogicalColour
	),
-- * Constants
	tag,
	sortOnStandardOpeningMoveFrequencyTag,
--	minimumHammingDistanceTag,
--	retireKillerMovesAfterTag,
--	trapRepeatedPositionsTag,
--	usePonderingTag,
--	retireTranspositionsAfterTag,
--	minimumTranspositionSearchDepthTag,
--	standardOpeningOptionsTag,
	searchDepthTag,
--	searchDepthByLogicalColourTag
	minimumSearchDepth,
	defaultSearchDepth,
-- * Functions
-- ** Constructor
	mkSearchOptions,
-- ** Accessors
	getSearchDepth,
	maybeRetireTranspositionsAfter,
	maybeMinimumTranspositionSearchDepth,
	identifyAutomatedPlayers,
-- ** Mutators
	setSearchDepth,
	swapSearchDepth,
-- ** Predicates
	recordKillerMoves
) where

import			BishBosh.Data.Bool()		-- For 'HXT.xpickle'.
import			Control.Arrow((***))
import qualified	BishBosh.Attribute.CaptureMoveSortAlgorithm	as Attribute.CaptureMoveSortAlgorithm
import qualified	BishBosh.Attribute.LogicalColour		as Attribute.LogicalColour
import qualified	BishBosh.Data.Exception				as Data.Exception
import qualified	BishBosh.Data.Foldable
import qualified	BishBosh.Input.StandardOpeningOptions		as Input.StandardOpeningOptions
import qualified	BishBosh.Property.Empty				as Property.Empty
import qualified	BishBosh.Property.Opposable			as Property.Opposable
import qualified	BishBosh.Text.Case				as Text.Case
import qualified	BishBosh.Text.ShowList				as Text.ShowList
import qualified	BishBosh.Type.Count				as Type.Count
import qualified	Control.DeepSeq
import qualified	Control.Exception
import qualified	Control.Monad.Reader
import qualified	Data.Default
import qualified	Data.Foldable
import qualified	Data.Map.Strict					as Map
import qualified	Data.Maybe
import qualified	Text.XML.HXT.Arrow.Pickle			as HXT

-- | Used to qualify XML.
tag :: String
tag :: String
tag					= String
"searchOptions"

-- | Used to qualify XML.
sortOnStandardOpeningMoveFrequencyTag :: String
sortOnStandardOpeningMoveFrequencyTag :: String
sortOnStandardOpeningMoveFrequencyTag	= String
"sortOnStandardOpeningMoveFrequency"

-- | Used to qualify XML.
minimumHammingDistanceTag :: String
minimumHammingDistanceTag :: String
minimumHammingDistanceTag		= String
"minimumHammingDistance"

-- | Used to qualify XML.
retireKillerMovesAfterTag :: String
retireKillerMovesAfterTag :: String
retireKillerMovesAfterTag		= String
"retireKillerMovesAfter"

-- | Used to qualify XML.
trapRepeatedPositionsTag :: String
trapRepeatedPositionsTag :: String
trapRepeatedPositionsTag		= String
"trapRepeatedPositions"

-- | Used to qualify XML.
usePonderingTag :: String
usePonderingTag :: String
usePonderingTag				= String
"usePondering"

-- | Used to qualify XML.
retireTranspositionsAfterTag :: String
retireTranspositionsAfterTag :: String
retireTranspositionsAfterTag		= String
"retireTranspositionsAfter"

-- | Used to qualify XML.
minimumTranspositionSearchDepthTag :: String
minimumTranspositionSearchDepthTag :: String
minimumTranspositionSearchDepthTag	= String
"minimumTranspositionSearchDepth"

-- | Used to qualify XML.
searchDepthTag :: String
searchDepthTag :: String
searchDepthTag				= String
"searchDepth"

-- | Used to qualify XML.
searchDepthByLogicalColourTag :: String
searchDepthByLogicalColourTag :: String
searchDepthByLogicalColourTag		= String -> ShowS
showString String
searchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"By" ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ ShowS
Text.Case.toUpperInitial String
Attribute.LogicalColour.tag

-- | The constant minimum permissible search-depth.
minimumSearchDepth :: Type.Count.NPlies
minimumSearchDepth :: NPlies
minimumSearchDepth	= NPlies
1

{- |
	* The constant default search-depth.

	* CAVEAT: this is rather arbitrary.
-}
defaultSearchDepth :: Type.Count.NPlies
defaultSearchDepth :: NPlies
defaultSearchDepth	= NPlies
4

-- | Sort moves on the decreasing frequency of occurrence in standard openings.
type SortOnStandardOpeningMoveFrequency	= Bool

-- | The optional minimum Hamming-distance between the random numbers from which Zobrist-hashes are composed.
type HammingDistance			= Int

-- | The number of full moves (one for each player) after which to retire killer moves.
type MaybeRetireAfterNMoves		= Maybe Type.Count.NMoves

-- | Whether to short-circuit the fitness-evaluation of /position/s which have been visited before in the current /game/.
type TrapRepeatedPositions		= Bool

-- | Whether to ponder about one's next move while the opponent is thinking.
type UsePondering			= Bool

-- | The number of full moves (one for each player) after which to retire transpositions & the search-depth beneath which they aren't recorded at all.
type MaybeUseTranspositions		= Maybe (Type.Count.NMoves, Type.Count.NPlies)

-- | The depth to search for each /logical colour/.
type SearchDepthByLogicalColour		= Map.Map Attribute.LogicalColour.LogicalColour Type.Count.NPlies

-- | Defines options related to searching for a move.
data SearchOptions	= MkSearchOptions {
	SearchOptions -> SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	:: SortOnStandardOpeningMoveFrequency,	-- ^ Whether to sort moves on the decreasing frequency of occurrence in standard openings.
	SearchOptions -> Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	:: Maybe Attribute.CaptureMoveSortAlgorithm.CaptureMoveSortAlgorithm,
	SearchOptions -> Maybe NPlies
getMaybeMinimumHammingDistance		:: Maybe HammingDistance,		-- ^ The optional minimum Hamming-distance between the random numbers from which Zobrist-hashes are composed.
	SearchOptions -> Maybe NPlies
getMaybeRetireKillerMovesAfter		:: MaybeRetireAfterNMoves,		-- ^ The number of full moves (one for each player) after which to retire killer moves.
	SearchOptions -> SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		:: TrapRepeatedPositions,		-- ^ Whether to short-circuit the fitness-evaluation of /position/s which have been visited before in the current /game/.
	SearchOptions -> SortOnStandardOpeningMoveFrequency
getUsePondering				:: UsePondering,			-- ^ Whether to ponder about one's next move while the opponent is thinking.
	SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions		:: MaybeUseTranspositions,
	SearchOptions -> StandardOpeningOptions
getStandardOpeningOptions		:: Input.StandardOpeningOptions.StandardOpeningOptions,
	SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour		:: SearchDepthByLogicalColour		-- ^ The depth to search for each /logical colour/.
} deriving SearchOptions
-> SearchOptions -> SortOnStandardOpeningMoveFrequency
(SearchOptions
 -> SearchOptions -> SortOnStandardOpeningMoveFrequency)
-> (SearchOptions
    -> SearchOptions -> SortOnStandardOpeningMoveFrequency)
-> Eq SearchOptions
forall a.
(a -> a -> SortOnStandardOpeningMoveFrequency)
-> (a -> a -> SortOnStandardOpeningMoveFrequency) -> Eq a
/= :: SearchOptions
-> SearchOptions -> SortOnStandardOpeningMoveFrequency
$c/= :: SearchOptions
-> SearchOptions -> SortOnStandardOpeningMoveFrequency
== :: SearchOptions
-> SearchOptions -> SortOnStandardOpeningMoveFrequency
$c== :: SearchOptions
-> SearchOptions -> SortOnStandardOpeningMoveFrequency
Eq

instance Control.DeepSeq.NFData SearchOptions where
	rnf :: SearchOptions -> ()
rnf MkSearchOptions {
		getSortOnStandardOpeningMoveFrequency :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	= SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency,
		getMaybeCaptureMoveSortAlgorithm :: SearchOptions -> Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	= Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm,
		getMaybeMinimumHammingDistance :: SearchOptions -> Maybe NPlies
getMaybeMinimumHammingDistance		= Maybe NPlies
maybeMinimumHammingDistance,
		getMaybeRetireKillerMovesAfter :: SearchOptions -> Maybe NPlies
getMaybeRetireKillerMovesAfter		= Maybe NPlies
maybeRetireKillerMovesAfter,
		getTrapRepeatedPositions :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		= SortOnStandardOpeningMoveFrequency
trapRepeatedPositions,
		getUsePondering :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getUsePondering				= SortOnStandardOpeningMoveFrequency
usePondering,
		getMaybeUseTranspositions :: SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions		= MaybeUseTranspositions
maybeUseTranspositions,
		getStandardOpeningOptions :: SearchOptions -> StandardOpeningOptions
getStandardOpeningOptions		= StandardOpeningOptions
standardOpeningOptions,
		getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour		= SearchDepthByLogicalColour
searchDepthByLogicalColour
	} = ((SortOnStandardOpeningMoveFrequency,
  Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies),
 (SortOnStandardOpeningMoveFrequency,
  SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
  StandardOpeningOptions, SearchDepthByLogicalColour))
-> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf (
		(
			SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency, Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm, Maybe NPlies
maybeMinimumHammingDistance, Maybe NPlies
maybeRetireKillerMovesAfter
		), (
			SortOnStandardOpeningMoveFrequency
trapRepeatedPositions, SortOnStandardOpeningMoveFrequency
usePondering, MaybeUseTranspositions
maybeUseTranspositions, StandardOpeningOptions
standardOpeningOptions, SearchDepthByLogicalColour
searchDepthByLogicalColour
		)
	 )

instance Show SearchOptions where
	showsPrec :: NPlies -> SearchOptions -> ShowS
showsPrec NPlies
_ MkSearchOptions {
		getSortOnStandardOpeningMoveFrequency :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	= SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency,
		getMaybeCaptureMoveSortAlgorithm :: SearchOptions -> Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	= Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm,
		getMaybeMinimumHammingDistance :: SearchOptions -> Maybe NPlies
getMaybeMinimumHammingDistance		= Maybe NPlies
maybeMinimumHammingDistance,
		getMaybeRetireKillerMovesAfter :: SearchOptions -> Maybe NPlies
getMaybeRetireKillerMovesAfter		= Maybe NPlies
maybeRetireKillerMovesAfter,
		getTrapRepeatedPositions :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		= SortOnStandardOpeningMoveFrequency
trapRepeatedPositions,
		getUsePondering :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getUsePondering				= SortOnStandardOpeningMoveFrequency
usePondering,
		getMaybeUseTranspositions :: SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions		= MaybeUseTranspositions
maybeUseTranspositions,
		getStandardOpeningOptions :: SearchOptions -> StandardOpeningOptions
getStandardOpeningOptions		= StandardOpeningOptions
standardOpeningOptions,
		getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour		= SearchDepthByLogicalColour
searchDepthByLogicalColour
	} = [(String, ShowS)] -> ShowS
Text.ShowList.showsAssociationList' ([(String, ShowS)] -> ShowS)
-> ([(String, ShowS)] -> [(String, ShowS)])
-> [(String, ShowS)]
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(String, ShowS)] -> [(String, ShowS)])
-> (CaptureMoveSortAlgorithm
    -> [(String, ShowS)] -> [(String, ShowS)])
-> Maybe CaptureMoveSortAlgorithm
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [(String, ShowS)] -> [(String, ShowS)]
forall a. a -> a
id (
		(:) ((String, ShowS) -> [(String, ShowS)] -> [(String, ShowS)])
-> (CaptureMoveSortAlgorithm -> (String, ShowS))
-> CaptureMoveSortAlgorithm
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) String
Attribute.CaptureMoveSortAlgorithm.tag (ShowS -> (String, ShowS))
-> (CaptureMoveSortAlgorithm -> ShowS)
-> CaptureMoveSortAlgorithm
-> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CaptureMoveSortAlgorithm -> ShowS
forall a. Show a => a -> ShowS
shows
	 ) Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm ([(String, ShowS)] -> [(String, ShowS)])
-> ([(String, ShowS)] -> [(String, ShowS)])
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(String, ShowS)] -> [(String, ShowS)])
-> (NPlies -> [(String, ShowS)] -> [(String, ShowS)])
-> Maybe NPlies
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [(String, ShowS)] -> [(String, ShowS)]
forall a. a -> a
id (
		(:) ((String, ShowS) -> [(String, ShowS)] -> [(String, ShowS)])
-> (NPlies -> (String, ShowS))
-> NPlies
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) String
minimumHammingDistanceTag (ShowS -> (String, ShowS))
-> (NPlies -> ShowS) -> NPlies -> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPlies -> ShowS
forall a. Show a => a -> ShowS
shows
	 ) Maybe NPlies
maybeMinimumHammingDistance ([(String, ShowS)] -> [(String, ShowS)])
-> ([(String, ShowS)] -> [(String, ShowS)])
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(String, ShowS)] -> [(String, ShowS)])
-> (NPlies -> [(String, ShowS)] -> [(String, ShowS)])
-> Maybe NPlies
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [(String, ShowS)] -> [(String, ShowS)]
forall a. a -> a
id (
		(:) ((String, ShowS) -> [(String, ShowS)] -> [(String, ShowS)])
-> (NPlies -> (String, ShowS))
-> NPlies
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) String
retireKillerMovesAfterTag (ShowS -> (String, ShowS))
-> (NPlies -> ShowS) -> NPlies -> (String, ShowS)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NPlies -> ShowS
forall a. Show a => a -> ShowS
shows
	 ) Maybe NPlies
maybeRetireKillerMovesAfter ([(String, ShowS)] -> ShowS) -> [(String, ShowS)] -> ShowS
forall a b. (a -> b) -> a -> b
$ ([(String, ShowS)] -> [(String, ShowS)])
-> ((NPlies, NPlies) -> [(String, ShowS)] -> [(String, ShowS)])
-> MaybeUseTranspositions
-> [(String, ShowS)]
-> [(String, ShowS)]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [(String, ShowS)] -> [(String, ShowS)]
forall a. a -> a
id (
		\(NPlies
retireTranspositionsAfter, NPlies
minimumTranspositionSearchDepth)	-> [(String, ShowS)] -> [(String, ShowS)] -> [(String, ShowS)]
forall a. [a] -> [a] -> [a]
(++) [
			(
				String
sortOnStandardOpeningMoveFrequencyTag,
				SortOnStandardOpeningMoveFrequency -> ShowS
forall a. Show a => a -> ShowS
shows SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency
			), (
				String
retireTranspositionsAfterTag,
				NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
retireTranspositionsAfter
			), (
				String
minimumTranspositionSearchDepthTag,
				NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
minimumTranspositionSearchDepth
			)
		]
	 ) MaybeUseTranspositions
maybeUseTranspositions [
		(
			String
trapRepeatedPositionsTag,
			SortOnStandardOpeningMoveFrequency -> ShowS
forall a. Show a => a -> ShowS
shows SortOnStandardOpeningMoveFrequency
trapRepeatedPositions
		), (
			String
usePonderingTag,
			SortOnStandardOpeningMoveFrequency -> ShowS
forall a. Show a => a -> ShowS
shows SortOnStandardOpeningMoveFrequency
usePondering
		), (
			String
Input.StandardOpeningOptions.tag,
			StandardOpeningOptions -> ShowS
forall a. Show a => a -> ShowS
shows StandardOpeningOptions
standardOpeningOptions
		), (
			String
searchDepthByLogicalColourTag,
			[(String, ShowS)] -> ShowS
Text.ShowList.showsAssociationList' ([(String, ShowS)] -> ShowS)
-> ([(LogicalColour, NPlies)] -> [(String, ShowS)])
-> [(LogicalColour, NPlies)]
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((LogicalColour, NPlies) -> (String, ShowS))
-> [(LogicalColour, NPlies)] -> [(String, ShowS)]
forall a b. (a -> b) -> [a] -> [b]
map (LogicalColour -> String
forall a. Show a => a -> String
show (LogicalColour -> String)
-> (NPlies -> ShowS) -> (LogicalColour, NPlies) -> (String, ShowS)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** NPlies -> ShowS
forall a. Show a => a -> ShowS
shows) ([(LogicalColour, NPlies)] -> ShowS)
-> [(LogicalColour, NPlies)] -> ShowS
forall a b. (a -> b) -> a -> b
$ SearchDepthByLogicalColour -> [(LogicalColour, NPlies)]
forall k a. Map k a -> [(k, a)]
Map.toList SearchDepthByLogicalColour
searchDepthByLogicalColour
		)
	 ]

instance Data.Default.Default SearchOptions where
	def :: SearchOptions
def = MkSearchOptions :: SortOnStandardOpeningMoveFrequency
-> Maybe CaptureMoveSortAlgorithm
-> Maybe NPlies
-> Maybe NPlies
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
-> MaybeUseTranspositions
-> StandardOpeningOptions
-> SearchDepthByLogicalColour
-> SearchOptions
MkSearchOptions {
		getSortOnStandardOpeningMoveFrequency :: SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	= SortOnStandardOpeningMoveFrequency
False,	-- CAVEAT: this can only be True if a PGN database has been defined; which is currently unknown.
		getMaybeCaptureMoveSortAlgorithm :: Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	= Maybe CaptureMoveSortAlgorithm
forall a. Maybe a
Nothing,
		getMaybeMinimumHammingDistance :: Maybe NPlies
getMaybeMinimumHammingDistance		= Maybe NPlies
forall a. Maybe a
Nothing,
		getMaybeRetireKillerMovesAfter :: Maybe NPlies
getMaybeRetireKillerMovesAfter		= Maybe NPlies
forall a. Maybe a
Nothing,
		getTrapRepeatedPositions :: SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		= SortOnStandardOpeningMoveFrequency
True,
		getUsePondering :: SortOnStandardOpeningMoveFrequency
getUsePondering				= SortOnStandardOpeningMoveFrequency
False,
		getMaybeUseTranspositions :: MaybeUseTranspositions
getMaybeUseTranspositions		= MaybeUseTranspositions
forall a. Maybe a
Nothing,
		getStandardOpeningOptions :: StandardOpeningOptions
getStandardOpeningOptions		= StandardOpeningOptions
forall a. Default a => a
Data.Default.def,
		getSearchDepthByLogicalColour :: SearchDepthByLogicalColour
getSearchDepthByLogicalColour		= SearchDepthByLogicalColour
forall a. Empty a => a
Property.Empty.empty	-- Manual play.
	}

instance HXT.XmlPickler SearchOptions where
	xpickle :: PU SearchOptions
xpickle	= SearchOptions -> PU SearchOptions -> PU SearchOptions
forall a. Eq a => a -> PU a -> PU a
HXT.xpDefault SearchOptions
forall a. Default a => a
Data.Default.def (PU SearchOptions -> PU SearchOptions)
-> (PU
      (SortOnStandardOpeningMoveFrequency,
       Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
       SortOnStandardOpeningMoveFrequency,
       SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
       StandardOpeningOptions, SearchDepthByLogicalColour)
    -> PU SearchOptions)
-> PU
     (SortOnStandardOpeningMoveFrequency,
      Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
      SortOnStandardOpeningMoveFrequency,
      SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
      StandardOpeningOptions, SearchDepthByLogicalColour)
-> PU SearchOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PU SearchOptions -> PU SearchOptions
forall a. String -> PU a -> PU a
HXT.xpElem String
tag (PU SearchOptions -> PU SearchOptions)
-> (PU
      (SortOnStandardOpeningMoveFrequency,
       Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
       SortOnStandardOpeningMoveFrequency,
       SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
       StandardOpeningOptions, SearchDepthByLogicalColour)
    -> PU SearchOptions)
-> PU
     (SortOnStandardOpeningMoveFrequency,
      Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
      SortOnStandardOpeningMoveFrequency,
      SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
      StandardOpeningOptions, SearchDepthByLogicalColour)
-> PU SearchOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((SortOnStandardOpeningMoveFrequency,
  Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
  SortOnStandardOpeningMoveFrequency,
  SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
  StandardOpeningOptions, SearchDepthByLogicalColour)
 -> SearchOptions,
 SearchOptions
 -> (SortOnStandardOpeningMoveFrequency,
     Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
     SortOnStandardOpeningMoveFrequency,
     SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
     StandardOpeningOptions, SearchDepthByLogicalColour))
-> PU
     (SortOnStandardOpeningMoveFrequency,
      Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
      SortOnStandardOpeningMoveFrequency,
      SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
      StandardOpeningOptions, SearchDepthByLogicalColour)
-> PU SearchOptions
forall a b. (a -> b, b -> a) -> PU a -> PU b
HXT.xpWrap (
		\(SortOnStandardOpeningMoveFrequency
a, Maybe CaptureMoveSortAlgorithm
b, Maybe NPlies
c, Maybe NPlies
d, SortOnStandardOpeningMoveFrequency
e, SortOnStandardOpeningMoveFrequency
f, MaybeUseTranspositions
g, StandardOpeningOptions
h, SearchDepthByLogicalColour
i) -> SortOnStandardOpeningMoveFrequency
-> Maybe CaptureMoveSortAlgorithm
-> Maybe NPlies
-> Maybe NPlies
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
-> MaybeUseTranspositions
-> StandardOpeningOptions
-> SearchDepthByLogicalColour
-> SearchOptions
mkSearchOptions SortOnStandardOpeningMoveFrequency
a Maybe CaptureMoveSortAlgorithm
b Maybe NPlies
c Maybe NPlies
d SortOnStandardOpeningMoveFrequency
e SortOnStandardOpeningMoveFrequency
f MaybeUseTranspositions
g StandardOpeningOptions
h SearchDepthByLogicalColour
i,	-- Construct.
		\MkSearchOptions {
			getSortOnStandardOpeningMoveFrequency :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	= SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency,
			getMaybeCaptureMoveSortAlgorithm :: SearchOptions -> Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	= Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm,
			getMaybeMinimumHammingDistance :: SearchOptions -> Maybe NPlies
getMaybeMinimumHammingDistance		= Maybe NPlies
maybeMinimumHammingDistance,
			getMaybeRetireKillerMovesAfter :: SearchOptions -> Maybe NPlies
getMaybeRetireKillerMovesAfter		= Maybe NPlies
maybeRetireKillerMovesAfter,
			getTrapRepeatedPositions :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		= SortOnStandardOpeningMoveFrequency
trapRepeatedPositions,
			getUsePondering :: SearchOptions -> SortOnStandardOpeningMoveFrequency
getUsePondering				= SortOnStandardOpeningMoveFrequency
usePondering,
			getMaybeUseTranspositions :: SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions		= MaybeUseTranspositions
maybeUseTranspositions,
			getStandardOpeningOptions :: SearchOptions -> StandardOpeningOptions
getStandardOpeningOptions		= StandardOpeningOptions
standardOpeningOptions,
			getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour		= SearchDepthByLogicalColour
searchDepthByLogicalColour
		} -> (
			SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency,
			Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm,
			Maybe NPlies
maybeMinimumHammingDistance,
			Maybe NPlies
maybeRetireKillerMovesAfter,
			SortOnStandardOpeningMoveFrequency
trapRepeatedPositions,
			SortOnStandardOpeningMoveFrequency
usePondering,
			MaybeUseTranspositions
maybeUseTranspositions,
			StandardOpeningOptions
standardOpeningOptions,
			SearchDepthByLogicalColour
searchDepthByLogicalColour
		) -- Deconstruct.
	 ) (PU
   (SortOnStandardOpeningMoveFrequency,
    Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
    SortOnStandardOpeningMoveFrequency,
    SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
    StandardOpeningOptions, SearchDepthByLogicalColour)
 -> PU SearchOptions)
-> PU
     (SortOnStandardOpeningMoveFrequency,
      Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
      SortOnStandardOpeningMoveFrequency,
      SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
      StandardOpeningOptions, SearchDepthByLogicalColour)
-> PU SearchOptions
forall a b. (a -> b) -> a -> b
$ PU SortOnStandardOpeningMoveFrequency
-> PU (Maybe CaptureMoveSortAlgorithm)
-> PU (Maybe NPlies)
-> PU (Maybe NPlies)
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
-> PU MaybeUseTranspositions
-> PU StandardOpeningOptions
-> PU SearchDepthByLogicalColour
-> PU
     (SortOnStandardOpeningMoveFrequency,
      Maybe CaptureMoveSortAlgorithm, Maybe NPlies, Maybe NPlies,
      SortOnStandardOpeningMoveFrequency,
      SortOnStandardOpeningMoveFrequency, MaybeUseTranspositions,
      StandardOpeningOptions, SearchDepthByLogicalColour)
forall a b c d e f g h i.
PU a
-> PU b
-> PU c
-> PU d
-> PU e
-> PU f
-> PU g
-> PU h
-> PU i
-> PU (a, b, c, d, e, f, g, h, i)
HXT.xp9Tuple (
		SearchOptions -> SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency SearchOptions
def SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. String -> PU a -> PU a
HXT.xpAttr String
sortOnStandardOpeningMoveFrequencyTag PU SortOnStandardOpeningMoveFrequency
forall a. XmlPickler a => PU a
HXT.xpickle
	 ) (
		PU CaptureMoveSortAlgorithm -> PU (Maybe CaptureMoveSortAlgorithm)
forall a. PU a -> PU (Maybe a)
HXT.xpOption PU CaptureMoveSortAlgorithm
forall a. XmlPickler a => PU a
HXT.xpickle {-CaptureMoveSortAlgorithm-}
	 ) (
		String -> PU NPlies -> PU (Maybe NPlies)
forall a. String -> PU a -> PU (Maybe a)
HXT.xpAttrImplied String
minimumHammingDistanceTag PU NPlies
HXT.xpInt
	 ) (
		String -> PU NPlies -> PU (Maybe NPlies)
forall a. String -> PU a -> PU (Maybe a)
HXT.xpAttrImplied String
retireKillerMovesAfterTag PU NPlies
forall a. XmlPickler a => PU a
HXT.xpickle {-NMoves-}
	 ) (
		SearchOptions -> SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions SearchOptions
def SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. String -> PU a -> PU a
HXT.xpAttr String
trapRepeatedPositionsTag PU SortOnStandardOpeningMoveFrequency
forall a. XmlPickler a => PU a
HXT.xpickle {-Bool-}
	 ) (
		SearchOptions -> SortOnStandardOpeningMoveFrequency
getUsePondering SearchOptions
def SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String
-> PU SortOnStandardOpeningMoveFrequency
-> PU SortOnStandardOpeningMoveFrequency
forall a. String -> PU a -> PU a
HXT.xpAttr String
usePonderingTag PU SortOnStandardOpeningMoveFrequency
forall a. XmlPickler a => PU a
HXT.xpickle {-Bool-}
	 ) (
		PU (NPlies, NPlies) -> PU MaybeUseTranspositions
forall a. PU a -> PU (Maybe a)
HXT.xpOption (PU (NPlies, NPlies) -> PU MaybeUseTranspositions)
-> (PU (NPlies, NPlies) -> PU (NPlies, NPlies))
-> PU (NPlies, NPlies)
-> PU MaybeUseTranspositions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PU (NPlies, NPlies) -> PU (NPlies, NPlies)
forall a. String -> PU a -> PU a
HXT.xpElem String
"transpositions" (PU (NPlies, NPlies) -> PU MaybeUseTranspositions)
-> PU (NPlies, NPlies) -> PU MaybeUseTranspositions
forall a b. (a -> b) -> a -> b
$ String -> PU NPlies -> PU NPlies
forall a. String -> PU a -> PU a
HXT.xpAttr String
retireTranspositionsAfterTag PU NPlies
forall a. XmlPickler a => PU a
HXT.xpickle {-NMoves-} PU NPlies -> PU NPlies -> PU (NPlies, NPlies)
forall a b. PU a -> PU b -> PU (a, b)
`HXT.xpPair` String -> PU NPlies -> PU NPlies
forall a. String -> PU a -> PU a
HXT.xpAttr String
minimumTranspositionSearchDepthTag PU NPlies
forall a. XmlPickler a => PU a
HXT.xpickle {-NPlies-}
	 ) PU StandardOpeningOptions
forall a. XmlPickler a => PU a
HXT.xpickle {-standardOpeningOptions-} (
		String
-> PU SearchDepthByLogicalColour -> PU SearchDepthByLogicalColour
forall a. String -> PU a -> PU a
HXT.xpElem String
searchDepthByLogicalColourTag (PU SearchDepthByLogicalColour -> PU SearchDepthByLogicalColour)
-> (PU (LogicalColour, NPlies) -> PU SearchDepthByLogicalColour)
-> PU (LogicalColour, NPlies)
-> PU SearchDepthByLogicalColour
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(LogicalColour, NPlies)] -> SearchDepthByLogicalColour,
 SearchDepthByLogicalColour -> [(LogicalColour, NPlies)])
-> PU [(LogicalColour, NPlies)] -> PU SearchDepthByLogicalColour
forall a b. (a -> b, b -> a) -> PU a -> PU b
HXT.xpWrap (
			[(LogicalColour, NPlies)] -> SearchDepthByLogicalColour
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(LogicalColour, NPlies)] -> SearchDepthByLogicalColour)
-> ([(LogicalColour, NPlies)] -> [(LogicalColour, NPlies)])
-> [(LogicalColour, NPlies)]
-> SearchDepthByLogicalColour
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (
				\[(LogicalColour, NPlies)]
l	-> let
					duplicateLogicalColours :: [LogicalColour]
duplicateLogicalColours	= [LogicalColour] -> [LogicalColour]
forall (foldable :: * -> *) a.
(Foldable foldable, Ord a) =>
foldable a -> [a]
BishBosh.Data.Foldable.findDuplicates ([LogicalColour] -> [LogicalColour])
-> [LogicalColour] -> [LogicalColour]
forall a b. (a -> b) -> a -> b
$ ((LogicalColour, NPlies) -> LogicalColour)
-> [(LogicalColour, NPlies)] -> [LogicalColour]
forall a b. (a -> b) -> [a] -> [b]
map (LogicalColour, NPlies) -> LogicalColour
forall a b. (a, b) -> a
fst {-logicalColour-} [(LogicalColour, NPlies)]
l
				in if [LogicalColour] -> SortOnStandardOpeningMoveFrequency
forall (t :: * -> *) a.
Foldable t =>
t a -> SortOnStandardOpeningMoveFrequency
null [LogicalColour]
duplicateLogicalColours
					then [(LogicalColour, NPlies)]
l
					else Exception -> [(LogicalColour, NPlies)]
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> [(LogicalColour, NPlies)])
-> (String -> Exception) -> String -> [(LogicalColour, NPlies)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkDuplicateData (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.SearchOptions.xpickle:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
Attribute.LogicalColour.tag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"s must be distinct; " (String -> [(LogicalColour, NPlies)])
-> String -> [(LogicalColour, NPlies)]
forall a b. (a -> b) -> a -> b
$ [LogicalColour] -> ShowS
forall a. Show a => a -> ShowS
shows [LogicalColour]
duplicateLogicalColours String
"."
			),	-- Construct from a List.
			SearchDepthByLogicalColour -> [(LogicalColour, NPlies)]
forall k a. Map k a -> [(k, a)]
Map.toList		-- Deconstruct to an association-list.
		) (PU [(LogicalColour, NPlies)] -> PU SearchDepthByLogicalColour)
-> (PU (LogicalColour, NPlies) -> PU [(LogicalColour, NPlies)])
-> PU (LogicalColour, NPlies)
-> PU SearchDepthByLogicalColour
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PU (LogicalColour, NPlies) -> PU [(LogicalColour, NPlies)]
forall a. PU a -> PU [a]
HXT.xpList {-potentially null-} (PU (LogicalColour, NPlies) -> PU [(LogicalColour, NPlies)])
-> (PU (LogicalColour, NPlies) -> PU (LogicalColour, NPlies))
-> PU (LogicalColour, NPlies)
-> PU [(LogicalColour, NPlies)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PU (LogicalColour, NPlies) -> PU (LogicalColour, NPlies)
forall a. String -> PU a -> PU a
HXT.xpElem (
			String -> ShowS
showString String
"by" ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ ShowS
Text.Case.toUpperInitial String
Attribute.LogicalColour.tag
		) (PU (LogicalColour, NPlies) -> PU SearchDepthByLogicalColour)
-> PU (LogicalColour, NPlies) -> PU SearchDepthByLogicalColour
forall a b. (a -> b) -> a -> b
$ PU LogicalColour
forall a. XmlPickler a => PU a
HXT.xpickle {-LogicalColour-} PU LogicalColour -> PU NPlies -> PU (LogicalColour, NPlies)
forall a b. PU a -> PU b -> PU (a, b)
`HXT.xpPair` String -> PU NPlies -> PU NPlies
forall a. String -> PU a -> PU a
HXT.xpAttr String
searchDepthTag PU NPlies
forall a. XmlPickler a => PU a
HXT.xpickle {-NPlies-}
	 ) where
		def :: SearchOptions
def	= SearchOptions
forall a. Default a => a
Data.Default.def

-- | Smart constructor.
mkSearchOptions
	:: SortOnStandardOpeningMoveFrequency
	-> Maybe Attribute.CaptureMoveSortAlgorithm.CaptureMoveSortAlgorithm
	-> Maybe HammingDistance	-- ^ The optional lower bound on the Hamming-distance between the random numbers used to compose Zobrist hashes from /position/s.
	-> MaybeRetireAfterNMoves	-- ^ The number of full moves back from the current position, after which to retire killer-moves.
	-> TrapRepeatedPositions
	-> UsePondering
	-> MaybeUseTranspositions	-- ^ The number of full moves after which to retire transpositions, & the search-depth beneath which transpositions aren't recorded.
	-> Input.StandardOpeningOptions.StandardOpeningOptions
	-> SearchDepthByLogicalColour
	-> SearchOptions
mkSearchOptions :: SortOnStandardOpeningMoveFrequency
-> Maybe CaptureMoveSortAlgorithm
-> Maybe NPlies
-> Maybe NPlies
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
-> MaybeUseTranspositions
-> StandardOpeningOptions
-> SearchDepthByLogicalColour
-> SearchOptions
mkSearchOptions SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm Maybe NPlies
maybeMinimumHammingDistance Maybe NPlies
maybeRetireKillerMovesAfter SortOnStandardOpeningMoveFrequency
trapRepeatedPositions SortOnStandardOpeningMoveFrequency
usePondering MaybeUseTranspositions
maybeUseTranspositions StandardOpeningOptions
standardOpeningOptions SearchDepthByLogicalColour
searchDepthByLogicalColour
	| Just NPlies
minimumHammingDistance		<- Maybe NPlies
maybeMinimumHammingDistance
	, NPlies
minimumHammingDistance NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
1	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
minimumHammingDistanceTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
minimumHammingDistance String
" must exceed zero."
	| Just NPlies
retireKillerMovesAfter		<- Maybe NPlies
maybeRetireKillerMovesAfter
	, NPlies
retireKillerMovesAfter NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
0	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
retireKillerMovesAfterTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
retireKillerMovesAfter String
" can't be negative."
	| let nAutomatedPlayers :: NPlies
nAutomatedPlayers	= SearchDepthByLogicalColour -> NPlies
forall (t :: * -> *) a. Foldable t => t a -> NPlies
Data.Foldable.length SearchDepthByLogicalColour
searchDepthByLogicalColour
	, SortOnStandardOpeningMoveFrequency
usePondering SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
&& NPlies
nAutomatedPlayers NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Eq a => a -> a -> SortOnStandardOpeningMoveFrequency
/= NPlies
1
	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkIncompatibleData (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.SearchOptions.mkSearchOptions:\tpondering is pointless unless there's an automated player who can use the unused CPU-time during a manual player's move, but there're " (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
nAutomatedPlayers String
" automated players."
	| Just (NPlies
retireTranspositionsAfter, NPlies
_)	<- MaybeUseTranspositions
maybeUseTranspositions
	, NPlies
retireTranspositionsAfter NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
0	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
retireTranspositionsAfterTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
retireTranspositionsAfter String
" can't be negative."
	| Just (NPlies
_, NPlies
minimumTranspositionSearchDepth)	<- MaybeUseTranspositions
maybeUseTranspositions
	, NPlies
minimumTranspositionSearchDepth NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
1	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
minimumTranspositionSearchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
minimumTranspositionSearchDepth String
" must exceed zero."
	| Just (NPlies
_, NPlies
minimumTranspositionSearchDepth)	<- MaybeUseTranspositions
maybeUseTranspositions
	, SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
not (SortOnStandardOpeningMoveFrequency
 -> SortOnStandardOpeningMoveFrequency)
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
forall a b. (a -> b) -> a -> b
$ SearchDepthByLogicalColour -> SortOnStandardOpeningMoveFrequency
forall (t :: * -> *) a.
Foldable t =>
t a -> SortOnStandardOpeningMoveFrequency
Data.Foldable.null SearchDepthByLogicalColour
searchDepthByLogicalColour
	, (NPlies -> SortOnStandardOpeningMoveFrequency)
-> SearchDepthByLogicalColour -> SortOnStandardOpeningMoveFrequency
forall (t :: * -> *) a.
Foldable t =>
(a -> SortOnStandardOpeningMoveFrequency)
-> t a -> SortOnStandardOpeningMoveFrequency
Data.Foldable.all (
		NPlies
minimumTranspositionSearchDepth NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
>
	) SearchDepthByLogicalColour
searchDepthByLogicalColour	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
minimumTranspositionSearchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
minimumTranspositionSearchDepth ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" exceeds " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
searchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [(LogicalColour, NPlies)] -> ShowS
forall a. Show a => a -> ShowS
shows (SearchDepthByLogicalColour -> [(LogicalColour, NPlies)]
forall k a. Map k a -> [(k, a)]
Map.toList SearchDepthByLogicalColour
searchDepthByLogicalColour) String
"."
	| (NPlies -> SortOnStandardOpeningMoveFrequency)
-> SearchDepthByLogicalColour -> SortOnStandardOpeningMoveFrequency
forall (t :: * -> *) a.
Foldable t =>
(a -> SortOnStandardOpeningMoveFrequency)
-> t a -> SortOnStandardOpeningMoveFrequency
Data.Foldable.any (
		NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
minimumSearchDepth
	) SearchDepthByLogicalColour
searchDepthByLogicalColour	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.mkSearchOptions:\t" (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
searchDepthTag String
" must be positive."
	| SortOnStandardOpeningMoveFrequency
otherwise	= MkSearchOptions :: SortOnStandardOpeningMoveFrequency
-> Maybe CaptureMoveSortAlgorithm
-> Maybe NPlies
-> Maybe NPlies
-> SortOnStandardOpeningMoveFrequency
-> SortOnStandardOpeningMoveFrequency
-> MaybeUseTranspositions
-> StandardOpeningOptions
-> SearchDepthByLogicalColour
-> SearchOptions
MkSearchOptions {
		getSortOnStandardOpeningMoveFrequency :: SortOnStandardOpeningMoveFrequency
getSortOnStandardOpeningMoveFrequency	= SortOnStandardOpeningMoveFrequency
sortOnStandardOpeningMoveFrequency,
		getMaybeCaptureMoveSortAlgorithm :: Maybe CaptureMoveSortAlgorithm
getMaybeCaptureMoveSortAlgorithm	= Maybe CaptureMoveSortAlgorithm
maybeCaptureMoveSortAlgorithm,
		getMaybeMinimumHammingDistance :: Maybe NPlies
getMaybeMinimumHammingDistance		= Maybe NPlies
maybeMinimumHammingDistance,
		getMaybeRetireKillerMovesAfter :: Maybe NPlies
getMaybeRetireKillerMovesAfter		= Maybe NPlies
maybeRetireKillerMovesAfter,
		getTrapRepeatedPositions :: SortOnStandardOpeningMoveFrequency
getTrapRepeatedPositions		= SortOnStandardOpeningMoveFrequency
trapRepeatedPositions,
		getUsePondering :: SortOnStandardOpeningMoveFrequency
getUsePondering				= SortOnStandardOpeningMoveFrequency
usePondering,
		getMaybeUseTranspositions :: MaybeUseTranspositions
getMaybeUseTranspositions		= MaybeUseTranspositions
maybeUseTranspositions,
		getStandardOpeningOptions :: StandardOpeningOptions
getStandardOpeningOptions		= StandardOpeningOptions
standardOpeningOptions,
		getSearchDepthByLogicalColour :: SearchDepthByLogicalColour
getSearchDepthByLogicalColour		= SearchDepthByLogicalColour
searchDepthByLogicalColour
	}

-- | Get either player's search-depth, using a default value when none are defined.
getSearchDepth :: SearchOptions -> Type.Count.NPlies
getSearchDepth :: SearchOptions -> NPlies
getSearchDepth MkSearchOptions { getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour = SearchDepthByLogicalColour
searchDepthByLogicalColour }	= NPlies -> Maybe NPlies -> NPlies
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe NPlies
defaultSearchDepth (Maybe NPlies -> NPlies)
-> ([NPlies] -> Maybe NPlies) -> [NPlies] -> NPlies
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NPlies] -> Maybe NPlies
forall a. [a] -> Maybe a
Data.Maybe.listToMaybe ([NPlies] -> NPlies) -> [NPlies] -> NPlies
forall a b. (a -> b) -> a -> b
$ SearchDepthByLogicalColour -> [NPlies]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Data.Foldable.toList SearchDepthByLogicalColour
searchDepthByLogicalColour	-- Manual players don't have a searchDepth, so use the opponent's settings.

-- | Self-documentation.
type RecordKillerMoves	= Bool

-- | Whether killer-moves are to be recorded.
recordKillerMoves :: SearchOptions -> RecordKillerMoves
recordKillerMoves :: SearchOptions -> SortOnStandardOpeningMoveFrequency
recordKillerMoves MkSearchOptions { getMaybeRetireKillerMovesAfter :: SearchOptions -> Maybe NPlies
getMaybeRetireKillerMovesAfter = Maybe NPlies
maybeRetireKillerMovesAfter }	= Maybe NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Maybe a -> SortOnStandardOpeningMoveFrequency
Data.Maybe.isJust Maybe NPlies
maybeRetireKillerMovesAfter

-- | When to retire transpositions.
maybeRetireTranspositionsAfter :: SearchOptions -> MaybeRetireAfterNMoves
maybeRetireTranspositionsAfter :: SearchOptions -> Maybe NPlies
maybeRetireTranspositionsAfter MkSearchOptions { getMaybeUseTranspositions :: SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions = MaybeUseTranspositions
maybeUseTranspositions }	= ((NPlies, NPlies) -> NPlies)
-> MaybeUseTranspositions -> Maybe NPlies
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NPlies, NPlies) -> NPlies
forall a b. (a, b) -> a
fst {-NMoves-} MaybeUseTranspositions
maybeUseTranspositions

-- | The search-depth beneath which transpositions aren't recorded.
maybeMinimumTranspositionSearchDepth :: SearchOptions -> Maybe Type.Count.NPlies
maybeMinimumTranspositionSearchDepth :: SearchOptions -> Maybe NPlies
maybeMinimumTranspositionSearchDepth MkSearchOptions { getMaybeUseTranspositions :: SearchOptions -> MaybeUseTranspositions
getMaybeUseTranspositions = MaybeUseTranspositions
maybeUseTranspositions }	= ((NPlies, NPlies) -> NPlies)
-> MaybeUseTranspositions -> Maybe NPlies
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NPlies, NPlies) -> NPlies
forall a b. (a, b) -> b
snd {-NPlies-} MaybeUseTranspositions
maybeUseTranspositions

-- | The type of a function used to transform 'SearchOptions'.
type Transformation	= SearchOptions -> SearchOptions

-- | Mutator.
setSearchDepth :: Type.Count.NPlies -> Transformation
setSearchDepth :: NPlies -> Transformation
setSearchDepth NPlies
searchDepth searchOptions :: SearchOptions
searchOptions@MkSearchOptions { getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour = SearchDepthByLogicalColour
searchDepthByLogicalColour }
	| NPlies
searchDepth NPlies -> NPlies -> SortOnStandardOpeningMoveFrequency
forall a. Ord a => a -> a -> SortOnStandardOpeningMoveFrequency
< NPlies
minimumSearchDepth	= Exception -> SearchOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> SearchOptions)
-> (String -> Exception) -> String -> SearchOptions
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.Input.SearchOptions.setSearchDepth:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
searchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> SearchOptions) -> String -> SearchOptions
forall a b. (a -> b) -> a -> b
$ NPlies -> ShowS
forall a. Show a => a -> ShowS
shows NPlies
searchDepth String
" must be positive."
	| SortOnStandardOpeningMoveFrequency
otherwise	= SearchOptions
searchOptions { getSearchDepthByLogicalColour :: SearchDepthByLogicalColour
getSearchDepthByLogicalColour = (NPlies -> NPlies)
-> SearchDepthByLogicalColour -> SearchDepthByLogicalColour
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (NPlies -> NPlies -> NPlies
forall a b. a -> b -> a
const NPlies
searchDepth) SearchDepthByLogicalColour
searchDepthByLogicalColour }

-- | Swap the /logical colour/ associated with any /searchDepth/ currently assigned.
swapSearchDepth :: Transformation
swapSearchDepth :: Transformation
swapSearchDepth searchOptions :: SearchOptions
searchOptions@MkSearchOptions {
	getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour	= SearchDepthByLogicalColour
searchDepthByLogicalColour
} = SearchOptions
searchOptions {
	getSearchDepthByLogicalColour :: SearchDepthByLogicalColour
getSearchDepthByLogicalColour	= (LogicalColour -> LogicalColour)
-> SearchDepthByLogicalColour -> SearchDepthByLogicalColour
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite SearchDepthByLogicalColour
searchDepthByLogicalColour
}

-- | Extract those /logical colour/s for which a search-depth has been defined, which implies that the corresponding player is automated.
identifyAutomatedPlayers :: SearchOptions -> [Attribute.LogicalColour.LogicalColour]
identifyAutomatedPlayers :: SearchOptions -> [LogicalColour]
identifyAutomatedPlayers MkSearchOptions {
	getSearchDepthByLogicalColour :: SearchOptions -> SearchDepthByLogicalColour
getSearchDepthByLogicalColour	= SearchDepthByLogicalColour
searchDepthByLogicalColour
} = SearchDepthByLogicalColour -> [LogicalColour]
forall k a. Map k a -> [k]
Map.keys SearchDepthByLogicalColour
searchDepthByLogicalColour

-- | Self-documentation.
type Reader	= Control.Monad.Reader.Reader SearchOptions