Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Nov 12, 2023
1 parent b6e06d9 commit 9aed042
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 42 deletions.
23 changes: 12 additions & 11 deletions public/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
--col-bg: #1d1d1a;
--col-text: #feffff;
--col-primary: #fec53c;
--col-secondary: #eaeaea;
--col-secondary: #c5e4ff;
--col-placed-tile: #fff;
--col-cell: #2d2d2d;
--col-success: #84ff7a;
--grid-size: 14;
Expand Down Expand Up @@ -159,7 +160,7 @@ dialog > form {
text-align: center;
font-size: 35px;
line-height: var(--cell-size);
background-color: var(--col-secondary);
background-color: var(--col-placed-tile);
color: var(--col-bg);
border-radius: var(--tile-border-radius);
font-family: Georgia, 'Times New Roman', Times, serif;
Expand All @@ -185,6 +186,14 @@ dialog > form {
animation-fill-mode: forwards;
}

.just-placed-tile {
color: #0053be;
}

.just-placed-tile-text {
color: #58a1ff;
}

.tile-value {
position: absolute;
font-size: 1rem;
Expand Down Expand Up @@ -238,19 +247,11 @@ dialog > form {
}

.bottom-action-buttons > button {
font-size: 2em;
font-size: 1.8em;
font-family: Consolas, monospace;
padding: 8px 12px;
/* border-radius: 24px; */
/* border: 2px solid #fff; */
/* background-color: transparent; */
/* color: var(--col-primary) */
}

.text-col-primary {
color: var(--col-primary);
}

/* .bottom-action-buttons > button:disabled {
color: #fff;
} */
2 changes: 1 addition & 1 deletion src/Checker.elm
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ scoreLine wordlist line =
( mult, Preview tile ) ->
Just { tile = tile, isPreview = True, multiplier = mult }

( mult, Placed tile ) ->
( mult, Placed { tile } ) ->
Just { tile = tile, isPreview = False, multiplier = mult }

_ ->
Expand Down
20 changes: 16 additions & 4 deletions src/Data.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Data exposing (CellContents(..), CellProps, CellSelection(..), Multiplier, PlayedTurn(..), RackState, RackTile, SelectDirection(..), Tile, Tiles, getAllCellContents, isRackReset, playedTurnToRackState, resetRackState, shuffleRack, swapDirection)
module Data exposing (CellContents(..), CellProps, CellSelection(..), Multiplier, Placement, PlayedTurn(..), RackState, RackTile, SelectDirection(..), Tile, Tiles, getAllCellContents, isRackReset, playedTurnToRackState, resetRackState, shuffleRack, swapDirection)

import Array exposing (Array)
import Array.Extra
Expand Down Expand Up @@ -30,7 +30,7 @@ type CellSelection
type CellContents
= Empty
| Preview Tile
| Placed Tile
| Placed { tile : Tile, justPlaced : Bool }


type alias Multiplier =
Expand Down Expand Up @@ -68,7 +68,15 @@ getAllCellContents model =
let
initialBoard =
model.board
|> Array2D.map (Maybe.map Placed >> Maybe.withDefault Empty)
|> Array2D.map
(\c ->
case c of
Nothing ->
Empty

Just tile ->
Placed { tile = tile, justPlaced = False }
)
in
Array.foldl
(\previewTile board ->
Expand All @@ -83,8 +91,12 @@ getAllCellContents model =
model.rack


type alias Placement =
{ rackIndex : Int, position : Point }


type PlayedTurn
= PlayedTurn (List { rackIndex : Int, position : Point })
= PlayedTurn (List Placement)


playedTurnToRackState : PlayedTurn -> Array Tile -> RackState
Expand Down
59 changes: 33 additions & 26 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Model
type alias PlayingModel =
{ selectedCell : Maybe Point
, selectDirection : SelectDirection
, board : Tiles
, board : PostTurnBoardState
, bag : List Tile
, rack : RackState
, opponent :
Expand All @@ -84,8 +84,12 @@ type alias PostTurnPlayerState =
}


type alias PostTurnBoardState =
Array2D (Maybe { placedTurn : Int, tile : Tile })


type alias PostTurnGameState =
{ board : Tiles
{ board : PostTurnBoardState
, nextPlayer : PostTurnPlayerState
, lastPlayer : PostTurnPlayerState
, bag : List Tile
Expand All @@ -108,7 +112,7 @@ getCellContents : PlayingModel -> Point -> CellContents
getCellContents model point =
case model.board |> Array2D.get point.x point.y of
Just (Just tile) ->
Placed tile
Placed { tile = tile.tile, justPlaced = tile.placedTurn == List.length model.playedTurns - 1 }

_ ->
let
Expand All @@ -126,7 +130,7 @@ getCellContents model point =
Empty


initialBoard : Tiles
initialBoard : PostTurnBoardState
initialBoard =
Array2D.repeat gridSize gridSize Nothing

Expand Down Expand Up @@ -338,13 +342,17 @@ getInitialGameState seed0 =
getNextGameState : Set String -> PlayedTurn -> PostTurnGameState -> PostTurnGameState
getNextGameState wordlist turn state =
let
boardWithPlacement : Data.Placement -> PostTurnBoardState -> PostTurnBoardState
boardWithPlacement placement board =
let
tile =
state.nextPlayer.rack |> Array.get placement.rackIndex
state.nextPlayer.rack |> Array.get placement.rackIndex |> Maybe.withDefault 'A'

newCell =
Just { tile = tile, placedTurn = List.length state.history }
in
board
|> Array2D.set placement.position.x placement.position.y tile
|> Array2D.set placement.position.x placement.position.y newCell
in
case turn of
PlayedTurn placements ->
Expand All @@ -357,7 +365,7 @@ getNextGameState wordlist turn state =

outcome =
getMoveOutcome
{ board = state.board
{ board = state.board |> Array2D.map (Maybe.map .tile)
, rack = checkerRack
, wordlist = wordlist
, bag = state.bag
Expand Down Expand Up @@ -561,7 +569,7 @@ view model =
let
moveOutcome =
getMoveOutcome
{ board = pm.board
{ board = pm.board |> Array2D.map (Maybe.map .tile)
, rack = pm.rack
, wordlist = pm.wordlist
, bag = pm.bag
Expand Down Expand Up @@ -721,7 +729,7 @@ moveSummaryText model outcome =

viewLetter : ScoringCellContents -> Html msg
viewLetter t =
span [ classList [ ( "text-col-primary", t.isPreview ) ] ] [ text (String.fromChar t.tile) ]
span [ classList [ ( "just-placed-tile-text", t.isPreview ) ] ] [ text (String.fromChar t.tile) ]
in
case longestWord of
Just longestWord_ ->
Expand Down Expand Up @@ -825,31 +833,30 @@ viewRackTile disable index tile =
, onClick (PlaceTile index)
, disabled (disable || tile.placement /= Nothing)
]
[ viewTile tile.tile True ]
[ viewTile tile.tile False True ]


viewGrid : Array2D CellProps -> Html Msg
viewGrid cellProps =
let
partialGrid =
div [ class "grid" ]
(cellProps
|> Array2D.indexedMap (\y x p -> viewCell (Point x y) p)
|> Array2D.Extra.flattenToList
)
in
Html.node "scroll-repeat"
[ class "scroll-repeat-view" ]
-- We use a zero-size div to force the xy coords for panzoom to be the top-left of the grid.
[ div [ style "width" "0", style "height" "0" ]
[ div
[ id "super-grid" ]
(List.repeat 9 (viewPartialGrid cellProps))
(List.repeat 9 partialGrid)
]
]


viewPartialGrid : Array2D CellProps -> Html Msg
viewPartialGrid cellProps =
div [ class "grid" ]
(cellProps
|> Array2D.indexedMap (\y x p -> viewCell (Point x y) p)
|> Array2D.Extra.flattenToList
)


getCellProps : PlayingModel -> Point -> CellProps
getCellProps model point =
{ state = getCellState model point
Expand Down Expand Up @@ -918,18 +925,18 @@ viewCell point state =
]
[]

( Placed tile, _ ) ->
viewTile tile False
( Placed { tile, justPlaced }, _ ) ->
viewTile tile justPlaced False

( Preview tile, _ ) ->
viewTile tile True
viewTile tile False True
]


viewTile : Tile -> Bool -> Html msg
viewTile tile isPreview =
viewTile : Tile -> Bool -> Bool -> Html msg
viewTile tile isJustPlaced isPreview =
div
[ classList [ ( "tile", True ), ( "preview-tile", isPreview ) ] ]
[ classList [ ( "tile", True ), ( "preview-tile", isPreview ), ( "just-placed-tile", isJustPlaced ) ] ]
[ div [ class "tile-value " ] [ text (getLetterValue tile |> String.fromInt) ]
, text (String.fromChar tile)
]

0 comments on commit 9aed042

Please sign in to comment.