Shuffle is more a CCard thing than something specific to KoiKoi or other Games
This commit is contained in:
parent
51436f4eb2
commit
871f1a383f
12
CCard.hs
12
CCard.hs
|
@ -2,6 +2,7 @@ module CCard where
|
|||
|
||||
import Data.Word (Word64)
|
||||
import Data.Bits (setBit, (.|.), (.&.), shift, xor, testBit)
|
||||
import System.Random (randomRIO)
|
||||
|
||||
data Flower =
|
||||
Pine
|
||||
|
@ -72,3 +73,14 @@ pair card1 card2 = flower card1 == flower card2
|
|||
|
||||
cards :: [Card]
|
||||
cards = [Pine0 .. Phoenix]
|
||||
|
||||
shuffle :: [a] -> IO [a]
|
||||
shuffle l =
|
||||
aux (length l) l
|
||||
where
|
||||
aux n [] = return []
|
||||
aux n (h:t) = do
|
||||
cut <- randomRIO (0, n-1)
|
||||
shuffled <- shuffle t
|
||||
let (top, bottom) = splitAt cut shuffled
|
||||
return $ top ++ h : bottom
|
||||
|
|
Loading…
Reference in New Issue