implement online player bidding

This commit is contained in:
2020-03-28 22:30:06 +01:00
parent b6b92c2cf9
commit 1ccce66d4a
5 changed files with 173 additions and 17 deletions
+13 -10
View File
@@ -1,11 +1,11 @@
{-# LANGUAGE ExistentialQuantification #-}
module Skat.Preperation (
Bidder(..), Bid, BD(..), Bidders(..), PrepEnv(..), runPreperation
) where
import Control.Monad.IO.Class
import Control.Monad.State
import Control.Monad.Reader
import Skat.Pile
import Skat.Card
@@ -16,17 +16,16 @@ import Skat (SkatEnv, mkSkatEnv)
type Bid = Int
data PrepEnv = PrepEnv { piles :: Piles
, currentBid :: Bid
, currentHand :: Hand
, bidders :: Bidders }
deriving Show
type Preperation = StateT PrepEnv IO
type Preperation = ReaderT PrepEnv IO
class Bidder a where
hand :: a -> Hand
onStart :: MonadIO m => a -> m ()
askBid :: MonadIO m => a -> Hand -> Bid -> m (Maybe Bid)
askResponse :: MonadIO m => a -> Hand -> m Bool
askResponse :: MonadIO m => a -> Hand -> Bid -> m Bool
askGame :: MonadIO m => a -> Bid -> m Game
askHand :: MonadIO m => a -> Bid -> m Bool
askSkat :: MonadIO m => a -> Bid -> [Card] -> m [Card]
@@ -46,6 +45,7 @@ instance Bidder BD where
askSkat (BD b) = askSkat b
askResponse (BD b) = askResponse b
toPlayer (BD b) = toPlayer b
onStart (BD b) = onStart b
data Bidders = Bidders BD BD BD
deriving Show
@@ -63,7 +63,10 @@ toPlayers single (Bidders b1 b2 b3) =
runPreperation :: Preperation (Maybe SkatEnv)
runPreperation = do
bds <- gets bidders
bds <- asks bidders
onStart (bidder bds Hand1)
onStart (bidder bds Hand2)
onStart (bidder bds Hand3)
(winner, bid) <- runBidding 0 (bidder bds Hand2) (bidder bds Hand1)
(finalWinner, finalBid) <- runBidding 0 (bidder bds Hand3) (bidder bds winner)
if finalBid == 0 then do
@@ -78,15 +81,15 @@ runBidding startingBid reizer gereizter = do
first <- askBid reizer (hand gereizter) startingBid
case first of
Just val -> do
response <- askResponse gereizter (hand reizer)
response <- askResponse gereizter (hand reizer) val
if response then runBidding val reizer gereizter
else return (hand reizer, val)
Nothing -> return (hand gereizter, startingBid)
initGame :: Hand -> Bid -> Preperation SkatEnv
initGame single bid = do
ps <- gets piles
bds <- gets bidders
ps <- asks piles
bds <- asks bidders
-- ask if player wants to play hand
noSkat <- askHand (bidder bds single) bid
-- either return piles or ask for skat cards and modify piles