Permalink
Browse files

enterPlayer; adapted Utils to new types

  • Loading branch information...
1 parent 03412c5 commit 35500f3bcaf6329b6ab35eb4749b5ac12e2f1152 @MedeaMelana committed Sep 3, 2012
Showing with 35 additions and 11 deletions.
  1. +14 −5 Engine.hs
  2. +4 −1 IdList.hs
  3. +1 −1 Types.hs
  4. +16 −4 Utils.hs
View
@@ -6,9 +6,10 @@ import qualified IdList
import Labels
import Predicates
import Types
+import Utils
import Control.Applicative ((<$>))
-import Control.Monad (forever, void)
+import Control.Monad (forever, void, forM_)
import Control.Monad.Operational
import Control.Monad.Random (RandT, StdGen)
import Control.Monad.State (StateT)
@@ -21,6 +22,14 @@ import Data.Traversable (for)
type Engine = StateT World (RandT StdGen (Program Ask))
+
+enterPlayer :: [Card] -> Engine ()
+enterPlayer deck = do
+ playerId <- IdList.consM players player
+ forM_ deck $ \card -> do
+ t <- tick
+ IdList.consM (players .^ listEl playerId .^ library) (instantiateCard card t playerId)
+
round :: Engine ()
round = forever $ do
players ~:* set manaPool []
@@ -155,12 +164,12 @@ compileEffect (DrawCard rp) = do
(ro, _) : _ -> executeEffect (MoveObject (Library rp, ro) (Hand rp))
compileEffect (MoveObject (rFromZone, i) rToZone) = do
- mObject <- IdList.removeM (compileZoneRef rFromZone) i
- case mObject of
+ mObj <- IdList.removeM (compileZoneRef rFromZone) i
+ case mObj of
Nothing -> return ()
- Just object -> do
+ Just obj -> do
t <- tick
- void (IdList.consM (compileZoneRef rToZone) (set timestamp t object))
+ void (IdList.consM (compileZoneRef rToZone) (set timestamp t obj))
compileEffect (ShuffleLibrary rPlayer) = do
let libraryLabel = players .^ listEl rPlayer .^ library
View
@@ -2,7 +2,7 @@
module IdList
( Id, IdList
- , empty, get, set, remove, cons, toList, filter, shuffle
+ , empty, get, set, remove, cons, fromList, toList, filter, shuffle
, consM, removeM, shuffleM
) where
@@ -48,6 +48,9 @@ cons x (IdList ixs i) = (i, IdList ((i, x) : ixs) (succ i))
contents :: ([(Id, a)] -> [(Id, b)]) -> IdList a -> IdList b
contents f (IdList ixs i) = IdList (f ixs) i
+fromList :: [a] -> IdList a
+fromList = foldr (\x xs -> snd (cons x xs)) empty
+
toList :: IdList a -> [(Id, a)]
toList (IdList ixs _) = ixs
View
@@ -85,7 +85,7 @@ data Player = Player
data Card = Card
-- timestamp, owner (and controller)
- { enterWorld :: Timestamp -> PlayerRef-> Object
+ { instantiateCard :: Timestamp -> PlayerRef-> Object
}
data Object = Object
View
@@ -2,6 +2,7 @@
module Utils where
+import qualified IdList
import Types
import Control.Monad.State (State, execState)
@@ -12,14 +13,25 @@ import qualified Data.Set as Set
mkCard :: State Object () -> Card
-mkCard f = Card (\ts rOwner zone -> execState f (object ts rOwner zone))
+mkCard f = Card (\ts rOwner -> execState f (object ts rOwner))
+
+player :: Player
+player = Player
+ { _life = 20
+ , _manaPool = []
+ , _prestack = []
+ , _library = IdList.empty
+ , _hand = IdList.empty
+ , _graveyard = IdList.empty
+ , _maximumHandSize = Just 7
+ , _failedCardDraw = False
+ }
-object :: Timestamp -> Ref Player -> Zone -> Object
-object ts rOwner zone = Object
+object :: Timestamp -> PlayerRef -> Object
+object ts rOwner = Object
{ _name = Nothing
, _colors = mempty
, _types = mempty
- , _zone = zone
, _owner = rOwner
, _controller = rOwner
, _timestamp = ts

0 comments on commit 35500f3

Please sign in to comment.