Fianl Course Work Oop (GDSE)
Fianl Course Work Oop (GDSE)
Final Examination
Total Marks: 100
1
Tic-Tac-Toe: Championship Edition
You MUST do this assignment individually and, unless otherwise specified, follow all the
general instructions and regulations for assignments. Please read this entire document
before starting.
Warm-up
In this assignment, your knowledge and development skills will be evaluated in the
following areas:
- Programming Fundamentals
- Matrices
- Concrete Classes, Abstract Classes, Interfaces, Nested Classes
- Enumerations
- Encapsulation, Inheritance, Polymorphism, Abstractions
- Java Bean Specification
- Access Modifiers
- Recursion
- UML Class Diagrams
- Simple Artificial Intelligence
Take 20 minutes to recap and refresh your knowledge of these topics before you begin.
Introduction
In this assignment, you will implement the logic behind the Tic-Tac-Toe game, including a
simple Artificial Intelligence for the computer player. If you've never played the game
before, familiarize yourself with it by visiting the following link:
https://en.wikipedia.org/wiki/Tic-Tac-Toe
The goal of the game is to form a horizontal, vertical, or diagonal line of three connected
pieces. We will use a 3x3 grid for this assignment.
The UI logic has been pre-implemented for you using JavaFX. You don't need any UI-related
coding skills for this assignment. The focus is solely on implementing the game logic using
object-oriented programming principles.
2
Step 1: Getting the class hierarchy ready (Marks: 30)
After opening the project in IntelliJ IDEA(or any IDE compatible with Java), you should see a
project structure with compilation errors in the BoardController class. Ignore these for now,
as we will focus on building the class hierarchy first.
3
Key Components:
1. Main:
The Main class contains the main() method, which is the entry point for the
application. It controls the flow of the game, including player turns, reading user
input, and invoking methods to check the game state.
Key Methods:
main(String[] args): Starts the game loop, handling user input and
alternating turns between the human and AI players.
2. Board(Interface):
The Board interface defines the essential methods that any implementation of a Tic-
Tac-Toe board must provide.
3. BoardImpl:
The BoardImpl class represents the Tic-Tac-Toe board and handles game logic,
including validating moves, updating the board state, and checking for a winner.
Attributes:
Key Methods:
4
4. Player (Abstract):
The Player class is an abstract base class for both human and AI players. It defines
the common interface for making moves.
Attributes:
BoardImpl board: The game board on which the player will make moves.
Key Methods:
The HumanPlayer class implements the logic for human players, allowing them to
select a move by specifying a row and column.
Key Methods:
move(int row, int col): Implements the abstract method, placing an X on the
board at the specified location.
The AiPlayer class handles the AI player logic. Initially, the AI chooses moves
randomly. Later, it can be enhanced with algorithms like Minimax.
Attributes:
Key Methods:
move(int row, int col): Selects a random valid move on the board and places
an O in the corresponding location.
7. Piece (Enum):
The Piece enum represents the three possible states of a cell on the board.
Enum Values:
5
• EMPTY: Represents an empty cell.
The idea is to simulate all possible moves for the AI and the human player, alternating turns
between them. The AI will try to maximize its score (maximize its chances of winning),
while the human player is assumed to minimize the AI's score (reduce the chances of AI
winning). The AI evaluates each potential move using a recursive process until it reaches a
terminal state (win, loss, or draw).
Key Concepts:
1. Maximizer (AI): The AI player tries to maximize the score, i.e., tries to win.
6
2. Minimizer (Human): The human player tries to minimize the AI's score by making
moves that reduce the AI's chances of winning.
• The algorithm explores all possible moves, simulating alternating turns between
the human player and the AI.
• For each possible move, simulate the opponent's best response and
backpropagate the results up the game tree.
3. Choose the Best Move
• The AI selects the move that maximizes its chances of winning (the move with
the highest score).
• For each possible move, it simulates the human's response (the "minimizing"
player).
• Then, it evaluates the outcome of the game based on that move, assigning scores:
• +1 for an AI win,
• -1 for a human win,
• 0 for a tie.
• The AI player (maximizer) selects the move that maximizes its chances of winning,
while assuming the human player will choose moves that minimize the AI's chances.
7
General Instructions:
1. Pay attention to the details.
2. You are allowed to use the internet for help, except for directly searching for Minimax
implementations.
3. Include detailed comments, especially on the Minimax algorithm.
4. This assignment is individual.
5. Code only in the com.assignment.tictactoe.service package.
6. You are not allowed to create top-level classes beyond what's outlined here.