瀏覽代碼

fix moveToSkat

master
flavis 6 年之前
父節點
當前提交
18aa516905
共有 1 個檔案被更改,包括 10 行新增5 行删除
  1. +10
    -5
      src/Skat/Pile.hs

+ 10
- 5
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


Loading…
取消
儲存