From 7a5304e9b6c8f2f9b0cc2239f53ed0eac445c074 Mon Sep 17 00:00:00 2001 From: Shaun Kerr Date: Thu, 16 May 2019 09:34:10 +1200 Subject: [PATCH] better hurt/attract semantics --- Groups.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Groups.hs b/Groups.hs index 132f53f..e840f21 100644 --- a/Groups.hs +++ b/Groups.hs @@ -44,6 +44,11 @@ getAdj x nt = curFrens x nt ++ (foldr (++) [] (adjGroups x nt)) hurt :: MainCharacter -> MainCharacter -> BoardState -> BoardState hurt x y (nt,d) | not $ y `elem` (getAdj x nt) = (nt,d) + | otherwise = hurt' x y (nt,d) + +-- X hurts Y (no restrictions) +hurt' :: MainCharacter -> MainCharacter -> BoardState -> BoardState +hurt' x y (nt,d) | y `elem` d = if (curFrens y nt == []) then (nt, d) else ([y] : (groupMinusChar y) : (otherGroups y nt), d) @@ -53,7 +58,12 @@ hurt x y (nt,d) -- Attract X and Y (only if adjacent) attract :: MainCharacter -> MainCharacter -> BoardState -> BoardState -attract x y (nt,d) +attract x y (nt,d) | not $ y `elem` (getAdj x nt) = (nt,d) + | otherwise = attract' x y (nt'd) + +-- Attract X and Y (no restrictions) +attract' :: MainCharacter -> MainCharacter -> BoardState -> BoardState +attract' x y (nt,d) | x `elem` d = (nt, (filter (/= x) d)) | otherwise = ((uniq (charsGroup x nt ++ charsGroup y nt)) : (otherGroups y (otherGroups x nt)), d)