Add a notion of «distance to a Yaku» that will be useful to Hannah

This commit is contained in:
Tissevert 2019-08-22 17:37:01 +02:00
parent 5a89cb4064
commit 3b50479612

View file

@ -25,11 +25,13 @@ data Yaku =
| TsukiFuda | TsukiFuda
deriving (Eq, Ord, Read, Show) deriving (Eq, Ord, Read, Show)
type YakuRater = Pack -> Maybe Points type YakuRater = Pack -> Maybe Points
type YakuDistance = Pack -> Int
type Score = M.Map Yaku Points type Score = M.Map Yaku Points
data YakuFinder = YakuFinder { data YakuFinder = YakuFinder {
yaku :: Yaku yaku :: Yaku
, rater :: YakuRater , rater :: YakuRater
, distance :: YakuDistance
} }
instance Eq YakuFinder where instance Eq YakuFinder where
@ -62,7 +64,11 @@ moreThan count _ pack =
index :: (Yaku, [Card], (Pack -> YakuRater)) -> YakusByCard index :: (Yaku, [Card], (Pack -> YakuRater)) -> YakusByCard
index (yaku, cards, scorer) = index (yaku, cards, scorer) =
let pack = packOfCards cards in let pack = packOfCards cards in
let yakuFinder = YakuFinder {yaku, rater = scorer pack . intersection pack} in let yakuFinder = YakuFinder {
yaku
, rater = scorer pack . intersection pack
, distance = size . difference pack
} in
foldl (\yakusByCard card -> M.insert card (S.singleton yakuFinder) yakusByCard) M.empty cards foldl (\yakusByCard card -> M.insert card (S.singleton yakuFinder) yakusByCard) M.empty cards
finders :: Monthly YakusByCard finders :: Monthly YakusByCard