From 444e50cdb1910a4ea6b7faf4a6718772c5f321cd Mon Sep 17 00:00:00 2001 From: flavis Date: Wed, 19 Jan 2022 11:43:18 +0100 Subject: [PATCH] add two vs bot --- src/Skat/Matches.hs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Skat/Matches.hs b/src/Skat/Matches.hs index 8284ecd..eff9b70 100644 --- a/src/Skat/Matches.hs +++ b/src/Skat/Matches.hs @@ -1,11 +1,11 @@ module Skat.Matches ( singleVsBots, pvp, singleWithBidding, Match(..), Unfinished(..), continue, - Table(..) + Table(..), twoWithBidding, H(..), randomPositions ) where import Control.Monad.State import Control.Monad.Reader -import System.Random (mkStdGen) +import System.Random (mkStdGen, newStdGen) import Skat import Skat.Operations @@ -14,6 +14,7 @@ import Skat.Pile import Skat.Card import Skat.Preperation import Skat.Bidding +import Skat.Utils (shuffle) import Skat.AI.Rulebased import Skat.AI.Online @@ -122,6 +123,26 @@ singleWithBidding comm = do env = makePrep ps bs void $ match env +--- helper object for twoWithBidding +data H = P1 | P2 | AI + +randomPositions :: IO [H] +randomPositions = do + gen <- newStdGen + return $ shuffle gen [P1, P2, AI] + +twoWithBidding :: Communicator c => [H] -> c -> c -> IO () +twoWithBidding positions comm1 comm2 = do + cards <- shuffleCards + let bds = zipWith mkBidder [Hand1, Hand2, Hand3] positions + ps = distribute cards + mkBidder hand P1 = BD $ PrepOnline hand comm1 (map toCard $ handCards hand ps) + mkBidder hand P2 = BD $ PrepOnline hand comm2 (map toCard $ handCards hand ps) + mkBidder hand AI = BD $ NoBidder hand + bs = Bidders (bds !! 0) (bds !! 1) (bds !! 2) + env = makePrep ps bs + void $ match env + pvp :: Communicator c => c -> c -> c -> IO Table pvp comm1 comm2 comm3 = do cards <- shuffleCards