Go Fish/Haskell: Difference between revisions

m
Cleanup.
(Fixing formatting from copy after Go Fish pages were branched out)
m (Cleanup.)
Line 2:
If possible, the AI will randomly select a rank known to be in the human's hand (a card in the AI's hand that the human has asked for before and the AI hasn't asked for before). If there are no known ranks, a rank is randomly selected from the AI's hand.
 
<lang haskell>import Char
import Char
import IO
import Data.Map (Map)
Line 105 ⟶ 104:
initialGameState = liftM worker newStdGen
where worker gen =
(GS deck (hand1, S.empty, S.empty) (hand2, S.empty, S.empty))
where (startDeck, _) = shuffle initialDeck gen
(hand1, deckMinusPlayerHand) = drawN 9 M.empty startDeck
Line 132 ⟶ 131:
 
shuffle deck gen = worker gen (length deck) [] deck
where worker g l_ xs [] = (xs, g)
worker g l xs ys = worker newGen (l-1) (card : xs) (delete card ys)
where (index, newGen) = randomR (0,l-1) g
Line 141 ⟶ 140:
drawN n hand deck = iterate (uncurry draw) (hand, deck) !! (n-1)
 
handToCards = concatMap (\(r,ss) -> map (flip (,) r) $ S.toList ss) . M.assocs</lang>
</lang>
Anonymous user