fix moveToSkat
This commit is contained in:
+10
-5
@@ -110,13 +110,18 @@ playCard :: HasCard c => Hand -> c -> Piles -> Piles
|
|||||||
playCard hand card' ps = (removeFromHand hand card ps) { _table = (CardS card (P hand)) : _table ps }
|
playCard hand card' ps = (removeFromHand hand card ps) { _table = (CardS card (P hand)) : _table ps }
|
||||||
where card = toCard card'
|
where card = toCard card'
|
||||||
|
|
||||||
moveToSkat :: HasCard c => Hand -> [c] -> Piles -> Piles
|
moveToSkat :: HasCard c => Hand -> [c] -> Piles -> Maybe Piles
|
||||||
moveToSkat hand cards' piles = removed { _skat = newSkat }
|
moveToSkat hand cards' piles
|
||||||
|
| length cards' == 2 && all (`elem` possible) cards =
|
||||||
|
Just $ updated { _skat = newSkat }
|
||||||
|
| otherwise = Nothing
|
||||||
where cards = map toCard cards'
|
where cards = map toCard cards'
|
||||||
skat = skatCards piles
|
oldSkat = skatCards piles
|
||||||
notSkatYet = filter (not . (`elem` skat)) cards
|
noLongerSkat = filter (not . (`elem` cards)) oldSkat
|
||||||
newSkat = map (putAt S) $ skat ++ notSkatYet
|
possible = map toCard (handCards hand piles) ++ oldSkat
|
||||||
|
newSkat = map (putAt S) cards
|
||||||
removed = foldr (\card ps -> removeFromHand hand card ps) piles cards
|
removed = foldr (\card ps -> removeFromHand hand card ps) piles cards
|
||||||
|
updated = foldr (\card ps -> addToHand hand card ps) removed noLongerSkat
|
||||||
|
|
||||||
unplayCard :: Hand -> Card -> Team -> Piles -> Piles
|
unplayCard :: Hand -> Card -> Team -> Piles -> Piles
|
||||||
unplayCard hand card winner ps
|
unplayCard hand card winner ps
|
||||||
|
|||||||
Reference in New Issue
Block a user