-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Solving simple games -- -- A library for solving and analyzing finite two-player games (e.g., Fox -- & Hounds). @package solve @version 1.3 module Solve.Util groupl :: Int -> [a] -> [[a]] groupr :: Int -> [a] -> [[a]] ppInteger :: Integral a => a -> String ppHugeInteger :: Integral a => a -> String parity :: [Bool] -> Bool singleton :: a -> [a] doubleton :: a -> a -> [a] tripleton :: a -> a -> a -> [a] middle :: [a] -> a mapLR :: (s -> a -> (b, s)) -> s -> [a] -> ([b], s) mapRL :: (a -> s -> (s, b)) -> [a] -> s -> (s, [b]) unfold :: (a -> (b, a)) -> a -> [b] unfoldN :: (a -> (b, a)) -> Int -> a -> ([b], a) updateSet :: Ord a => (a -> [a]) -> Set a -> [Set a] transitiveClosure :: Ord a => (a -> [a]) -> [a] -> Set a ucfirst :: String -> String type Prob = Double normalize :: [Double] -> [Prob] expectation :: [Prob] -> [Double] -> Double isZeroProb :: Prob -> Bool nonZeroProb :: Prob -> Bool isOneProb :: Prob -> Bool boolProb :: Bool -> Prob showProb :: Prob -> String uniformDist :: Int -> [Prob] sumDist :: Prob -> [Prob] -> [Prob] -> [Prob] fuzzDist :: Prob -> [Prob] -> [Prob] data Table Table :: Bool -> Bool -> Int -> Table [borderTable] :: Table -> Bool [alignLeftTable] :: Table -> Bool [paddingTable] :: Table -> Int fmtTable :: Table -> [[String]] -> String ppTable :: [[String]] -> String instance GHC.Show.Show Solve.Util.Table module Solve.Graph type DfsPre n a v = n -> Either v [(a, n)] type DfsPost n a v = n -> [((a, n), Maybe v)] -> v type DfsResult n v = Map n v dfsWith :: Ord n => DfsPre n a v -> DfsPost n a v -> DfsResult n v -> n -> (v, DfsResult n v) dfs :: Ord n => DfsPre n a v -> DfsPost n a v -> n -> (v, DfsResult n v) eval :: Ord n => DfsResult n v -> n -> Maybe v evalUnsafe :: Ord n => DfsResult n v -> n -> v bfs :: Ord n => (n -> [n]) -> n -> [n] module Solve.Game data Player Player1 :: Player Player2 :: Player newtype PlayerState s PlayerState :: (s, s) -> PlayerState s turn :: Player -> Player getPlayerState :: PlayerState s -> Player -> s updatePlayerState :: (s -> (a, s)) -> PlayerState s -> Player -> (a, PlayerState s) type Moves = Int data Event In :: Moves -> Event Never :: Event now :: Event delay :: Event -> Event nowOrNever :: Bool -> Event data Eval Win :: Player -> Moves -> Eval Draw :: Eval compareEval :: Player -> Eval -> Eval -> Ordering betterEval :: Player -> Eval -> Eval -> Bool bestEval :: Player -> [Eval] -> Eval winEval :: Player -> Eval delayEval :: Eval -> Eval turnEval :: Eval -> Eval betterResult :: Player -> Eval -> Eval -> Bool sameResult :: Eval -> Eval -> Bool winning :: Player -> Eval -> Bool type Game p = Player -> p -> Either Eval [p] move :: Game p -> Player -> p -> [p] gameOver :: Game p -> Player -> p -> Bool type DfsPre p a v = Player -> DfsPre p a v type DfsPost p a v = Player -> DfsPost p a v type Val p v = DfsResult (Player, p) v dfsWith :: Ord p => DfsPre p a v -> DfsPost p a v -> Val p v -> Player -> p -> (v, Val p v) eval :: Ord p => Val p v -> Player -> p -> Maybe v evalUnsafe :: Ord p => Val p v -> Player -> p -> v bfs :: Ord p => Game p -> Player -> p -> [(Player, p)] type Solve p = Val p Eval solveWith :: Ord p => Game p -> Solve p -> Player -> p -> (Eval, Solve p) solve :: Ord p => Game p -> Player -> p -> Solve p reachable :: Solve p -> Int perfectPlay :: Ord p => Game p -> Solve p -> Player -> p -> [(Player, p)] type Games p = Val p Integer gamesWith :: Ord p => Game p -> Games p -> Player -> p -> (Integer, Games p) games :: Ord p => Game p -> Player -> p -> Games p type Force p = Val p Event forceWith :: Ord p => Game p -> Player -> (Player -> p -> Bool) -> Force p -> Player -> p -> (Event, Force p) force :: Ord p => Game p -> Player -> (Player -> p -> Bool) -> Player -> p -> Force p data Max v Max :: v -> Moves -> Max v gameMaxWith :: (Ord p, Ord v) => Game p -> Player -> (Player -> p -> v) -> Val p (Max v) -> Player -> p -> (Max v, Val p (Max v)) gameMax :: (Ord p, Ord v) => Game p -> Player -> (Player -> p -> v) -> Player -> p -> Val p (Max v) type Study p = (Player, Val p Int) studyWith :: Ord p => Game p -> Solve p -> Study p -> Player -> p -> (Int, Study p) study :: Ord p => Game p -> Solve p -> Player -> Player -> p -> Study p bestStudies :: Study p -> [(Player, p)] criticalPath :: Ord p => Game p -> Study p -> Player -> p -> [(Player, p)] class Printable p ppPosition :: Printable p => p -> String ppPlayer :: Printable p => p -> Player -> String ppPlayerPosition :: Printable p => Player -> p -> String ppEval :: Printable p => p -> Eval -> String ppPlay :: Printable p => [(Player, p)] -> String instance GHC.Classes.Eq v => GHC.Classes.Eq (Solve.Game.Max v) instance GHC.Show.Show v => GHC.Show.Show (Solve.Game.Max v) instance GHC.Show.Show Solve.Game.Eval instance GHC.Classes.Eq Solve.Game.Eval instance GHC.Show.Show Solve.Game.Event instance GHC.Classes.Ord Solve.Game.Event instance GHC.Classes.Eq Solve.Game.Event instance GHC.Enum.Bounded Solve.Game.Player instance GHC.Enum.Enum Solve.Game.Player instance GHC.Show.Show Solve.Game.Player instance GHC.Classes.Ord Solve.Game.Player instance GHC.Classes.Eq Solve.Game.Player instance GHC.Classes.Ord v => GHC.Classes.Ord (Solve.Game.Max v) instance GHC.Classes.Ord Solve.Game.Eval module Solve.Strategy type Weight = Double type Strategy p = [(p, Weight)] -> [(p, Weight)] moveDistStrategy :: Eq p => Game p -> Strategy p -> Player -> p -> [(p, Prob)] distStrategy :: Eq p => Strategy p -> [p] -> [(p, Prob)] applyStrategy :: Strategy p -> [p] -> [(p, Weight)] weightlessStrategy :: [p] -> [(p, Weight)] idStrategy :: Strategy p noStrategy :: Strategy p thenStrategy :: Strategy p -> Strategy p -> Strategy p orelseStrategy :: Strategy p -> Strategy p -> Strategy p tryStrategy :: Strategy p -> Strategy p filterStrategy :: (p -> Bool) -> Strategy p maxStrategy :: Ord v => (p -> v) -> Strategy p bestStrategy :: Player -> (p -> Eval) -> Strategy p sameResultStrategy :: Player -> (p -> Eval) -> Strategy p stopLossStrategy :: Ord p => Solve p -> Player -> Moves -> Strategy p forceStrategy :: Ord p => Force p -> Player -> Moves -> Strategy p mixedStrategy :: Ord p => Prob -> Strategy p -> Strategy p -> Strategy p type StrategyFail p = Set ((p, Eval), (p, Eval), (p, Eval)) validateStrategy :: Ord p => Game p -> Solve p -> Player -> Strategy p -> Player -> p -> StrategyFail p type ProbWin p = Val p Prob type Adversaries p = PlayerState [(Strategy p, ProbWin p)] probWinWith :: Ord p => Game p -> Player -> Strategy p -> ProbWin p -> Player -> p -> (Prob, ProbWin p) probWin :: Ord p => Game p -> Player -> Strategy p -> Player -> p -> ProbWin p moveDist :: Ord p => Game p -> Solve p -> Adversaries p -> Player -> p -> ([(Prob, p)], Adversaries p) module Solve.QueenPawns boardSize :: Int data Coord Coord :: Int -> Int -> Coord xCoord :: Coord -> Int yCoord :: Coord -> Int onBoard :: Coord -> Bool darkSquare :: Coord -> Bool newtype Vector Vector :: Coord -> Vector [unVector] :: Vector -> Coord addVector :: Vector -> Vector -> Vector negVector :: Vector -> Vector northVector :: Vector eastVector :: Vector southVector :: Vector westVector :: Vector northWestVector :: Vector northEastVector :: Vector southEastVector :: Vector southWestVector :: Vector rookVectors :: [Vector] bishopVectors :: [Vector] queenVectors :: [Vector] moveByVector :: Vector -> Coord -> Coord moveAlongVector :: Vector -> Coord -> [Coord] moveAlongVectors :: [Vector] -> Coord -> [[Coord]] data PosRep PosRep :: Coord -> Set Coord -> PosRep [queen] :: PosRep -> Coord [pawns] :: PosRep -> Set Coord initialRep :: PosRep occupied :: PosRep -> Coord -> Bool empty :: PosRep -> Coord -> Bool queenMove :: PosRep -> [PosRep] pawnsMove :: PosRep -> [PosRep] moveRep :: Player -> PosRep -> [PosRep] pawnsToMoveVictoryRep :: PosRep -> Bool type Idx = Int newtype Pos Pos :: Idx -> Pos [unPos] :: Pos -> Idx mkPos :: PosRep -> Pos destPos :: Pos -> PosRep initial :: Pos move :: Player -> Pos -> [Pos] pawnsToMoveVictory :: Pos -> Bool game :: Game Pos gameOver :: Player -> Pos -> Bool evalInitial :: Val Pos v -> v bfsInitial :: [(Player, Pos)] solution :: Solve Pos winningFor :: Player -> Player -> Pos -> Bool winningForQueen :: Player -> Pos -> Bool winningForPawns :: Player -> Pos -> Bool winDepth :: Player -> Pos -> Int perfectPlay :: Player -> Pos -> [(Player, Pos)] games :: Games Pos gamesInitial :: Integer study :: Player -> Study Pos stopLossStrategy :: Player -> Int -> Strategy Pos validateStrategy :: Player -> Strategy Pos -> StrategyFail Pos probWin :: Player -> Strategy Pos -> ProbWin Pos opposite :: (Player, Pos) evalOpposite :: Val Pos v -> v typical :: (Player -> Pos -> Bool) -> (Player, Pos) ppPlayer :: Player -> String ppEval :: Eval -> String instance GHC.Classes.Ord Solve.QueenPawns.Pos instance GHC.Classes.Eq Solve.QueenPawns.Pos instance GHC.Classes.Ord Solve.QueenPawns.PosRep instance GHC.Classes.Eq Solve.QueenPawns.PosRep instance GHC.Classes.Ord Solve.QueenPawns.Vector instance GHC.Classes.Eq Solve.QueenPawns.Vector instance GHC.Classes.Ord Solve.QueenPawns.Coord instance GHC.Classes.Eq Solve.QueenPawns.Coord instance GHC.Show.Show Solve.QueenPawns.Pos instance Solve.Game.Printable Solve.QueenPawns.Pos instance GHC.Show.Show Solve.QueenPawns.PosRep instance GHC.Show.Show Solve.QueenPawns.Vector instance GHC.Show.Show Solve.QueenPawns.Coord module Solve.NoughtsCrosses boardSize :: Int data Coord Coord :: Int -> Int -> Coord coords :: [Int] row :: Int -> [Coord] column :: Int -> [Coord] board :: Set Coord winningLines :: [Set Coord] containsWinningLine :: Set Coord -> Bool data Pos Pos :: Set Coord -> Set Coord -> Pos [noughts] :: Pos -> Set Coord [crosses] :: Pos -> Set Coord initial :: Pos occupation :: Player -> Pos -> Set Coord free :: Pos -> Set Coord occupying :: Pos -> Coord -> Maybe Player occupied :: Pos -> Coord -> Bool isFree :: Pos -> Coord -> Bool occupy :: Player -> Coord -> Pos -> Pos move :: Player -> Pos -> [Pos] game :: Game Pos gameOver :: Player -> Pos -> Bool evalInitial :: Val Pos v -> v bfsInitial :: [(Player, Pos)] solution :: Solve Pos winningFor :: Player -> Player -> Pos -> Bool perfectPlay :: Player -> Pos -> [(Player, Pos)] games :: Games Pos gamesInitial :: Integer study :: Player -> Study Pos ppPlayer :: Player -> String ppEval :: Eval -> String instance GHC.Classes.Ord Solve.NoughtsCrosses.Pos instance GHC.Classes.Eq Solve.NoughtsCrosses.Pos instance GHC.Classes.Ord Solve.NoughtsCrosses.Coord instance GHC.Classes.Eq Solve.NoughtsCrosses.Coord instance GHC.Show.Show Solve.NoughtsCrosses.Pos instance Solve.Game.Printable Solve.NoughtsCrosses.Pos instance GHC.Show.Show Solve.NoughtsCrosses.Coord module Solve.FoxHounds packSize :: Int boardSize :: Int numSquares :: Int type Idx = Int data Coord Coord :: Int -> Int -> Coord onBoard :: Coord -> Bool rankAdjacent :: Int -> Int -> [Coord] foxAdjacent :: Coord -> [Coord] houndAdjacent :: Coord -> [Coord] houndsReachable :: Set Coord -> Set Coord foxReachable :: Set Coord -> Coord -> Set Coord coordParity :: Coord -> Bool coordToSquare :: Coord -> Idx squareToCoord :: Idx -> Coord data Pos Pos :: Coord -> Set Coord -> Pos [fox] :: Pos -> Coord [hounds] :: Pos -> Set Coord initial :: Pos occupied :: Pos -> Coord -> Bool empty :: Pos -> Coord -> Bool isFoxBox :: Pos -> Bool posParity :: Pos -> Bool posToMove :: Pos -> Player posToIdx :: Pos -> Idx idxToPos :: Idx -> Pos foxMove :: Pos -> [Pos] houndsMove :: Pos -> [Pos] move :: Player -> Pos -> [Pos] foxEscaped :: Pos -> Bool won :: Player -> Pos -> Maybe Player game :: Game Pos gameOver :: Player -> Pos -> Bool evalInitial :: Val Pos v -> v bfsInitial :: [(Player, Pos)] solution :: Solve Pos winningFor :: Player -> Player -> Pos -> Bool winningForFox :: Player -> Pos -> Bool winningForHounds :: Player -> Pos -> Bool winDepth :: Player -> Pos -> Int perfectPlay :: Player -> Pos -> [(Player, Pos)] games :: Games Pos gamesInitial :: Integer study :: Player -> Study Pos foxBox :: Force Pos maxFoxBox :: Val Pos (Max Event) stopLossStrategy :: Player -> Int -> Strategy Pos foxBoxStrategy :: Int -> Strategy Pos maxFoxBoxStrategy :: Player -> Strategy Pos foxStrategyN :: Int -> Strategy Pos houndsStrategyN :: Int -> Strategy Pos adversaries :: Adversaries Pos strategy :: Prob -> Player -> Strategy Pos moveDist :: Prob -> Player -> Pos -> [(Pos, Prob)] validateStrategy :: Player -> Strategy Pos -> StrategyFail Pos probWin :: Player -> Strategy Pos -> ProbWin Pos opposite :: (Player, Pos) evalOpposite :: Val Pos v -> v typical :: (Player -> Pos -> Bool) -> (Player, Pos) ppPlayer :: Player -> String ppEval :: Eval -> String instance GHC.Classes.Ord Solve.FoxHounds.Pos instance GHC.Classes.Eq Solve.FoxHounds.Pos instance GHC.Classes.Ord Solve.FoxHounds.Coord instance GHC.Classes.Eq Solve.FoxHounds.Coord instance GHC.Show.Show Solve.FoxHounds.Pos instance Solve.Game.Printable Solve.FoxHounds.Pos instance GHC.Show.Show Solve.FoxHounds.Coord