Added ES2ES movement
This commit is contained in:
parent
d63cb53b45
commit
b7a538e302
1 changed files with 41 additions and 22 deletions
|
@ -162,6 +162,9 @@ canFinishOn cs index ((t2,v2,_):_) = sameType && succValue && visibility
|
|||
succValue = v1 == succ v2
|
||||
visibility = vis == Visible
|
||||
|
||||
-- Here is still room for improvement:
|
||||
-- Combine these functions into a single function?
|
||||
|
||||
-- Move from one gameStack to another.
|
||||
moveGS2GS :: Coordinate -> Int -> Board -> Board
|
||||
moveGS2GS fromCoord toStackNr board
|
||||
|
@ -178,6 +181,7 @@ moveGS2GS fromCoord toStackNr board
|
|||
tempGS = switchStack oldGS fromStackNr (showFirst newFrom)
|
||||
newGS = switchStack tempGS toStackNr newTo
|
||||
newBoard = board{ gameStacks = newGS }
|
||||
|
||||
-- Move from a gameStack to an endingStack.
|
||||
moveGS2ES :: Coordinate -> Int -> Board -> Board
|
||||
moveGS2ES fromCoord toIndex board
|
||||
|
@ -194,19 +198,6 @@ moveGS2ES fromCoord toIndex board
|
|||
newES = switchStack oldES toIndex newESStack
|
||||
newBoard = board{ endingStacks = newES, gameStacks = newGS }
|
||||
|
||||
-- Move a card between pile and endingStacks.
|
||||
moveP2ES :: Coordinate -> Int -> Board -> Board
|
||||
moveP2ES _ toIndex board
|
||||
| canFinishOn oldPile 0 to = newBoard
|
||||
| otherwise = board
|
||||
where oldPile = pile board
|
||||
oldES = endingStacks board
|
||||
to = oldES !! toIndex
|
||||
(card:newPile) = oldPile
|
||||
newESStack = card:to
|
||||
newES = switchStack oldES toIndex newESStack
|
||||
newBoard = board{ pile = newPile, endingStacks = newES }
|
||||
|
||||
-- Move a card between pile and gameStacks.
|
||||
moveP2GS :: Coordinate -> Int -> Board -> Board
|
||||
moveP2GS _ toStackNr board
|
||||
|
@ -220,11 +211,24 @@ moveP2GS _ toStackNr board
|
|||
newGS = switchStack oldGS toStackNr newGSStack
|
||||
newBoard = board{ gameStacks = newGS, pile = newPile }
|
||||
|
||||
-- Move a card between pile and endingStacks.
|
||||
moveP2ES :: Coordinate -> Int -> Board -> Board
|
||||
moveP2ES _ toIndex board
|
||||
| canFinishOn oldPile 0 to = newBoard
|
||||
| otherwise = board
|
||||
where oldPile = pile board
|
||||
oldES = endingStacks board
|
||||
to = oldES !! toIndex
|
||||
(card:newPile) = oldPile
|
||||
newESStack = card:to
|
||||
newES = switchStack oldES toIndex newESStack
|
||||
newBoard = board{ pile = newPile, endingStacks = newES }
|
||||
|
||||
-- Move a card from an endingStack to a gameStack.
|
||||
moveES2GS :: Coordinate -> Int -> Board -> Board
|
||||
moveES2GS fromCoord toStackNr board
|
||||
| canPlayOn from 0 to = newBoard
|
||||
| otherwise = board
|
||||
| otherwise = board
|
||||
where (tempIndex, _) = fromCoord
|
||||
fromIndex = tempIndex - (amountOfGameStacks - amountOfEndingStacks)
|
||||
oldES = endingStacks board
|
||||
|
@ -237,6 +241,20 @@ moveES2GS fromCoord toStackNr board
|
|||
newGS = switchStack oldGS toStackNr newGSStack
|
||||
newBoard = board{ gameStacks = newGS, endingStacks = newES }
|
||||
|
||||
-- Move from one endingStack to another.
|
||||
moveES2ES :: Coordinate -> Int -> Board -> Board
|
||||
moveES2ES fromCoord toIndex board
|
||||
| canFinishOn from 0 to = newBoard
|
||||
| otherwise = board
|
||||
where (tempIndex, _) = fromCoord
|
||||
fromIndex = tempIndex - (amountOfGameStacks - amountOfEndingStacks)
|
||||
oldES = endingStacks board
|
||||
from = oldES !! fromIndex
|
||||
to = oldES !! toIndex
|
||||
(card:newESStack) = from
|
||||
tempES = switchStack oldES fromIndex newESStack
|
||||
newES = switchStack tempES toIndex (card:to)
|
||||
newBoard = board{ endingStacks = newES }
|
||||
|
||||
-- Switch a stack for another stack in a list of stacks.
|
||||
switchStack :: [Stack] -> Int -> Stack -> [Stack]
|
||||
|
@ -252,13 +270,14 @@ getStackFromZone game GS index = gameStacks (board game) !! index
|
|||
getStackFromZone _ Out _ = []
|
||||
|
||||
-- Move between to zones with two indexes
|
||||
getMoveFunction2 :: Zone -> Zone -> Coordinate -> Int -> Board -> Board
|
||||
getMoveFunction2 Pile ES coord index = moveP2ES coord index
|
||||
getMoveFunction2 Pile GS coord index = moveP2GS coord index
|
||||
getMoveFunction2 GS GS coord index = moveGS2GS coord index
|
||||
getMoveFunction2 GS ES coord index = moveGS2ES coord index
|
||||
getMoveFunction2 ES GS coord index = moveES2GS coord index
|
||||
getMoveFunction2 _ _ _ _ = id
|
||||
getMoveFunction :: Zone -> Zone -> Coordinate -> Int -> Board -> Board
|
||||
getMoveFunction Pile ES coord index = moveP2ES coord index
|
||||
getMoveFunction Pile GS coord index = moveP2GS coord index
|
||||
getMoveFunction GS GS coord index = moveGS2GS coord index
|
||||
getMoveFunction GS ES coord index = moveGS2ES coord index
|
||||
getMoveFunction ES GS coord index = moveES2GS coord index
|
||||
getMoveFunction ES ES coord index = moveES2ES coord index
|
||||
getMoveFunction _ _ _ _ = id
|
||||
|
||||
-- Tranform the index based on the zone.
|
||||
transformIndex :: Zone -> Int -> Int
|
||||
|
@ -277,7 +296,7 @@ moveCard game fromCoord toCoord = game{ board = newBoard }
|
|||
toZone = getZoneFromCoord game toCoord
|
||||
fromStack = getStackFromZone game fromZone x
|
||||
toStack = getStackFromZone game toZone x
|
||||
moveFunction = getMoveFunction2 fromZone toZone fromCoord properIndex
|
||||
moveFunction = getMoveFunction fromZone toZone fromCoord properIndex
|
||||
newBoard = moveFunction originalBoard
|
||||
|
||||
------------------------------ Input ---------------------------------
|
||||
|
|
Reference in a new issue