Professional Documents
Culture Documents
How It Created and Language Used
How It Created and Language Used
Our
project contains 3 classes The Main Class: TictactoeGUIwAI, it contains the JFrame and the
method to initialize the game. Second Class: GUI, this class sets the JButtons into position.
And lastly the Third Class: Logic, it contains the turn conditions, winning conditions, AI
difficulty selection and the AI thinking capabilities the minimax algorithm.
Third Class:
1. Constructor:
a reference to the GUI class to interact with the graphical user interface.
Initializes the Random object for generating random numbers.
Initializes the game board (board), difficulty, and other related variables.
2. turn() Method:
Resets the game board and enables all buttons for a new turn.
Displays a dialog for selecting the difficulty level (Easy, Medium, Hard).
Initializes the first turn randomly.
Updates player and computer labels based on the first turn.
If it's the computer's turn, calls the aiTurn() method.
3. winCondition() Method:
Checks for win conditions (horizontal, vertical, diagonal) for both players.
If a player wins, updates the scores, shows a message, and starts a new turn.
Checks for a draw and starts a new turn if the game is a draw.
4. score() Method:
Updates the scores based on the winner.
Displays a message indicating the winner.
5. aiTurn() Method:
Chooses the appropriate AI difficulty level (easyAI, mediumAI, or hardAI).
Calls the corresponding AI method.
Checks for win conditions after the AI makes a move.
6. easyAI() Method:
Randomly selects an empty button and makes a move.
7. hardAI() Method:
Uses the minimax algorithm to determine the best move for the computer.
Calls the minimax() method.
8. minimax() Method:
Determines the best move for the computer using the minimax algorithm.
Calls the minimaxHelper() method.
9. minimaxHelper() Method:
Recursively evaluates the game state and assigns a score.
The algorithm explores possible future moves and assigns scores.
Determines the best move based on the calculated scores.
10.isGameFinished(), hasContestantWon(), isBoardFull() Methods:
Helper methods for checking the game state.
isGameFinished() checks if the game is finished.
hasContestantWon() checks if a player with the given symbol has won.
isBoardFull() checks if the game board is full.
This Logic class encapsulates the game logic, including player turns, win conditions, AI
moves, and scoring. It uses a mix of random moves for the easy difficulty level and a
minimax algorithm for the hard difficulty level.
The Language we used for our project is Java, especially since we have prior experience on
creating a simple board game so its relatively easy for us to code the game.