From 0ad88bb252766f7555f099dccea8d282e9e3bd9a Mon Sep 17 00:00:00 2001 From: Matthias Braendli Date: Mon, 9 Feb 2015 17:02:44 +0100 Subject: Save moves, not a string --- solitairesimulator2015.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/solitairesimulator2015.hs b/solitairesimulator2015.hs index 2a55969..1c30030 100644 --- a/solitairesimulator2015.hs +++ b/solitairesimulator2015.hs @@ -150,13 +150,13 @@ instance Show End where where Board pegs = b num_pegs = length pegs -solve_r :: Board -> String -> [End] -solve_r b s | null moves = [End (s ++ ".") b] - | otherwise = concat (map (uncurry solve_r) boards_strmoves ) +solve_r :: Board -> [Move] -> [End] +solve_r b m | null moves = [End (show m) b] + | otherwise = concat (map (uncurry solve_r) boards_moves ) where Board pegs = b (moves, boards) = unzip $ all_moves b - strmoves = map ((++) (s ++ " ")) (map show moves) :: [String] - boards_strmoves = zip boards strmoves :: [(Board, String)] + moves_append = map (flip (:) $ m) moves :: [[Move]] + boards_moves = zip boards moves_append :: [(Board, [Move])] pr board = putStrLn ("Welcome to Solitaire Simulator 2015 Deluxe Edition!\n From board\n" ++ show board ++ "\nIt is possible to do\n" ++ unlines (map show $ all_moves board)) @@ -173,6 +173,6 @@ main = do putStrLn $ unlines $ map show perfect_ends putStrLn "Only-one peg solutions:" putStrLn $ unlines $ map show good_ends - where ends = solve_r testboard "" + where ends = solve_r testboard [] good_ends = filter good_end ends perfect_ends = filter perfect_end ends -- cgit v1.2.3