0% found this document useful (0 votes)
15 views

How It Created and Language Used

This document summarizes a tic-tac-toe game project created using Java and Apache Netbeans IDE. It includes three main classes: 1) TictactoeGUIwAI handles the GUI frame and game initialization. 2) GUI sets up the game board buttons and connects to the logic class. 3) Logic manages game play logic like turns, win conditions, and AI difficulty levels using minimax algorithms.

Uploaded by

Kou Cataraja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

How It Created and Language Used

This document summarizes a tic-tac-toe game project created using Java and Apache Netbeans IDE. It includes three main classes: 1) TictactoeGUIwAI handles the GUI frame and game initialization. 2) GUI sets up the game board buttons and connects to the logic class. 3) Logic manages game play logic like turns, win conditions, and AI difficulty levels using minimax algorithms.

Uploaded by

Kou Cataraja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

We have used Apache Netbeans IDE and it’s several packages to create this project.

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.

Here are the functionalities of each method within the project:


Main Class:
1. TictactoeGUIwAI Class:
 Extends JFrame to create the main frame for the application.
 Contains a reference to the GUI class, which represents the graphical user
interface for the game.
2. showGUIElements() Method:
 Clears the content of the frame (getContentPane().removeAll()).
 Adds the GUI component to the frame's content pane.
 Sets the size of the frame to 355x430 pixels.
 Centers the frame on the screen.
 Calls revalidate() and repaint() to update and repaint the frame.
3. TictactoeGUIwAI Constructor:
 Sets the initial size of the frame to 355x430 pixels.
 Sets the default close operation to exit the application when the frame is closed.
 Prevents frame resizing (setResizable(false)).
 Creates an instance of the GUI class, passing a reference to the current
TictactoeGUIwAI instance.
 Calls the showGUIElements() method to initialize and display the GUI.
 Sets the frame visible.
4. main() Method:
 Creates an instance of the TictactoeGUIwAI class, which initializes and displays
the game.
This class sets up the main frame for the Tic-Tac-Toe game, initializes the graphical user
interface (GUI), and provides a method to update and display GUI elements within the
frame. The main method creates an instance of the application, triggering the initialization
and display of the Tic-Tac-Toe game.
Second Class:
1. GUI Constructor:
 Initializes the GUI for the Tic-Tac-Toe game.
 Sets up labels for player names, scores, and a turn indicator.
 Creates a 3x3 grid of JToggleButtons for the game board.
 Initializes the logic object for game logic.
 Calls logic.turn() to start the game.
2. actionPerformed(ActionEvent e):
 Overrides the actionPerformed method from the ActionListener interface.
 This method is called when a button on the game board is clicked.
 It iterates through the 3x3 grid of buttons to find the button that triggered the
event.
 Updates the button's font, text (either "X" or "O"), and disables the button.
 Sets the corresponding cell in the game logic's board array to the player's
symbol.
 Updates the turn label to indicate the computer's turn.
 Calls logic.winCondition() to check if the player has won.
 Calls logic.aiTurn() to make the computer's move.
3. Other Variables:
 Various JLabels (playerLabel, computerLabel, etc.) are used to display player
names, scores, and turn information.
 A 2D array of JToggleButtons (button) represents the Tic-Tac-Toe game board.
 Fonts (buttonFont and labelFont) are defined for styling.
This class creates a graphical user interface for a Tic-Tac-Toe game and connects it to a
game logic component (Logic class) to handle player moves, check for wins, and allow the
computer to make its moves.

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.

You might also like