add pvp mode, add chan communicator instance, fix json instances
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
module Skat.AI.Online where
|
module Skat.AI.Online where
|
||||||
|
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
import Control.Concurrent.Chan
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.ByteString.Lazy.Char8 as BS
|
import qualified Data.ByteString.Lazy.Char8 as BS
|
||||||
@@ -19,6 +20,10 @@ class Communicator a where
|
|||||||
send :: a -> String -> IO ()
|
send :: a -> String -> IO ()
|
||||||
receive :: a -> IO String
|
receive :: a -> IO String
|
||||||
|
|
||||||
|
instance Communicator (Chan String) where
|
||||||
|
send = writeChan
|
||||||
|
receive = readChan
|
||||||
|
|
||||||
class Monad m => MonadClient m where
|
class Monad m => MonadClient m where
|
||||||
query :: String -> m ()
|
query :: String -> m ()
|
||||||
response :: m String
|
response :: m String
|
||||||
|
|||||||
+13
-4
@@ -1,5 +1,5 @@
|
|||||||
module Skat.Matches (
|
module Skat.Matches (
|
||||||
singleVsBots
|
singleVsBots, pvp
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
@@ -31,11 +31,20 @@ cardDistr = emptyPiles hand1 hand2 hand3 skt
|
|||||||
|
|
||||||
singleVsBots :: Communicator c => c -> IO ()
|
singleVsBots :: Communicator c => c -> IO ()
|
||||||
singleVsBots comm = do
|
singleVsBots comm = do
|
||||||
--let gen = mkStdGen 123
|
cards <- shuffleCards
|
||||||
-- cards = shuffleCardsWithGen gen
|
|
||||||
let ps = Players
|
let ps = Players
|
||||||
(PL $ OnlineEnv Team Hand1 comm)
|
(PL $ OnlineEnv Team Hand1 comm)
|
||||||
(PL $ Stupid Team Hand2)
|
(PL $ Stupid Team Hand2)
|
||||||
(PL $ mkAIEnv Single Hand3 10)
|
(PL $ mkAIEnv Single Hand3 10)
|
||||||
env = SkatEnv cardDistr Nothing Spades ps Hand1
|
env = SkatEnv (distribute cards) Nothing Spades ps Hand1
|
||||||
|
liftIO $ evalStateT (publishGameStart Hand3 >> turn >>= publishGameResults) env
|
||||||
|
|
||||||
|
pvp :: Communicator c => c -> c -> c -> IO ()
|
||||||
|
pvp comm1 comm2 comm3 = do
|
||||||
|
cards <- shuffleCards
|
||||||
|
let ps = Players
|
||||||
|
(PL $ OnlineEnv Team Hand1 comm1)
|
||||||
|
(PL $ OnlineEnv Team Hand2 comm2)
|
||||||
|
(PL $ OnlineEnv Team Hand3 comm3)
|
||||||
|
env = SkatEnv (distribute cards) Nothing Spades ps Hand1
|
||||||
liftIO $ evalStateT (publishGameStart Hand3 >> turn >>= publishGameResults) env
|
liftIO $ evalStateT (publishGameStart Hand3 >> turn >>= publishGameResults) env
|
||||||
|
|||||||
+2
-1
@@ -62,7 +62,8 @@ data Owner = P Hand | S
|
|||||||
deriving (Show, Eq, Ord, Read)
|
deriving (Show, Eq, Ord, Read)
|
||||||
|
|
||||||
instance ToJSON Owner where
|
instance ToJSON Owner where
|
||||||
toJSON _ = undefined -- TODO: fix
|
toJSON (P hand) = object ["owner" .= show hand]
|
||||||
|
toJSON S = object ["owner" .= ("skat" :: String) ]
|
||||||
|
|
||||||
type Played = Owner -- TODO: remove
|
type Played = Owner -- TODO: remove
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user