Skip to content

Os14you/Tic-Tac-Toe-with-agent-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Tic-Tac-Toe with Minimax AI

This is a classic Tic-Tac-Toe game built in modern C++ with a clean, object-oriented design. It features a challenging AI opponent that uses the Minimax algorithm to ensure it never loses. The game is played entirely in the console.

Features

  • Multiple Game Modes:
    • Human vs. AI: Test your skills against an unbeatable AI.
    • Human vs. Human: Play with a friend on the same machine.
    • AI vs. AI: Watch two AI players battle it out.
  • Unbeatable AI: The AI opponent uses the Minimax algorithm to determine the optimal move in any situation.
  • Clean Codebase: The project is structured with a clear separation of concerns, using modern C++ practices like smart pointers and classes for the Game, Board, and Players.
  • Easy to Build: Comes with a pre-configured VS Code build task for one-click compilation.

Project Structure

The project uses a standard and clean directory layout to keep the codebase organized:

.
├── build/              # Compiled output goes here
├── include/            # Header files (.hpp)
│   ├── Board.hpp
│   ├── Game.hpp
│   └── Player.hpp
├── src/                # Source files (.cpp)
│   ├── Board.cpp
│   ├── Game.cpp
│   ├── main.cpp
│   └── Player.cpp
├── .gitignore          # Files to be ignored by Git
└── README.md           # This file

Getting Started

Prerequisites To build and run this project, you will need a C++ compiler that supports the C++17 standard (like g++).

  • g++ compiler: Can be installed on Linux with sudo apt-get install build-essential or on Windows via MinGW/MSYS2.

Building the Project

With VS Code (Recommended) Step by step:

  1. Open the project folder in Visual Studio Code.
  2. Press Ctrl+Shift+B (or Cmd+Shift+B on Mac) to run the default build task.
  3. The compiled executable will be created at build/game.

Manually from the Terminal Navigate to the root directory of the project and run the following command:

g++ -std=c++17 -Iinclude src/*.cpp -o build/game

Running the Game

After building the project, you can run the game from the root directory with this command:

./build/game

You will be greeted with the main menu where you can select your desired game mode.

A Note on Code Comments

Note: All of the explanatory comments within the source code for this project were generated by an AI assistant. While they aim to be accurate and helpful, there is a possibility of error. If you find a comment that is incorrect, unclear, or misleading, please feel free to open an issue in the repository to report it. Your feedback is appreciated!

License

This project is currently unlicensed. Feel free to use and modify the code as you see fit.

About

This is a simple game using minmax algorithm to create an agent to play against human in Tic-Tac-Toe game

Resources

License

Stars

Watchers

Forks

Packages

No packages published