Skip to content

Commit

Permalink
canonicalize tableaus
Browse files Browse the repository at this point in the history
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 ac187ed
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ac187ed

Please sign in to comment.