2019-05-15 02:16:17 -04:00
|
|
|
module Groups where
|
|
|
|
|
2019-05-15 02:50:27 -04:00
|
|
|
import State
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- Each characters default adjacents
|
2019-05-14 23:53:15 -04:00
|
|
|
defFrens :: MainCharacter -> [MainCharacter]
|
|
|
|
defFrens Asuka = [Rei, Shinji, Misato]
|
|
|
|
defFrens Shinji = [Rei, Gendo, Ritsuko, Misato, Asuka]
|
|
|
|
defFrens Rei = [Gendo, Shinji, Asuka]
|
|
|
|
defFrens Misato = [Asuka, Shinji, Ritsuko]
|
|
|
|
defFrens Ritsuko = [Misato, Shinji, Gendo]
|
|
|
|
defFrens Gendo = [Rei, Shinji, Ritsuko]
|
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- The group that character x belongs to
|
2019-05-14 23:53:15 -04:00
|
|
|
charsGroup :: MainCharacter -> NeoTokyo -> Group
|
2019-05-15 00:48:51 -04:00
|
|
|
charsGroup x nt = head $ filter (\g -> x `elem` g) nt
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- The characters currently grouped with x
|
2019-05-14 23:53:15 -04:00
|
|
|
curFrens :: MainCharacter -> NeoTokyo -> [MainCharacter]
|
|
|
|
curFrens x nt = filter (/= x) $ charsGroup x nt
|
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- Remove duplicates, stabily
|
2019-05-15 00:48:51 -04:00
|
|
|
uniq :: (Eq a) => [a] -> [a]
|
2019-05-15 02:14:32 -04:00
|
|
|
uniq x = reverse $ go x []
|
2019-05-15 00:48:51 -04:00
|
|
|
where
|
|
|
|
go [] al = al
|
|
|
|
go (c:cs) al = if (c `elem` al) then (go cs al) else (go cs (c:al))
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- The groups a character is adaject to
|
2019-05-14 23:53:15 -04:00
|
|
|
adjGroups :: MainCharacter -> NeoTokyo -> [Group]
|
2019-05-15 00:48:51 -04:00
|
|
|
adjGroups x nt = filter (\g -> any (\x -> x `elem` adjFrens) g) (otherGroups x nt)
|
2019-05-14 23:53:15 -04:00
|
|
|
where
|
2019-05-15 02:07:34 -04:00
|
|
|
adjFrens = uniq $ foldr (++) [] (map defFrens $ charsGroup x nt)
|
2019-05-15 00:48:51 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- The groups a character isnt in
|
2019-05-15 00:48:51 -04:00
|
|
|
otherGroups :: MainCharacter -> NeoTokyo -> [Group]
|
|
|
|
otherGroups x nt = filter (\g -> not $ x `elem` g) nt
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- All characters a X is adjacent to
|
2019-05-14 23:53:15 -04:00
|
|
|
getAdj :: MainCharacter -> NeoTokyo -> [MainCharacter]
|
2019-05-15 00:48:51 -04:00
|
|
|
getAdj x nt = curFrens x nt ++ (foldr (++) [] (adjGroups x nt))
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- Hurt character x
|
2019-05-15 02:46:48 -04:00
|
|
|
hurt :: MainCharacter -> BoardState -> BoardState
|
|
|
|
hurt x (nt,d)
|
|
|
|
| x `elem` d = if (curFrens x nt == [])
|
|
|
|
then (nt, d)
|
|
|
|
else ([x] : (groupMinusChar x) : (otherGroups x nt), d)
|
|
|
|
| otherwise = (nt, x:d)
|
|
|
|
where
|
|
|
|
groupMinusChar x = (filter (/= x) $ charsGroup x nt)
|
2019-05-14 23:53:15 -04:00
|
|
|
|
2019-05-15 02:14:32 -04:00
|
|
|
-- Attract X and Y
|
2019-05-15 02:46:48 -04:00
|
|
|
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)
|