Skip to content

Commit

Permalink
Merge pull request #108 from Carleton-Team-Koala/sunny
Browse files Browse the repository at this point in the history
last fixes
  • Loading branch information
shkim2001 authored Nov 21, 2023
2 parents 564b241 + 9c988c2 commit becef4b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
4 changes: 3 additions & 1 deletion app/backend/pkg/models/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func (app *App) UpdateGameState(gameID string, playerMove []Move, playerName str
return nil, err
}

tempGame := loadedGame

if loadedGame.GameOver {
return nil, errors.New("this game is already over")
}
Expand All @@ -199,7 +201,7 @@ func (app *App) UpdateGameState(gameID string, playerMove []Move, playerName str
}

// Get score for entered word
wordScore, err := app.LanguageClient.scoring(*loadedGame, playerMove)
wordScore, err := app.LanguageClient.scoring(*tempGame, *loadedGame, playerMove)
if err != nil {
return nil, err
}
Expand Down
13 changes: 2 additions & 11 deletions app/backend/pkg/models/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m MoveSlice) Swap(i, j int) {
// It takes the activeGame, which represents the current state of the game,
// and newTiles, which represents the tiles being placed in the move.
// It returns the calculated score and an error if any invalid conditions are encountered.
func (c *LanguageClient) scoring(activeGame Game, newTiles MoveSlice) (int, error) {
func (c *LanguageClient) scoring(tempGame Game, activeGame Game, newTiles MoveSlice) (int, error) {
//.Println("activeGame: ", activeGame, "newTiles: ", newTiles)

isFirstMove := isFirstMove(activeGame, newTiles)
Expand All @@ -52,7 +52,7 @@ func (c *LanguageClient) scoring(activeGame Game, newTiles MoveSlice) (int, erro

sort.Sort(newTiles)

adjacentToPlacedTile := TestAdjacentToPlacedTile(activeGame, newTiles)
adjacentToPlacedTile := TestAdjacentToPlacedTile(tempGame, newTiles)
if !adjacentToPlacedTile {
return 0, errors.New("at least one new tile must be adjacent to an already placed tile")
}
Expand Down Expand Up @@ -325,15 +325,6 @@ func TestAdjacentToPlacedTile(activeGame Game, newTiles MoveSlice) bool {
// Check if at least one new tile is adjacent to an already placed tile.
for _, tile := range newTiles {
row, col := tile.Col, tile.Row
fmt.Println("row: ", row, "col: ", col)
fmt.Println("tile: ", tile)

fmt.Println("up, ", activeGame.Board[row-1][col])
fmt.Println("down, ", activeGame.Board[row+1][col])
fmt.Println("left, ", activeGame.Board[row][col-1])
fmt.Println("right, ", activeGame.Board[row][col+1])

fmt.Println("CHECKING")

if row-1 >= 0 {
if activeGame.Board[row-1][col] != "" && !containsTile(newTiles, row-1, col) {
Expand Down
8 changes: 4 additions & 4 deletions app/backend/pkg/models/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type Move struct {

type SkipTurnResp struct {
CurrentPlayer string `json:"CurrentPlayer"`
Message string `json:"message"`
Message string `json:"message"`
}

type RefreshResp struct {
CurrentPlayer string `json:"CurrentPlayer"`
NewHand []string `json:"hand"`
}
CurrentPlayer string `json:"CurrentPlayer"`
NewHand []string `json:"hand"`
}
5 changes: 5 additions & 0 deletions frontend/src/pages/Welcome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function createGame() {
const url = baseURL + "newgame/";
const player = sessionStorage.getItem('playerName');

if (!player) {
alert("Player name is missing.");
return null; // Exit the function if the necessary data is missing
}

// Return the fetch promise
return fetch(url, {
method: "POST",
Expand Down

0 comments on commit becef4b

Please sign in to comment.