module Diplomacy.Dislodgement (
Dislodgement
, dislodgementAndOccupation
) where
import qualified Data.Map as M
import Diplomacy.Aligned
import Diplomacy.Unit
import Diplomacy.Zone
import Diplomacy.OrderObject
import Diplomacy.Phase
import Diplomacy.Occupation
import Diplomacy.OrderResolution
type Dislodgement = M.Map Zone (Aligned Unit)
dislodgementAndOccupation
:: M.Map Zone (Aligned Unit, SomeResolved OrderObject Typical)
-> (Dislodgement, Occupation)
dislodgementAndOccupation zonedResolvedOrders = (dislodgement, occupation)
where
currentOccupation :: Occupation
currentOccupation = M.map (\(a, _) -> a) zonedResolvedOrders
moveOccupation :: Occupation
stationaryOccupation :: Occupation
(moveOccupation, stationaryOccupation) = M.foldWithKey nextOccupationFold (M.empty, M.empty) currentOccupation
nextOccupationFold
:: Zone
-> Aligned Unit
-> (Occupation, Occupation)
-> (Occupation, Occupation)
nextOccupationFold zone aunit (move, stationary) = case M.lookup zone zonedResolvedOrders of
Just (_, SomeResolved (MoveObject pt, Nothing)) ->
(M.insert (Zone pt) aunit move, stationary)
_ ->
(move, M.insert zone aunit stationary)
dislodgement :: Dislodgement
dislodgement = stationaryOccupation `M.intersection` moveOccupation
occupation :: Occupation
occupation = moveOccupation `M.union` (stationaryOccupation `M.difference` dislodgement)