Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
Make roughness independent of tile value
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Apr 6, 2014
1 parent 5370a11 commit 222df4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions library/Hs2048/AI.hs
Expand Up @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion test-suite/Hs2048/AISpec.hs
Expand Up @@ -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

0 comments on commit 222df4d

Please sign in to comment.