From c49b5b25408bb397f27a6b756eb50a3cb1686263 Mon Sep 17 00:00:00 2001 From: Sidharth Kulkarni Date: Sat, 9 May 2026 20:14:41 -0700 Subject: [PATCH] move makeMove to Game --- src/Game.hs | 15 +++++++++++++++ src/Types/GameState.hs | 9 --------- test/Spec.hs | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Game.hs b/src/Game.hs index ca51dc9..fc5b2e2 100644 --- a/src/Game.hs +++ b/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 diff --git a/src/Types/GameState.hs b/src/Types/GameState.hs index a342625..6f70477 100644 --- a/src/Types/GameState.hs +++ b/src/Types/GameState.hs @@ -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 diff --git a/test/Spec.hs b/test/Spec.hs index 6263306..c28518f 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -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