Untitled
Anonymous
haskell
03/18/2021 1:02 PM
1004 B
22
Indexable
data BalanceState = BalanceState{getActions::[Action]
,getBalances::[Difference]
,getWorld::World} deriving (Eq,Show)
instance Ord BalanceState where
compare = compare `on` evaluate'
where
evaluate' st = (dist st,cost st)
dist st = evaluate (getWorld st) (getBalances st)
cost st = totalCost (getWorld st) (getActions st)
evaluate world balances = sum $ map evaluate' balances
where
evaluate' diff = abs $ getAmount diff * getMultiplier diff
getMultiplier diff | isDefaultCurrency diff = 1 / 2
| otherwise = runReader (toDefaultCurrency diff) world
totalCost world = sum . map ((`runReader` world) . getActionCost)
Editor is loading...