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
1 changed files with 7 additions and 1 deletions

View File

@ -25,11 +25,13 @@ data Yaku =
| TsukiFuda
deriving (Eq, Ord, Read, Show)
type YakuRater = Pack -> Maybe Points
type YakuDistance = Pack -> Int
type Score = M.Map Yaku Points
data YakuFinder = YakuFinder {
yaku :: Yaku
, rater :: YakuRater
, distance :: YakuDistance
}
instance Eq YakuFinder where
@ -62,7 +64,11 @@ moreThan count _ pack =
index :: (Yaku, [Card], (Pack -> YakuRater)) -> YakusByCard
index (yaku, cards, scorer) =
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
finders :: Monthly YakusByCard