From 3b5047961277888ccd2762bdd2045d2d0e27985e Mon Sep 17 00:00:00 2001 From: Tissevert Date: Thu, 22 Aug 2019 17:37:01 +0200 Subject: [PATCH] =?UTF-8?q?Add=20a=20notion=20of=20=C2=ABdistance=20to=20a?= =?UTF-8?q?=20Yaku=C2=BB=20that=20will=20be=20useful=20to=20Hannah?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Hanafuda/KoiKoi/Yaku.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Hanafuda/KoiKoi/Yaku.hs b/src/Hanafuda/KoiKoi/Yaku.hs index e8b5502..85a1b02 100644 --- a/src/Hanafuda/KoiKoi/Yaku.hs +++ b/src/Hanafuda/KoiKoi/Yaku.hs @@ -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