Permalink
Browse files

canonicalize tableaus

The solver was wasting incredible amounts of time shuffling cards around
between equivalent states. Picture two long runs with an empty column: it
would try every permutation of runs on columns, then break up the runs to try
every permutation of cards in runs or the empty column. Then it would slightly
move some other card in another column and do it all again.

Sorting the cells and columns makes for an incredible reduction in the number
of states enumerated during a solving. Putting Dragon before Suited puts them
on the left because freeing them up for collection is a very positive move and
possibleMoves generates Pack commands from left-to-right.
  • Loading branch information...
pushcx committed Oct 23, 2017
1 parent 0177fec commit ac187ed668cc6c593a1475adfb7f3667617ff046
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/Main.hs
View
@@ -44,7 +44,7 @@ instance Show Rank where
show Nine = "9"
data Card = Flower | Suited Suit Rank | Dragon Suit
data Card = Flower | Dragon Suit | Suited Suit Rank
deriving (Eq, Ord)
instance Show Card where
@@ -368,9 +368,12 @@ takeCardFromCol cols i = (card, newCols)
newCol = drop 1 fromCol
newCols = replaceIndex i newCol cols
canonicalize :: Tableau -> Tableau
canonicalize (Tableau cells fl fo cols) = Tableau (sort cells) fl fo (sort cols)
-- applys a player's move and automatically builds if possible
applyT :: Tableau -> Move -> Tableau
applyT t m = automaticBuild (applied t m)
applyT t m = canonicalize $ automaticBuild (applied t m)
where
applied (Tableau cells fl fo cols) (MoveFromColumnToCell coli celli) = Tableau newCells fl fo newCols
where
@@ -509,7 +512,7 @@ outcomes ls g
where
seen = previous g -- [Tableau]
now = last seen
moves = possibleMoves (trace (show (moveCount g) ++ " " ++ show now) now)
moves = possibleMoves (trace (show (moveCount g) ++ " " show (length ls) ++ " " ++ show now) now)
foo :: Losses -> Tableau -> Bool
foo ls' tab = tab `Set.notMember` ls' && tab `notElem` seen
bar :: Losses -> [Move] -> Either Losses (Game, Losses)

0 comments on commit ac187ed

Please sign in to comment.