diff --git a/game/gameloop.go b/game/gameloop.go index cc9c31e..9681add 100644 --- a/game/gameloop.go +++ b/game/gameloop.go @@ -1,7 +1,7 @@ package game import ( - "tictactoe/gamecontrol" + "tictactoe/gameControl" "tictactoe/opponent" "fyne.io/fyne/v2" @@ -79,11 +79,11 @@ func Gameloop(row, col int) { // starting with the human making a move board[row][col] = PLAYER_X // checking if the game has been won by the human player - if gamecontrol.PlayerHasWon(board, PLAYER_X) { + if gameControl.PlayerHasWon(board, PLAYER_X) { TextLabel.SetText("X Wins") } // checking if the game is a draw - if gamecontrol.BoardisFull(board) { + if gameControl.BoardisFull(board) { TextLabel.SetText("Draw") } // AI opponent makes a move @@ -93,12 +93,12 @@ func Gameloop(row, col int) { ChangeButtonText(bestMove.Row, bestMove.Col) // check if AI opponent has won the game - if gamecontrol.PlayerHasWon(board, PLAYER_O) { + if gameControl.PlayerHasWon(board, PLAYER_O) { TextLabel.SetText("O Wins") DisableAllButtons(gridContainer) } // checking if the game is a draw - if gamecontrol.BoardisFull(board) { + if gameControl.BoardisFull(board) { TextLabel.SetText("Draw") } } diff --git a/gameControl/check.go b/gameControl/check.go index 610f04e..6eebd4d 100644 --- a/gameControl/check.go +++ b/gameControl/check.go @@ -1,4 +1,4 @@ -package gamecontrol +package gameControl // checks if a player has won the game func PlayerHasWon(board [3][3]string, player string) bool { diff --git a/opponent/minimax.go b/opponent/minimax.go index ada729f..96a6df6 100644 --- a/opponent/minimax.go +++ b/opponent/minimax.go @@ -2,7 +2,7 @@ package opponent import ( "math" - "tictactoe/gamecontrol" + "tictactoe/gameControl" ) type NextMove struct { @@ -13,12 +13,12 @@ type NextMove struct { // iterative implementation of minimax algorithm func Minimax(board [3][3]string, depth int, isMaximizingPlayer bool, player string) NextMove { - // check if the game has ended - if gamecontrol.PlayerHasWon(board, "X") { + // Evaluate the Board based on who would win the current board + if gameControl.PlayerHasWon(board, "X") { return NextMove{score: -10 + depth} - } else if gamecontrol.PlayerHasWon(board, "O") { + } else if gameControl.PlayerHasWon(board, "O") { return NextMove{score: 10 - depth} - } else if gamecontrol.BoardisFull(board) { + } else if gameControl.BoardisFull(board) { return NextMove{score: 0} } // check who's turn it is