Skip to content

faafal/tic-tac-toe-ai

Repository files navigation

Tic-Tac-Toe-AI (Java)

A pattern-driven console game engine featuring an unbeatable AI player powered by the Minimax algorithm.

Project Description

The system is built with a focus on clean separation of concerns and architectural scalability. By utilizing the Strategy Pattern, the game engine fully decouples the execution of game loops from the underlying player types (Human vs. various AI implementations). This allows for seamless extensibility when introducing new behaviors or automation layers.

The core highlight of the project is the Hard AI player, which implements the Minimax Algorithm. The algorithm recursively evaluates the entire state tree of the game matrix to guarantee mathematically optimal moves, making the highest difficulty layer completely unbeatable.

Key Features

Strategy Pattern & AI Difficulty Levels [Logic]

The application supports multiple gameplay modes (Human vs. Human, Human vs. AI, and AI vs. AI) driven by a dynamic player injection mechanism.

Available AI Strategies:

  • EASY: Executes completely random legal moves across the board grid.
  • MEDIUM: Evaluates immediate state changes; prioritizes blocking an opponent's winning vector or executing its own winning move in a single step.
  • HARD: Leverages the Minimax Algorithm to simulate all possible outcomes, ensuring a perfect game strategy.

Installation & Building

Required JDK 21 version

Windows

.\mvnw.cmd clean package

Linux / macOS

./mvnw clean package

Running the Application

The system compiles into an executable shaded JAR containing all structural classes.

java -jar target/Tic_Tac_Toe_with_AI-1.0.jar

Quality Assurance & Static Analysis

The project is 100% compliant with Google's coding standards. Every class and method is fully documented using Javadoc.

Checkstyle Report

PMD & CPD (Static Analysis)

The codebase undergoes strict static code analysis to eliminate redundancies, unused variables, and logical anti-patterns.

PMD

SpotBugs

Bytecode analysis confirms the absence of hidden bugs, multi-threading vulnerabilities, or null pointer execution risks.

SpotBugs

About

Console-based Tic-Tac-Toe game featuring an unbeatable AI player powered by the Minimax algorithm alongside customizable strategy difficulty layers.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages