move makeMove to Game

This commit is contained in:
Sidharth Kulkarni 2026-05-09 20:14:41 -07:00
parent 989f2d7af4
commit c49b5b2540
Signed by: skulk
SSH key fingerprint: SHA256:Jby+S9d1WmwqnXIrngHgccYNHz+cYquxN1zm3ym3Kbg
3 changed files with 16 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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