Shuffle is more a CCard thing than something specific to KoiKoi or other Games

This commit is contained in:
Sasha 2018-02-02 17:25:10 +01:00
parent 51436f4eb2
commit 871f1a383f
1 changed files with 12 additions and 0 deletions

View File

@ -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