Skat Engine und AI auf Haskell Basis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.3KB

  1. module Skat.Matches (
  2. singleVsBots, pvp, pvpWithBidding, singleWithBidding
  3. ) where
  4. import Control.Monad.State
  5. import Control.Monad.Reader
  6. import System.Random (mkStdGen)
  7. import Skat
  8. import Skat.Operations
  9. import Skat.Player
  10. import Skat.Pile
  11. import Skat.Card
  12. import Skat.Preperation
  13. import Skat.AI.Rulebased
  14. import Skat.AI.Online
  15. import Skat.AI.Stupid
  16. -- | predefined card distribution for testing purposes
  17. cardDistr :: Piles
  18. cardDistr = emptyPiles hand1 hand2 hand3 skt
  19. where hand3 = [Card Ace Spades, Card Jack Diamonds, Card Jack Clubs, Card King Spades,
  20. Card Nine Spades, Card Ace Diamonds, Card Queen Diamonds, Card Ten Clubs,
  21. Card Eight Clubs, Card King Clubs]
  22. hand1 = [Card Jack Spades, Card Jack Hearts, Card Ten Spades, Card Ace Hearts, Card Ten Hearts,
  23. Card Nine Hearts, Card Seven Clubs, Card Ace Clubs, Card King Diamonds,
  24. Card Ten Diamonds]
  25. hand2 = [Card Eight Spades, Card Queen Spades, Card Seven Spades, Card Seven Diamonds,
  26. Card Seven Hearts, Card Eight Hearts, Card Queen Hearts, Card King Hearts,
  27. Card Nine Diamonds, Card Eight Diamonds]
  28. skt = [Card Nine Clubs, Card Queen Clubs]
  29. singleVsBots :: Communicator c => c -> IO ()
  30. singleVsBots comm = do
  31. cards <- shuffleCards
  32. let ps = Players
  33. (PL $ OnlineEnv Team Hand1 comm)
  34. (PL $ Stupid Team Hand2)
  35. (PL $ mkAIEnv Single Hand3 10)
  36. env = SkatEnv (distribute cards) Nothing Spades ps Hand1
  37. liftIO $ evalStateT (publishGameStart >> turn >>= publishGameResults) env
  38. singleWithBidding :: Communicator c => c -> IO ()
  39. singleWithBidding comm = do
  40. cards <- shuffleCards
  41. let ps = distribute cards
  42. h1 = map toCard $ handCards Hand1 ps
  43. bs = Bidders
  44. (BD $ PrepOnline Hand1 comm h1)
  45. (BD $ NoBidder Hand2)
  46. (BD $ NoBidder Hand3)
  47. env = PrepEnv ps bs
  48. maySkatEnv <- liftIO $ runReaderT runPreperation env
  49. case maySkatEnv of
  50. Just skatEnv ->
  51. liftIO $ evalStateT (publishGameStart >> turn >>= publishGameResults) skatEnv
  52. Nothing -> putStrLn "No one wanted to play."
  53. pvp :: Communicator c => c -> c -> c -> IO ()
  54. pvp comm1 comm2 comm3 = do
  55. cards <- shuffleCards
  56. let ps = Players
  57. (PL $ OnlineEnv Team Hand1 comm1)
  58. (PL $ OnlineEnv Team Hand2 comm2)
  59. (PL $ OnlineEnv Team Hand3 comm3)
  60. env = SkatEnv (distribute cards) Nothing Spades ps Hand1
  61. liftIO $ evalStateT (publishGameStart >> turn >>= publishGameResults) env
  62. pvpWithBidding :: Communicator c => c -> c -> c -> IO ()
  63. pvpWithBidding comm1 comm2 comm3 = do
  64. cards <- shuffleCards
  65. let ps = distribute cards
  66. h1 = map toCard $ handCards Hand1 ps
  67. h2 = map toCard $ handCards Hand2 ps
  68. h3 = map toCard $ handCards Hand3 ps
  69. bs = Bidders
  70. (BD $ PrepOnline Hand1 comm1 $ h1)
  71. (BD $ PrepOnline Hand2 comm2 $ h2)
  72. (BD $ PrepOnline Hand3 comm3 $ h3)
  73. env = PrepEnv ps bs
  74. maySkatEnv <- liftIO $ runReaderT runPreperation env
  75. case maySkatEnv of
  76. Just skatEnv ->
  77. liftIO $ evalStateT (publishGameStart >> turn >>= publishGameResults) skatEnv
  78. Nothing -> putStrLn "No one wanted to play."