packages feed

hstzaar-0.8.2: src/AI.hs

-- | Library of AI Players
module AI (aiPlayers) where

import Board
import AI.Utils
import AI.Minimax
import AI.Eval
-- import Debug.Trace

-- all AI players; ply depth >1 do not necessarily play better!
aiPlayers :: [(String,AI)]
aiPlayers = ("level0",basic) : [("level"++show n, ply n) | n<-[1,2,3]]

-- basic AI: material evaluation, depth 1
basic = AI { name = "Level 0"
           , description = "Minimax alpha-beta depth 2 (eval0)"
           , strategy = negamaxStrategy 2 eval0
           }

-- better AI, parameterized by ply depth
ply :: Int -> AI
ply d = AI { name = "Level " ++ show d
           , description = 
               "Minimaxing alpha-beta depth " ++ show (2*d) ++ " (eval1)"
           , strategy = withStacks $ \n ->
                        -- increase depth inversely linear with number of stacks
                        let d' = roundup (((60-n)*2*d)`div`60 + 1)
                        in negamaxStrategy d' eval1
           }
  where roundup n = max 2 n -- + n`mod`2


{-
level2 = AI { name = "Level 2"
            , description = "Minimaxing alpha-beta depth 2-4 (eval1)"
            , strategy = (withNPieces $ \numpieces -> 
                              if numpieces<30 then
                                  minimaxStrategy 4 eval1
                              else
                                  minimaxStrategy 2 eval1
                         )
            }
-}