From 18aa516905fe8274ef675a443ff59f011b154a13 Mon Sep 17 00:00:00 2001 From: flavis Date: Sun, 29 Mar 2020 16:01:57 +0200 Subject: [PATCH] fix moveToSkat --- src/Skat/Pile.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Skat/Pile.hs b/src/Skat/Pile.hs index 981d481..d7a97d7 100644 --- a/src/Skat/Pile.hs +++ b/src/Skat/Pile.hs @@ -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 } where card = toCard card' -moveToSkat :: HasCard c => Hand -> [c] -> Piles -> Piles -moveToSkat hand cards' piles = removed { _skat = newSkat } +moveToSkat :: HasCard c => Hand -> [c] -> Piles -> Maybe Piles +moveToSkat hand cards' piles + | length cards' == 2 && all (`elem` possible) cards = + Just $ updated { _skat = newSkat } + | otherwise = Nothing where cards = map toCard cards' - skat = skatCards piles - notSkatYet = filter (not . (`elem` skat)) cards - newSkat = map (putAt S) $ skat ++ notSkatYet + oldSkat = skatCards piles + noLongerSkat = filter (not . (`elem` cards)) oldSkat + possible = map toCard (handCards hand piles) ++ oldSkat + newSkat = map (putAt S) 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 winner ps