Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented ShuffleLibrary

  • Loading branch information...
commit dc0f477d89dbadf39ffb3b87382d90a3d21df0c3 1 parent 0ae763a
@MedeaMelana authored
Showing with 21 additions and 6 deletions.
  1. +11 −4 Engine.hs
  2. +9 −1 IdList.hs
  3. +1 −1  Types.hs
View
15 Engine.hs
@@ -9,15 +9,17 @@ import Types
import Control.Applicative ((<$>))
import Control.Monad (forever)
-import Control.Monad.State (StateT)
import Control.Monad.Operational
+import Control.Monad.Random (RandT, StdGen)
+import Control.Monad.State (StateT)
+import Control.Monad.Trans (lift)
import Data.Ord (comparing)
-import Data.Label.Pure
-import Data.Label.PureM
+import Data.Label.Pure (set)
+import Data.Label.PureM (gets, puts, (=:))
import Data.List (sortBy)
import Data.Traversable (for)
-type Engine = StateT World (Program Ask)
+type Engine = StateT World (RandT StdGen (Program Ask))
round :: Engine ()
round = forever $ do
@@ -150,6 +152,11 @@ compileEffect (MoveObject rObject@(rFromZone, i) rToZone) = do
Just object -> do
compileZoneRef rFromZone ~: IdList.remove i
compileZoneRef rToZone ~: IdList.cons object
+compileEffect (ShuffleLibrary rPlayer) = do
+ let libraryLabel = players .^ mapEl rPlayer .^ library
+ lib <- gets libraryLabel
+ lib' <- lift (IdList.shuffle lib)
+ puts libraryLabel lib'
compileEffect _ = undefined
lookupObject :: ObjectRef -> Engine (Maybe Object)
View
10 IdList.hs
@@ -1,11 +1,14 @@
module IdList
( Id, IdList
- , empty, get, set, remove, cons, toList, filter
+ , empty, get, set, remove, cons, toList, filter, shuffle
) where
import Prelude hiding (filter)
import qualified Prelude
+import Control.Monad.Random (MonadRandom)
+import System.Random.Shuffle (shuffleM)
+
type Id = Int
data IdList a = IdList [(Id, a)] Id
@@ -37,3 +40,8 @@ toList (IdList ixs _) = ixs
filter :: (a -> Bool) -> IdList a -> [(Id, a)]
filter f = Prelude.filter (f . snd) . toList
+
+shuffle :: MonadRandom m => IdList a -> m (IdList a)
+shuffle (IdList ixs ni) = do
+ ixs' <- shuffleM ixs
+ return (IdList ixs' ni)
View
2  Types.hs
@@ -298,7 +298,7 @@ data OneShotEffect
= AdjustLife PlayerRef Int
| DamageObject ObjectRef ObjectRef Int Bool Bool -- source, creature/planeswalker, amount, combat damage?, preventable?
| DamagePlayer ObjectRef PlayerRef Int Bool Bool -- source, player, amount, combat damage?, preventable?
- | ShuffleLibrary
+ | ShuffleLibrary PlayerRef
-- | ReorderLibraryCards
| DrawCard PlayerRef -- Drawing is special [120.5]
| DestroyPermanent ObjectRef Bool -- target, preventable? -- Destruction is special [701.6b]
Please sign in to comment.
Something went wrong with that request. Please try again.