Only allow adjacent gormlaks to attack

Previously the isUnit function was falsely returning `True` for
positions that were one tile off in *either* direction from the
character, when it should've been *both*. Oops.
This commit is contained in:
Griffin Smith 2019-10-06 13:13:00 -04:00
parent a57e36dca8
commit 6ab7cdfdc9
2 changed files with 10 additions and 2 deletions

View file

@ -136,7 +136,8 @@ diffPositions (Position x₁ y₁) (Position x₂ y₂) = Position (x₁ - x₂)
-- --
-- ∀ dir :: Direction. isUnit ('asPosition' dir) -- ∀ dir :: Direction. isUnit ('asPosition' dir)
isUnit :: Position -> Bool isUnit :: Position -> Bool
isUnit (Position px py) = abs px == 1 || abs py == 1 isUnit (Position px py) =
abs px `elem` [0,1] && abs py `elem` [0, 1] && (px, py) /= (0, 0)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -26,7 +26,14 @@ test = testGroup "Xanthous.Data"
directionOf pos (move dir pos) == dir directionOf pos (move dir pos) == dir
, testProperty "diffPositions is add inverse" $ \pos pos -> , testProperty "diffPositions is add inverse" $ \pos pos ->
diffPositions pos pos == addPositions pos (invert pos) diffPositions pos pos == addPositions pos (invert pos)
, testGroup "isUnit"
[ testProperty "double direction is never unit" $ \dir ->
not . isUnit $ move dir (asPosition dir)
, testCase "examples" $ do
isUnit (Position 1 1) @? "not . isUnit $ Position 1 1"
isUnit (Position 0 (-1)) @? "not . isUnit $ Position 0 (-1)"
(not . isUnit) (Position 1 13) @? "isUnit $ Position 1 13"
]
] ]
, testGroup "Direction" , testGroup "Direction"
[ testProperty "opposite is involutive" $ \(dir :: Direction) -> [ testProperty "opposite is involutive" $ \(dir :: Direction) ->