Skip to content

Commit

Permalink
Add penalty for leftover tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Dec 10, 2023
1 parent 82fd8de commit f6512d6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -283,7 +280,7 @@ getMoveOutcome :
, wordlist : Set String
, bag : List Tile
, selfScore : Int
, opponentScore : Int
, opponent : PostTurnPlayerState
}
-> MoveOutcome
getMoveOutcome model =
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -577,7 +577,7 @@ view model =
, wordlist = pm.wordlist
, bag = pm.bag
, selfScore = pm.selfScore
, opponentScore = pm.opponent.score
, opponent = pm.opponent
}

cellProps =
Expand Down

0 comments on commit f6512d6

Please sign in to comment.