hstzaar-0.4: src/AI/Lame.hs
-- | An example AI player.
module AI.Lame (lame) where
import System.Random
import AI.Utils
import Board
lame :: AI
lame = AI
{ name = "lame"
, description = "Randomly selects the next valid turn."
, strategy = (ifPieces (==60)
lameStrategy0
(winOrPreventLoss lameStrategy)
)
}
-- | The lame strategy picks a valid turn at random. If a two-move turn is available, it picks one. (wow, pretty smart!)
lameStrategy :: Strategy
lameStrategy (GameTree _ branches) g = (turns !! i, g')
where
allTurns = fst $ unzip branches
goodTurns = [ (m1, Just m2) | (m1, Just m2) <- allTurns ]
turns = if null goodTurns then allTurns else goodTurns
(i, g') = randomR (0, length turns - 1) g
-- starting move
lameStrategy0 :: Strategy
lameStrategy0 (GameTree _ branches) g = (turns !! i, g')
where
allTurns = fst $ unzip branches
turns = [ (m1, Nothing) | (m1, Nothing) <- allTurns ]
(i, g') = randomR (0, length turns - 1) g