Add and expose more useful functions on Hanafuda cards and use them in Yakus computations
This commit is contained in:
parent
3b50479612
commit
3615c29a47
2 changed files with 18 additions and 4 deletions
|
@ -5,8 +5,10 @@ module Hanafuda (
|
|||
, Pack
|
||||
, add
|
||||
, cards
|
||||
, cardsOf
|
||||
, cardsOfPack
|
||||
, contains
|
||||
, difference
|
||||
, empty
|
||||
, flower
|
||||
, intersection
|
||||
|
@ -16,6 +18,7 @@ module Hanafuda (
|
|||
, sameMonth
|
||||
, shuffle
|
||||
, size
|
||||
, union
|
||||
) where
|
||||
|
||||
import Data.Word (Word64)
|
||||
|
@ -27,6 +30,7 @@ import Data.Bits (
|
|||
, testBit
|
||||
, xor
|
||||
, (.&.)
|
||||
, (.|.)
|
||||
, countTrailingZeros
|
||||
)
|
||||
import System.Random (randomRIO)
|
||||
|
@ -112,6 +116,12 @@ intersection = portBinary (.&.)
|
|||
difference :: Pack -> Pack -> Pack
|
||||
difference = portBinary (\a b -> a `xor` (a .&. b))
|
||||
|
||||
union :: Pack -> Pack -> Pack
|
||||
union = portBinary (.|.)
|
||||
|
||||
cardsOf :: Flower -> Pack
|
||||
cardsOf = Pack . shift 0xf . (* 4) . fromEnum
|
||||
|
||||
sameMonth :: Card -> Pack -> Pack
|
||||
sameMonth card (Pack p) = Pack $ (0xf `shift` (fromEnum card .&. 0xfc)) .&. p
|
||||
|
||||
|
|
|
@ -6,11 +6,15 @@ module Hanafuda.KoiKoi.Yaku (
|
|||
, sumYakus
|
||||
) where
|
||||
|
||||
import Hanafuda (Card(..), Monthly, Pack, add, contains, intersection, packOfCards, size)
|
||||
import Hanafuda (
|
||||
Card(..), Monthly, Pack
|
||||
, add, cardsOf, cardsOfPack, contains, difference, intersection, packOfCards
|
||||
, size
|
||||
)
|
||||
import Hanafuda.Player (Points)
|
||||
import qualified Data.Map as M (Map, empty, insert, unionWith, (!))
|
||||
import qualified Data.Set as S (Set, empty, singleton, union)
|
||||
import Control.Monad.Reader (reader)
|
||||
import Control.Monad.Reader (asks)
|
||||
|
||||
data Yaku =
|
||||
Lights
|
||||
|
@ -73,7 +77,7 @@ index (yaku, cards, scorer) =
|
|||
|
||||
finders :: Monthly YakusByCard
|
||||
finders = do
|
||||
monthCardPlus <- reader $ (+) . (4*) . fromEnum
|
||||
monthCards <- cardsOfPack <$> asks cardsOf
|
||||
return $ foldl (\yakusByCard -> M.unionWith S.union yakusByCard . index) M.empty [
|
||||
(Lights, [Crane, CampCurtain, FullMoon, RainMan, Phoenix], lights)
|
||||
, (InoShikaCho, inoshikacho, fixed 5)
|
||||
|
@ -84,7 +88,7 @@ finders = do
|
|||
, (Kasu, plains, moreThan 9)
|
||||
, (TsukimiZake, [SakeCup, FullMoon], fixed 3)
|
||||
, (HanamiZake, [SakeCup, CampCurtain], fixed 3)
|
||||
, (TsukiFuda, map (toEnum . monthCardPlus) [0..3], fixed 5)
|
||||
, (TsukiFuda, monthCards, fixed 5)
|
||||
]
|
||||
where
|
||||
inoshikacho = [Butterflies, Boar, Deer]
|
||||
|
|
Loading…
Reference in a new issue