module BishBosh.Search.Search(
Result (
getSearchState,
getQuantifiedGames,
getNMovesEvaluated
),
showsSeparator,
search,
calculateBranchingFactor
) where
import Control.Arrow((&&&))
import qualified BishBosh.Component.Move as Component.Move
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Evaluation.PositionHashQuantifiedGameTree as Evaluation.PositionHashQuantifiedGameTree
import qualified BishBosh.Evaluation.QuantifiedGame as Evaluation.QuantifiedGame
import qualified BishBosh.Input.SearchOptions as Input.SearchOptions
import qualified BishBosh.Model.Game as Model.Game
import qualified BishBosh.Notation.MoveNotation as Notation.MoveNotation
import qualified BishBosh.Search.AlphaBeta as Search.AlphaBeta
import qualified BishBosh.Search.SearchState as Search.SearchState
import qualified BishBosh.State.TurnsByLogicalColour as State.TurnsByLogicalColour
import qualified BishBosh.Text.ShowList as Text.ShowList
import qualified Control.DeepSeq
import qualified Control.Exception
import qualified Control.Monad.Reader
import qualified Data.Maybe
data Result x y positionHash criterionValue weightedMean = MkResult {
Result x y positionHash criterionValue weightedMean
-> SearchState x y positionHash criterionValue weightedMean
getSearchState :: Search.SearchState.SearchState x y positionHash criterionValue weightedMean,
Result x y positionHash criterionValue weightedMean
-> [QuantifiedGame x y criterionValue weightedMean]
getQuantifiedGames :: [Evaluation.QuantifiedGame.QuantifiedGame x y criterionValue weightedMean],
Result x y positionHash criterionValue weightedMean -> NMoves
getNMovesEvaluated :: Component.Move.NMoves
}
instance Control.DeepSeq.NFData weightedMean => Control.DeepSeq.NFData (Result x y positionHash criterionValue weightedMean) where
rnf :: Result x y positionHash criterionValue weightedMean -> ()
rnf MkResult { getQuantifiedGames :: forall x y positionHash criterionValue weightedMean.
Result x y positionHash criterionValue weightedMean
-> [QuantifiedGame x y criterionValue weightedMean]
getQuantifiedGames = [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames } = [QuantifiedGame x y criterionValue weightedMean] -> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames
showsSeparator :: ShowS
showsSeparator :: ShowS
showsSeparator = String -> ShowS
showString String
" -> "
instance (Enum x, Enum y, Real criterionValue, Real weightedMean) => Notation.MoveNotation.ShowNotationFloat (Result x y positionHash criterionValue weightedMean) where
showsNotationFloat :: MoveNotation
-> (Double -> ShowS)
-> Result x y positionHash criterionValue weightedMean
-> ShowS
showsNotationFloat MoveNotation
moveNotation Double -> ShowS
showsDouble result :: Result x y positionHash criterionValue weightedMean
result@MkResult {
getQuantifiedGames :: forall x y positionHash criterionValue weightedMean.
Result x y positionHash criterionValue weightedMean
-> [QuantifiedGame x y criterionValue weightedMean]
getQuantifiedGames = [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames,
getNMovesEvaluated :: forall x y positionHash criterionValue weightedMean.
Result x y positionHash criterionValue weightedMean -> NMoves
getNMovesEvaluated = NMoves
nMovesEvaluated
} = ShowS
-> (QuantifiedGame x y criterionValue weightedMean -> ShowS)
-> [QuantifiedGame x y criterionValue weightedMean]
-> ShowS
forall a. ShowS -> (a -> ShowS) -> [a] -> ShowS
Text.ShowList.showsFormattedList ShowS
showsSeparator (
MoveNotation
-> (Double -> ShowS)
-> QuantifiedGame x y criterionValue weightedMean
-> ShowS
forall a.
ShowNotationFloat a =>
MoveNotation -> (Double -> ShowS) -> a -> ShowS
Notation.MoveNotation.showsNotationFloat MoveNotation
moveNotation Double -> ShowS
showsDouble
) [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"; selected after analysing " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NMoves -> ShowS
forall a. Show a => a -> ShowS
shows NMoves
nMovesEvaluated ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" moves (branching-factor" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
showsDouble (
Result x y positionHash criterionValue weightedMean -> Double
forall branchingFactor x y positionHash criterionValue
weightedMean.
Floating branchingFactor =>
Result x y positionHash criterionValue weightedMean
-> branchingFactor
calculateBranchingFactor Result x y positionHash criterionValue weightedMean
result
) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
')'
search :: (
Enum x,
Enum y,
Eq criterionValue,
Num weightedMean,
Ord weightedMean,
Ord positionHash,
Ord x,
Ord y
)
=> Input.SearchOptions.SearchDepth
-> Search.SearchState.SearchState x y positionHash criterionValue weightedMean
-> Input.SearchOptions.Reader (Result x y positionHash criterionValue weightedMean)
search :: NMoves
-> SearchState x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean)
search NMoves
0 SearchState x y positionHash criterionValue weightedMean
_ = Exception
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a e. Exception e => e -> a
Control.Exception.throw (Exception
-> Reader (Result x y positionHash criterionValue weightedMean))
-> (String -> Exception)
-> String
-> Reader (Result x y positionHash criterionValue weightedMean)
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.Search.Search.search:\t" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
forall a. Show a => a -> ShowS
shows String
Input.SearchOptions.searchDepthTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" must be at least " (String
-> Reader (Result x y positionHash criterionValue weightedMean))
-> String
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ NMoves -> ShowS
forall a. Show a => a -> ShowS
shows NMoves
Input.SearchOptions.minimumSearchDepth String
"."
search NMoves
searchDepth SearchState x y positionHash criterionValue weightedMean
searchState
| Just GameTerminationReason
terminationReason <- Game x y -> Maybe GameTerminationReason
forall x y. Game x y -> Maybe GameTerminationReason
Model.Game.getMaybeTerminationReason Game x y
game = Exception
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a e. Exception e => e -> a
Control.Exception.throw (Exception
-> Reader (Result x y positionHash criterionValue weightedMean))
-> (String -> Exception)
-> String
-> Reader (Result x y positionHash criterionValue weightedMean)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkInvalidDatum (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Search.Search.search:\tthe game has already terminated; " (String
-> Reader (Result x y positionHash criterionValue weightedMean))
-> String
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ GameTerminationReason -> ShowS
forall a. Show a => a -> ShowS
shows GameTerminationReason
terminationReason String
"."
| Bool
otherwise = do
(MaybeRetireAfterNMoves
maybeRetireKillerMovesAfter, MaybeRetireAfterNMoves
maybeRetireTranspositionsAfter) <- (SearchOptions -> (MaybeRetireAfterNMoves, MaybeRetireAfterNMoves))
-> ReaderT
SearchOptions
Identity
(MaybeRetireAfterNMoves, MaybeRetireAfterNMoves)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Control.Monad.Reader.asks ((SearchOptions
-> (MaybeRetireAfterNMoves, MaybeRetireAfterNMoves))
-> ReaderT
SearchOptions
Identity
(MaybeRetireAfterNMoves, MaybeRetireAfterNMoves))
-> (SearchOptions
-> (MaybeRetireAfterNMoves, MaybeRetireAfterNMoves))
-> ReaderT
SearchOptions
Identity
(MaybeRetireAfterNMoves, MaybeRetireAfterNMoves)
forall a b. (a -> b) -> a -> b
$ SearchOptions -> MaybeRetireAfterNMoves
Input.SearchOptions.getMaybeRetireKillerMovesAfter (SearchOptions -> MaybeRetireAfterNMoves)
-> (SearchOptions -> MaybeRetireAfterNMoves)
-> SearchOptions
-> (MaybeRetireAfterNMoves, MaybeRetireAfterNMoves)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& SearchOptions -> MaybeRetireAfterNMoves
Input.SearchOptions.maybeRetireTranspositionsAfter
let nPlies :: NMoves
nPlies = TurnsByLogicalColour (Turn x y) -> NMoves
forall turn. TurnsByLogicalColour turn -> NMoves
State.TurnsByLogicalColour.getNPlies (TurnsByLogicalColour (Turn x y) -> NMoves)
-> TurnsByLogicalColour (Turn x y) -> NMoves
forall a b. (a -> b) -> a -> b
$ Game x y -> TurnsByLogicalColour (Turn x y)
forall x y. Game x y -> TurnsByLogicalColour x y
Model.Game.getTurnsByLogicalColour Game x y
game
Result x y positionHash criterionValue weightedMean
searchResult <- NMoves
-> SearchState x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean)
forall x y criterionValue weightedMean positionHash.
(Enum x, Enum y, Eq criterionValue, Num weightedMean,
Ord weightedMean, Ord positionHash, Ord x, Ord y) =>
NMoves
-> SearchState x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean)
Search.AlphaBeta.negaMax NMoves
searchDepth (SearchState x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean))
-> SearchState x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ NMoves
-> MaybeRetireAfterNMoves
-> MaybeRetireAfterNMoves
-> SearchState x y positionHash criterionValue weightedMean
-> SearchState x y positionHash criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
NMoves
-> MaybeRetireAfterNMoves
-> MaybeRetireAfterNMoves
-> SearchState x y positionHash criterionValue weightedMean
-> SearchState x y positionHash criterionValue weightedMean
Search.SearchState.euthanise NMoves
nPlies MaybeRetireAfterNMoves
maybeRetireKillerMovesAfter MaybeRetireAfterNMoves
maybeRetireTranspositionsAfter SearchState x y positionHash criterionValue weightedMean
searchState
case NMoves
-> Result x y positionHash criterionValue weightedMean
-> (DynamicMoveData x y positionHash, [Turn x y], NMoves)
forall x y positionHash criterionValue weightedMean.
NMoves
-> Result x y positionHash criterionValue weightedMean
-> (DynamicMoveData x y positionHash, [Turn x y], NMoves)
Search.AlphaBeta.extractSelectedTurns NMoves
nPlies Result x y positionHash criterionValue weightedMean
searchResult of
(DynamicMoveData x y positionHash
dynamicMoveData, turns :: [Turn x y]
turns@(Turn x y
turn : [Turn x y]
_), NMoves
nMovesEvaluated) -> let
isMatch :: Turn x y
-> NodeLabel x y positionHash criterionValue weightedMean -> Bool
isMatch Turn x y
turn' = (Turn x y -> Turn x y -> Bool
forall a. Eq a => a -> a -> Bool
== Turn x y
turn') (Turn x y -> Bool)
-> (NodeLabel x y positionHash criterionValue weightedMean
-> Turn x y)
-> NodeLabel x y positionHash criterionValue weightedMean
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QuantifiedGame x y criterionValue weightedMean -> Turn x y
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Turn x y
Evaluation.QuantifiedGame.getLastTurn (QuantifiedGame x y criterionValue weightedMean -> Turn x y)
-> (NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean)
-> NodeLabel x y positionHash criterionValue weightedMean
-> Turn x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
Evaluation.PositionHashQuantifiedGameTree.getQuantifiedGame
in Result x y positionHash criterionValue weightedMean
-> Reader (Result x y positionHash criterionValue weightedMean)
forall (m :: * -> *) a. Monad m => a -> m a
return MkResult :: forall x y positionHash criterionValue weightedMean.
SearchState x y positionHash criterionValue weightedMean
-> [QuantifiedGame x y criterionValue weightedMean]
-> NMoves
-> Result x y positionHash criterionValue weightedMean
MkResult {
getSearchState :: SearchState x y positionHash criterionValue weightedMean
getSearchState = PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> DynamicMoveData x y positionHash
-> SearchState x y positionHash criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> DynamicMoveData x y positionHash
-> SearchState x y positionHash criterionValue weightedMean
Search.SearchState.mkSearchState (
PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> Maybe
(PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe (
Exception
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
forall a e. Exception e => e -> a
Control.Exception.throw (Exception
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
-> Exception
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkIncompatibleData String
"BishBosh.Search.Search.search:\tBishBosh.Data.RoseTree.reduce failed."
) (Maybe
(PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
-> Maybe
(PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
forall a b. (a -> b) -> a -> b
$ IsMatch (NodeLabel x y positionHash criterionValue weightedMean)
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> Maybe
(PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
forall x y positionHash criterionValue weightedMean.
IsMatch (NodeLabel x y positionHash criterionValue weightedMean)
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> Maybe
(PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean)
Evaluation.PositionHashQuantifiedGameTree.reduce (Turn x y
-> IsMatch (NodeLabel x y positionHash criterionValue weightedMean)
forall x y positionHash criterionValue weightedMean.
(Eq x, Eq y) =>
Turn x y
-> NodeLabel x y positionHash criterionValue weightedMean -> Bool
isMatch Turn x y
turn) PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
positionHashQuantifiedGameTree
) DynamicMoveData x y positionHash
dynamicMoveData,
getQuantifiedGames :: [QuantifiedGame x y criterionValue weightedMean]
getQuantifiedGames = (NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean)
-> [NodeLabel x y positionHash criterionValue weightedMean]
-> [QuantifiedGame x y criterionValue weightedMean]
forall a b. (a -> b) -> [a] -> [b]
map NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
NodeLabel x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
Evaluation.PositionHashQuantifiedGameTree.getQuantifiedGame ([NodeLabel x y positionHash criterionValue weightedMean]
-> [QuantifiedGame x y criterionValue weightedMean])
-> (Maybe [NodeLabel x y positionHash criterionValue weightedMean]
-> [NodeLabel x y positionHash criterionValue weightedMean])
-> Maybe [NodeLabel x y positionHash criterionValue weightedMean]
-> [QuantifiedGame x y criterionValue weightedMean]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NodeLabel x y positionHash criterionValue weightedMean]
-> Maybe [NodeLabel x y positionHash criterionValue weightedMean]
-> [NodeLabel x y positionHash criterionValue weightedMean]
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe (
Exception
-> [NodeLabel x y positionHash criterionValue weightedMean]
forall a e. Exception e => e -> a
Control.Exception.throw (Exception
-> [NodeLabel x y positionHash criterionValue weightedMean])
-> Exception
-> [NodeLabel x y positionHash criterionValue weightedMean]
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkSearchFailure String
"BishBosh.Search.Search.search:\tBishBosh.Data.RoseTree.traceRoute failed."
) (Maybe [NodeLabel x y positionHash criterionValue weightedMean]
-> [QuantifiedGame x y criterionValue weightedMean])
-> Maybe [NodeLabel x y positionHash criterionValue weightedMean]
-> [QuantifiedGame x y criterionValue weightedMean]
forall a b. (a -> b) -> a -> b
$ (Turn x y
-> IsMatch
(NodeLabel x y positionHash criterionValue weightedMean))
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> [Turn x y]
-> Maybe [NodeLabel x y positionHash criterionValue weightedMean]
forall x y positionHash criterionValue weightedMean.
(Turn x y
-> IsMatch
(NodeLabel x y positionHash criterionValue weightedMean))
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> [Turn x y]
-> Maybe [NodeLabel x y positionHash criterionValue weightedMean]
Evaluation.PositionHashQuantifiedGameTree.traceRoute Turn x y
-> IsMatch (NodeLabel x y positionHash criterionValue weightedMean)
forall x y positionHash criterionValue weightedMean.
(Eq x, Eq y) =>
Turn x y
-> NodeLabel x y positionHash criterionValue weightedMean -> Bool
isMatch PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
positionHashQuantifiedGameTree [Turn x y]
turns,
getNMovesEvaluated :: NMoves
getNMovesEvaluated = NMoves
nMovesEvaluated
}
(DynamicMoveData x y positionHash, [Turn x y], NMoves)
_ -> Exception
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a e. Exception e => e -> a
Control.Exception.throw (Exception
-> Reader (Result x y positionHash criterionValue weightedMean))
-> Exception
-> Reader (Result x y positionHash criterionValue weightedMean)
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkNullDatum String
"BishBosh.Search.Search.search:\tzero turns selected."
where
positionHashQuantifiedGameTree :: PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
positionHashQuantifiedGameTree = SearchState x y positionHash criterionValue weightedMean
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
SearchState x y positionHash criterionValue weightedMean
-> PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
Search.SearchState.getPositionHashQuantifiedGameTree SearchState x y positionHash criterionValue weightedMean
searchState
game :: Game x y
game = QuantifiedGame x y criterionValue weightedMean -> Game x y
forall x y criterionValue weightedMean.
QuantifiedGame x y criterionValue weightedMean -> Game x y
Evaluation.QuantifiedGame.getGame (QuantifiedGame x y criterionValue weightedMean -> Game x y)
-> QuantifiedGame x y criterionValue weightedMean -> Game x y
forall a b. (a -> b) -> a -> b
$ PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
forall x y positionHash criterionValue weightedMean.
PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
-> QuantifiedGame x y criterionValue weightedMean
Evaluation.PositionHashQuantifiedGameTree.getRootQuantifiedGame PositionHashQuantifiedGameTree
x y positionHash criterionValue weightedMean
positionHashQuantifiedGameTree
calculateBranchingFactor :: Floating branchingFactor => Result x y positionHash criterionValue weightedMean -> branchingFactor
calculateBranchingFactor :: Result x y positionHash criterionValue weightedMean
-> branchingFactor
calculateBranchingFactor MkResult {
getQuantifiedGames :: forall x y positionHash criterionValue weightedMean.
Result x y positionHash criterionValue weightedMean
-> [QuantifiedGame x y criterionValue weightedMean]
getQuantifiedGames = [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames,
getNMovesEvaluated :: forall x y positionHash criterionValue weightedMean.
Result x y positionHash criterionValue weightedMean -> NMoves
getNMovesEvaluated = NMoves
nMovesEvaluated
}
| [QuantifiedGame x y criterionValue weightedMean] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames = Exception -> branchingFactor
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> branchingFactor) -> Exception -> branchingFactor
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkNullDatum String
"BishBosh.Search.Search.calculateBranchingFactor:\tnull quantifiedGames."
| NMoves
nMovesEvaluated NMoves -> NMoves -> Bool
forall a. Eq a => a -> a -> Bool
== NMoves
0 = Exception -> branchingFactor
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> branchingFactor) -> Exception -> branchingFactor
forall a b. (a -> b) -> a -> b
$ String -> Exception
Data.Exception.mkInsufficientData String
"BishBosh.Search.Search.calculateBranchingFactor:\tzero moves analysed."
| Bool
otherwise = NMoves -> branchingFactor
forall a b. (Integral a, Num b) => a -> b
fromIntegral NMoves
nMovesEvaluated branchingFactor -> branchingFactor -> branchingFactor
forall a. Floating a => a -> a -> a
** branchingFactor -> branchingFactor
forall a. Fractional a => a -> a
recip (
NMoves -> branchingFactor
forall a b. (Integral a, Num b) => a -> b
fromIntegral (NMoves -> branchingFactor) -> NMoves -> branchingFactor
forall a b. (a -> b) -> a -> b
$ [QuantifiedGame x y criterionValue weightedMean] -> NMoves
forall (t :: * -> *) a. Foldable t => t a -> NMoves
length [QuantifiedGame x y criterionValue weightedMean]
quantifiedGames
)