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:
		
							parent
							
								
									a57e36dca8
								
							
						
					
					
						commit
						6ab7cdfdc9
					
				
					 2 changed files with 10 additions and 2 deletions
				
			
		|  | @ -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) | ||||||
| 
 | 
 | ||||||
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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) -> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue