From f6512d6a2e422c171025f1c814d9d6f34934ead0 Mon Sep 17 00:00:00 2001 From: Jcparkyn <51850908+Jcparkyn@users.noreply.github.com> Date: Sun, 10 Dec 2023 03:31:19 +0000 Subject: [PATCH] Add penalty for leftover tiles --- src/Main.elm | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 04b44cf..5105553 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,6 +1,7 @@ port module Main exposing (Flags, Model, MoveOutcome, Msg, PlayingModel, PostTurnGameState, PostTurnPlayerState, SubmitDialogState, main) import Array exposing (Array) +import Array.Extra import Array2D exposing (Array2D) import Array2D.Extra import Browser @@ -60,11 +61,7 @@ type alias PlayingModel = , board : PostTurnBoardState , bag : List Tile , rack : RackState - , opponent : - { name : String - , score : Int - , rack : Array Tile - } + , opponent : PostTurnPlayerState , selfName : String , selfScore : Int , playedTurns : List PlayedTurn @@ -283,7 +280,7 @@ getMoveOutcome : , wordlist : Set String , bag : List Tile , selfScore : Int - , opponentScore : Int + , opponent : PostTurnPlayerState } -> MoveOutcome getMoveOutcome model = @@ -301,17 +298,20 @@ getMoveOutcome model = gameOver = List.isEmpty model.bag - && (model.rack |> Array.toList |> List.all (\t -> t.placement /= Nothing)) + && (model.rack |> Array.Extra.all (\t -> t.placement /= Nothing)) - newSelfScore = - model.selfScore + score + leftoverTilesPenalty = + if gameOver then + model.opponent.rack |> Array.toList |> List.map getLetterValue |> List.sum - -- TODO: Subtract tile values - newOpponentScore = - model.opponentScore + else + 0 + + newSelfScore = + model.selfScore + score + leftoverTilesPenalty in { selfScore = newSelfScore - , opponentScore = newOpponentScore + , opponentScore = model.opponent.score , checkerResult = checkerResult , isMoveValid = isMoveValid , gameOver = gameOver @@ -372,7 +372,7 @@ getNextGameState wordlist turn state = , wordlist = wordlist , bag = state.bag , selfScore = state.nextPlayer.score - , opponentScore = state.lastPlayer.score + , opponent = state.lastPlayer } -- TODO: Handle game over @@ -577,7 +577,7 @@ view model = , wordlist = pm.wordlist , bag = pm.bag , selfScore = pm.selfScore - , opponentScore = pm.opponent.score + , opponent = pm.opponent } cellProps =