evac/Main.hs

45 lines
1.5 KiB
Haskell
Raw Normal View History

2019-05-15 00:48:51 -04:00
import Data.List
type Group = [MainCharacter]
type NeoTokyo = [Group]
2019-05-14 23:53:15 -04:00
data MainCharacter = Asuka | Shinji | Rei | Misato | Ritsuko | Gendo
2019-05-15 00:48:51 -04:00
deriving (Show, Eq)
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]
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
curFrens :: MainCharacter -> NeoTokyo -> [MainCharacter]
curFrens x nt = filter (/= x) $ charsGroup x nt
2019-05-15 00:48:51 -04:00
uniq :: (Eq a) => [a] -> [a]
uniq x = go x []
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
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 00:48:51 -04:00
adjFrens = uniq $ foldr (++) [] (map defFrens $ curFrens x nt)
otherGroups :: MainCharacter -> NeoTokyo -> [Group]
otherGroups x nt = filter (\g -> not $ x `elem` g) nt
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
hurt :: MainCharacter -> NeoTokyo -> NeoTokyo
2019-05-15 00:48:51 -04:00
hurt x nt = [x] : (filter (/= x) $ charsGroup x nt) : (otherGroups x nt)
2019-05-14 23:53:15 -04:00
2019-05-15 00:48:51 -04:00
attract :: MainCharacter -> MainCharacter -> NeoTokyo -> NeoTokyo
attract x y nt = (uniq (charsGroup x nt ++ charsGroup y nt)) : (otherGroups y (otherGroups x nt))