move makeMove to Game
This commit is contained in:
parent
989f2d7af4
commit
c49b5b2540
3 changed files with 16 additions and 9 deletions
15
src/Game.hs
15
src/Game.hs
|
|
@ -1 +1,16 @@
|
|||
module Game where
|
||||
|
||||
import Optics
|
||||
import Types.BoardAction
|
||||
import Types.GameBoard
|
||||
import Types.GameMode
|
||||
import Types.GameState
|
||||
|
||||
makeMove :: (GameMode mode) => PlayerIndex -> BoardAction -> GameState mode -> GameState mode
|
||||
makeMove (MkPlayerIndex idx) (SelectSquare topLeft bottomRight) state@MkGameState{board} =
|
||||
let tiles = select topLeft bottomRight board
|
||||
gMode = gameMode board
|
||||
in if check gMode tiles
|
||||
then
|
||||
over (#players % (ix idx) % #score) (+ 1) state
|
||||
else state
|
||||
|
|
|
|||
|
|
@ -26,12 +26,3 @@ newGame gmode playerInfos rng =
|
|||
let (initialBoard, nextRng) = newRandomBoard gmode 10 10 rng
|
||||
playerStates = S.fromList $ map (\n -> MkPlayerState{name = n, score = 0}) playerInfos
|
||||
in (MkGameState initialBoard playerStates, nextRng)
|
||||
|
||||
makeMove :: (GameMode mode) => PlayerIndex -> BoardAction -> GameState mode -> GameState mode
|
||||
makeMove (MkPlayerIndex idx) (SelectSquare topLeft bottomRight) state@MkGameState{board} =
|
||||
let tiles = select topLeft bottomRight board
|
||||
gMode = gameMode board
|
||||
in if check gMode tiles
|
||||
then
|
||||
over (#players % (ix idx) % #score) (+ 1) state
|
||||
else state
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module Spec where
|
|||
import Data.Array (array, elems)
|
||||
import Data.Sequence qualified as S
|
||||
import Display (displayText)
|
||||
import Game
|
||||
import Optics
|
||||
import Test.Hspec
|
||||
import Types.BoardAction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue