hstzaar-0.6: src/AI/Lame.hs
-- | An example AI player.
module AI.Lame(lameStrategy) where
import System.Random
import AI.Utils
import Board
-- randomly selects the next valid turn
lameStrategy :: Strategy
lameStrategy = withNPieces $
\n -> if n==60 then lame0 else lameNext
-- | Starting move: capture only
lame0 :: Strategy
lame0 (GameTree _ branches) rnd = (turns !! i, rnd')
where
turns = [ (m1, Pass) | (m1, _) <- branches ]
(i, rnd') = randomR (0, length turns - 1) rnd
-- | The lame strategy picks a valid turn at random.
-- If a two-move turn is available, it picks one. (wow, pretty smart!)
lameNext :: Strategy
lameNext (GameTree _ branches) rnd = (turns !! i, rnd')
where
allTurns = [ (m1,m2) |
(m1,GameTree _ branches')<-branches,
(m2, _) <- branches']
goodTurns = [ (m1, m2) | (m1, m2) <- allTurns, m2/=Pass ]
turns = if null goodTurns then allTurns else goodTurns
(i, rnd') = randomR (0, length turns - 1) rnd