Untitled
unknown
haskell
4 years ago
752 B
5
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...