From 222df4d65e4a8ba02c5452f0301fee92425e875e Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Sun, 6 Apr 2014 16:48:08 -0500 Subject: [PATCH] Make roughness independent of tile value --- library/Hs2048/AI.hs | 6 +++--- test-suite/Hs2048/AISpec.hs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/Hs2048/AI.hs b/library/Hs2048/AI.hs index 215cda2..940fb20 100644 --- a/library/Hs2048/AI.hs +++ b/library/Hs2048/AI.hs @@ -72,14 +72,14 @@ quality b = sum each other. Smooth boards are generally better. >>> roughness [[Just 2, Just 4]] - 2 + 1 >>> roughness [[Just 2, Just 2]] 0 Blank tiles are ignored for the purposes of calculating roughness. >>> roughness [[Just 2, Nothing, Just 4]] - 2 + 1 -} roughness :: B.Board -> Int roughness b = boardRoughness b + boardRoughness (B.rotate b) @@ -96,6 +96,6 @@ duplicates :: B.Board -> [[Int]] duplicates = group . sort . (=<<) catMaybes vectorRoughness :: V.Vector -> Int -vectorRoughness v = sum (fmap abs (zipWith subtract ts (tail ts))) +vectorRoughness v = length (filter id (zipWith (/=) ts (tail ts))) where ts = catMaybes v diff --git a/test-suite/Hs2048/AISpec.hs b/test-suite/Hs2048/AISpec.hs index cf2a8a6..c119760 100644 --- a/test-suite/Hs2048/AISpec.hs +++ b/test-suite/Hs2048/AISpec.hs @@ -34,4 +34,4 @@ spec = do roughness [] `shouldBe` 0 it "calculates the roughness of a board" $ do - roughness b `shouldBe` 5734 + roughness b `shouldBe` 16