This program is a text-based Chess game written in Java. It allows a human player to play chess against the computer using the terminal. The project demonstrates object-oriented design, game state management, move validation, and basic artificial intelligence techniques.
The game supports two AI difficulties:
- EasyAI – makes simple, mostly random legal moves.
- HarderAI – uses a shallow minimax algorithm to choose stronger moves based on material evaluation.
The game ends when a king is captured.
The program is split into several logical components:
- Game Control & Flow – manages turns, input, and win conditions
- Board Representation – stores the chess board and pieces
- Pieces & Move Validation – enforces chess rules
- AI Players – decide moves for the computer
- Display – prints the board to the terminal
- Compile all
.javafiles - Run
A3Main.java - Follow the on-screen prompts to enter moves
Moves are entered using board coordinates (row and column numbers).
This is the starting point of the program. It:
- Creates the game controller
- Selects the display type (text-based)
- Starts the game loop
Running this file launches the chess game in the terminal.
Controls the overall game flow. Responsibilities include:
- Alternating turns between the human player and the AI
- Requesting moves from players
- Passing moves to the game logic
- Detecting when the game is over
Handles all game rules, including:
- Validating moves
- Moving pieces on the board
- Capturing pieces
- Pawn promotion
- Ending the game when a king is captured
This class is the authority on what is legal in the game.
Represents the chess board as an 8×8 grid of Spot objects.
Each Spot represents a single square on the board and contains:
- A row and column
- A reference to the
Pieceoccupying it (ornullif empty)
An abstract base class shared by all chess pieces. It defines:
- Which player the piece belongs to (
whosePiece) - The method
isValidMove(...), which each piece must implement
Each chess piece has its own class that enforces its movement rules:
Pawn.javaRook.javaKnight.javaBishop.javaQueen.javaKing.java
Move validation is handled inside each piece, following object-oriented principles.
Encapsulates a chess move, including:
- Starting row and column
- Destination row and column
- Flags for resignation and pawn promotion
- The piece involved in the move
This allows moves to be passed cleanly between the controller, logic, and AI.
An interface implemented by all player types (human or AI). It defines:
makeMove(...)– returns the next move for that player
The human player provides input through the terminal.
A basic computer opponent that:
- Generates all legal moves
- Chooses one with minimal strategy
This AI is useful for testing and learning the game.
A stronger AI that uses a simple minimax algorithm:
- Searches a few moves ahead
- Assumes the human plays optimally
- Evaluates board positions using material values
This AI provides a more challenging opponent while remaining efficient.
The minimax algorithm:
- Generates all legal moves for the AI
- Simulates each move on a copied board
- Recursively evaluates human replies
- Assigns scores based on material advantage
- Selects the move with the highest score
Piece values used for evaluation:
- Pawn: 100
- Knight: 320
- Bishop: 330
- Rook: 500
- Queen: 900
- King: very large value (game-ending)
The search depth is intentionally shallow to keep the game responsive.
An interface for displaying the board.
A terminal-based implementation that:
- Prints the chess board in ASCII format
- Updates after every move
- Object-oriented design with clear separation of responsibilities
- Encapsulated move validation per piece
- Simple but effective AI using minimax
- Clean board cloning for AI simulations
- Text-based interface for simplicity and portability