A classic Tic-Tac-Toe game implementation in C++ with console interface.
- Two-player gameplay - Classic X vs O gameplay
- Input validation - Prevents invalid moves and coordinates
- Win detection - Automatic detection of wins and draws
- Replay option - Play multiple games in succession
- Cross-platform - Works on Windows, Linux, and macOS
- Multiple compilers - Support for g++, Visual Studio, and Embarcadero
Current Board:
0 1 2
+---+---+---+
0 | | X | |
+---+---+---+
1 | O | X | O |
+---+---+---+
2 | | X | |
+---+---+---+
Player X wins!
build.bat
run.batmake
make runThe build script automatically detects your compiler:
build.batSupported compilers (in detection order):
- Embarcadero C++ Builder (
bcc32c) - MinGW/g++ (
g++) - Visual Studio (
cl)
| Compiler | Command |
|---|---|
| g++/MinGW | g++ -std=c++11 -Wall -Wextra -O2 main.cpp TicTacToe.cpp -o tictactoe.exe |
| Embarcadero | bcc32c -std=c++11 -O2 -etictactoe.exe main.cpp TicTacToe.cpp |
| Visual Studio | cl /EHsc /std:c++14 /O2 main.cpp TicTacToe.cpp /Fe:tictactoe.exe |
make # Build the project
make run # Build and run
make clean # Clean build files- The game displays a 3x3 grid with coordinate labels
- Players alternate turns (X goes first)
- Enter coordinates as
row column(e.g.,1 2) - Coordinates range from 0 to 2
- First player to get three in a row wins
- Game detects wins (horizontal, vertical, diagonal) and draws
Player X's turn
Enter row and column (0-2): 1 1
Player O's turn
Enter row and column (0-2): 0 0
Player X's turn
Enter row and column (0-2): 1 2
tic-tac-toe/
├── src/
│ ├── TicTacToe.h # Class declaration
│ ├── TicTacToe.cpp # Game logic implementation
│ └── main.cpp # Entry point
├── build.bat # Windows build script
├── run.bat # Windows run script
├── Makefile # Unix build configuration
└── README.md # This file
- C++11 compatible compiler
- Windows 7+ or Linux or macOS
| Platform | Recommended Compiler | Installation |
|---|---|---|
| Windows | MinGW-w64 | MSYS2 |
| Windows | Visual Studio | VS Community |
| Windows | Embarcadero C++ | RAD Studio |
| Linux | g++ | sudo apt install g++ |
| macOS | clang++ | xcode-select --install |
class TicTacToe {
private:
std::vector<std::vector<char>> board;
char currentPlayer;
bool gameOver;
char winner;
public:
void displayBoard();
bool makeMove(int row, int col);
bool checkWin();
bool checkDraw();
void switchPlayer();
void playGame();
void resetGame();
};displayBoard()- Renders the current game statemakeMove()- Validates and executes player movescheckWin()- Detects winning conditionscheckDraw()- Detects draw conditionsplayGame()- Main game loop
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Not licensed so feel free to do whatever you want.
- Classic Tic-Tac-Toe game rules
- Console-based user interface design
- Cross-platform C++ development practices
Built with C++ | Cross-platform | Open Source