Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More progress on the alternate representation

  • Loading branch information...
commit 7f7647e77ecdbdb08896238e4c190c5eb3ef4cc6 1 parent 25c82f2
@RobinMorisset authored
Showing with 25 additions and 3 deletions.
  1. +19 −3 GameTree.hs
  2. +6 −0 TetrisBase.hs
View
22 GameTree.hs
@@ -66,17 +66,27 @@ minMax (Tree _s p (m1 : moves)) d =
-- one child when the parent is playing)
data SolutionTree state player a move where
STree :: (RatableState state player a, Eq player)
- => (Worth a player) -> state -> player -> [(SolutionTree state player a move, move)]
+ => (Worth player a) -> state -> player -> [(SolutionTree state player a move, move)]
-> SolutionTree state player a move
-- We are either sure of the value of a tree (ie we have been to the leaves in our simulation), or not
-- We also add which player is giving this valuation
-data Worth a player = Sure player a | Unsure player a
+data Worth player a = Sure player a | Unsure player a deriving (Eq)
-instance (Show a, Show player) => Show (Worth a player) where
+instance (Show a, Show player) => Show (Worth player a) where
show (Sure p v) = show p ++ "$$" ++ show v
show (Unsure p v) = show p ++ "$" ++ show v
+instance Functor (Worth player) where
+ fmap f (Sure p x) = Sure p $ f x
+ fmap f (Unsure p x) = Unsure p $ f x
+
+instance (Eq player, Ord a) => Ord (Worth player a) where
+ w1 <= w2 = fromW w1 <= fromW w2
+ where
+ fromW (Sure _ x) = x
+ fromW (Unsure _ x) = x
+
mkBaseSolutionTree :: player -> GameTree state player a move -> SolutionTree state player a move
mkBaseSolutionTree player (Tree s p gs) =
STree (Unsure player $ rate player s) s p $ map (first (mkBaseSolutionTree player)) gs
@@ -113,6 +123,12 @@ showSolutionTree d pre (STree w s p ts) =
minMax' :: player -> Depth -> SolutionTree state player a move -> SolutionTree state player a move
-- This branch is already completely explored, just return it as is
minMax' _ _ t@(STree (Sure _ _) _ _ _) = t
+-- We have reached a leaf, we can be sure about the result
+minMax' p _ (STree _ s pChoice []) = STree (Sure p $ rate p s) s pChoice []
+-- We are not allowed to look deeper
+minMax' _ 0 t = t
+-- General case
+minMax' p d (STree _ s pChoice ts) = undefined
{-
View
6 TetrisBase.hs
@@ -206,3 +206,9 @@ addToHistory pp = do
----- Connecting with game trees ----------------------------------------------
data SituationWorth = AIWin | PlayerWin | MaxHeight Int
+
+instance Ord SituationWorth where
+ AIWin <= _ = True
+ _ <= PlayerWin = True
+ MaxHeight h1 <= MaxHeight h2 = h1 <= h2
+ _ <= _ = False
Please sign in to comment.
Something went wrong with that request. Please try again.