Skip to content

utkarshgupta-iitbhu/Mini-Arcade-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Mini Games Console

A comprehensive C++ console-based gaming application featuring three classic games with a unified score management system. This project demonstrates Object-Oriented Programming (OOP) principles and implements the Minimax Algorithm for AI-powered gameplay.

C++ Platform AI Game


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

This project is a Mini Games Console application built entirely in C++. It provides an interactive menu-driven interface where users can play three different games, track their high scores, and compete against either another player or an AI opponent.

The application showcases:

  • Clean Object-Oriented Design
  • AI implementation using the Minimax Algorithm
  • Persistent score tracking across game sessions
  • Multiple difficulty levels with score multipliers

โœจ Features

Feature Description
๐ŸŽฒ Multiple Games Three classic games in one application
๐Ÿค– AI Opponent Play against computer with varying difficulty
๐Ÿ“Š Score System Track wins, games played, and cumulative scores
๐Ÿ† Leaderboard View high scores for each game
โš™๏ธ Difficulty Levels Multiple difficulty settings with score multipliers
๐ŸŽจ Clean UI Well-formatted console interface

๐ŸŽฎ Games Included

1. ๐Ÿชจ๐Ÿ“„โœ‚๏ธ Rock Paper Scissors

Classic hand game against the computer with customizable win targets.

  • Win Targets: First to 3, 5, or 10 wins
  • Scoring: 20 points per round won

2. โญ•โŒ Tic-Tac-Toe

The timeless 3x3 grid game with both PvP and PvE modes.

  • Modes: Player vs Player, Player vs Computer
  • AI Difficulty: Easy (Random) or Hard (Minimax AI)
  • Scoring: 100 base points ร— difficulty multiplier

3. ๐Ÿ”ข Number Guessing Game

Guess the secret number within limited attempts.

  • Difficulty Levels:
    Level Range Attempts Multiplier
    Easy 1-50 10 1x
    Medium 1-100 10 2x
    Hard 1-200 5 3x
    Expert 1-500 10 5x

๐Ÿš€ How to Run

Prerequisites

  • Windows Operating System
  • C++ Compiler (g++, MSVC, or similar)
  • C++11 or higher

Compilation

Using g++:

g++ -o MiniGames main.cpp -std=c++11

Using MSVC (Visual Studio Developer Command Prompt):

cl /EHsc main.cpp /Fe:MiniGames.exe

Execution

./MiniGames.exe

๐Ÿ“– Game Instructions

Main Menu Navigation

  +----------------------------------+
  |     SELECT A GAME TO PLAY        |
  +----------------------------------+
  | 1. Rock-Paper-Scissors           |
  | 2. Tic-Tac-Toe                   |
  | 3. Number Guessing               |
  +----------------------------------+
  |     OTHER OPTIONS                |
  +----------------------------------+
  | 4. View High Scores              |
  | 5. Reset High Scores             |
  | 6. Exit                          |
  +----------------------------------+

Tic-Tac-Toe Board Layout

  1  |  2  |  3
-----|-----|-----
  4  |  5  |  6
-----|-----|-----
  7  |  8  |  9

Enter a number (1-9) to place your mark on the corresponding cell.


๐Ÿ”ง Technical Implementation

Object-Oriented Programming (OOP)

This project demonstrates several key OOP concepts:

1. Encapsulation

Each class encapsulates its data and provides controlled access through public methods.

class TicTacToe {
private:
    char board[9];           // Hidden internal state
    string player1Name;
    bool vsComputer;
    int difficulty;
    
    void initialBoard();     // Private helper methods
    bool checkWin(char mark) const;
    
public:
    void play(ScoreManager &scoreManager);  // Public interface
};

Benefits:

  • Internal implementation details are hidden
  • Data integrity is maintained
  • Changes to internal structure don't affect external code

2. Abstraction

Complex operations are abstracted into simple method calls.

// Complex AI logic is abstracted behind a simple interface
int getComputerMove();  // Returns the best move - complexity hidden

// Score management abstracted
scoreManager.saveScore("TicTacToe", playerName, score, wins);

3. Classes and Objects

Class Responsibility
ScoreManager Manages all game scores, rankings, and persistence
TicTacToe Handles Tic-Tac-Toe game logic and AI
NumberGuessing Manages number guessing game mechanics
RockPaperScissors Controls RPS game flow and scoring
PlayerScore (struct) Data structure for player statistics

4. Composition

The main program composes game objects and a score manager:

int main() {
    ScoreManager scoreManager;      // Score management component
    RockPaperScissors rpsGame;      // Game components
    TicTacToe tttGame;
    NumberGuessing ngGame;
    
    // Games use scoreManager through composition
    tttGame.play(scoreManager);
}

5. Const Correctness

Methods that don't modify state are marked const:

void displayBoard() const;
bool checkWin(char mark) const;
bool isBoardFull() const;
void displayScores(const string &title, const vector<PlayerScore> &scores) const;

Minimax Algorithm

The Minimax Algorithm is a decision-making algorithm used in game theory for two-player zero-sum games. In this project, it powers the "Hard" difficulty AI in Tic-Tac-Toe.

How Minimax Works

                    Current Board State
                           |
            +--------------+--------------+
            |              |              |
         Move A         Move B         Move C
            |              |              |
         Player          Player        Player
        Responds        Responds      Responds
            |              |              |
           ...            ...            ...
            |              |              |
      Final Score    Final Score   Final Score

Algorithm Explanation

  1. Recursive Tree Search: The algorithm explores all possible future game states
  2. Maximizing Player (AI/O): Tries to maximize the score
  3. Minimizing Player (Human/X): Tries to minimize the score
  4. Base Cases: Win, Loss, or Draw

Code Implementation

int minimax(bool isMaximizing, int depth) {
    // BASE CASES - Terminal states
    if (checkWin('O')) return 10 - depth;   // AI wins (prefer faster wins)
    if (checkWin('X')) return depth - 10;   // Human wins (prefer slower losses)
    if (isBoardFull()) return 0;            // Draw
    
    if (isMaximizing) {
        // AI's turn - maximize score
        int bestScore = -1000;
        for (int i = 0; i < 9; i++) {
            if (board[i] == ' ') {
                board[i] = 'O';                          // Try move
                int score = minimax(false, depth + 1);   // Recurse
                board[i] = ' ';                          // Undo move
                bestScore = max(bestScore, score);       // Keep best
            }
        }
        return bestScore;
    } else {
        // Human's turn - minimize score
        int bestScore = 1000;
        for (int i = 0; i < 9; i++) {
            if (board[i] == ' ') {
                board[i] = 'X';                          // Try move
                int score = minimax(true, depth + 1);    // Recurse
                board[i] = ' ';                          // Undo move
                bestScore = min(bestScore, score);       // Keep worst for AI
            }
        }
        return bestScore;
    }
}

Depth Consideration

The depth parameter serves two purposes:

  1. Prefer Faster Wins: 10 - depth means winning sooner gives higher score
  2. Delay Losses: depth - 10 means losing later is better than losing sooner

Visual Example

Initial State:          After Minimax Analysis:
                        
  X | O | X             AI evaluates all possibilities
----|---|----           and determines the optimal move
  O |   |               that guarantees a win or draw
----|---|----           
    |   |               Best Move: Position 5 (center-right)

Time Complexity

  • Worst Case: O(b^d) where b = branching factor, d = depth
  • For Tic-Tac-Toe: Maximum ~9! = 362,880 states (but pruning reduces this significantly)

๐Ÿ“ Code Structure

mini-games-console/
โ”‚
โ”œโ”€โ”€ main.cpp                 # Complete source code
โ”‚
โ”œโ”€โ”€ Components:
โ”‚   โ”œโ”€โ”€ PlayerScore (struct) # Player data structure
โ”‚   โ”œโ”€โ”€ ScoreManager (class) # Score tracking & display
โ”‚   โ”œโ”€โ”€ TicTacToe (class)    # TTT game with Minimax AI
โ”‚   โ”œโ”€โ”€ NumberGuessing (class)# Number guessing game
โ”‚   โ””โ”€โ”€ RockPaperScissors (class) # RPS game
โ”‚
โ””โ”€โ”€ README.md                # This file

Class Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    ScoreManager      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - tttScores          โ”‚
โ”‚ - ngScores           โ”‚
โ”‚ - rpsScores          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + saveScore()        โ”‚
โ”‚ + displayScores()    โ”‚
โ”‚ + showAllHighScores()โ”‚
โ”‚ + resetAllScores()   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ–ฒ
         โ”‚ uses
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                      โ”‚
โ–ผ                โ–ผ                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  TicTacToe   โ”‚ โ”‚NumberGuessingโ”‚ โ”‚    RPS       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - board[9]   โ”‚ โ”‚-secretNumber โ”‚ โ”‚-playerScore  โ”‚
โ”‚ - players    โ”‚ โ”‚-maxAttempts  โ”‚ โ”‚-computerScoreโ”‚
โ”‚ - difficulty โ”‚ โ”‚-difficulty   โ”‚ โ”‚              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + play()     โ”‚ โ”‚ + play()     โ”‚ โ”‚ + play()     โ”‚
โ”‚ - minimax()  โ”‚ โ”‚-generateNum()โ”‚ โ”‚-determineWinโ”‚
โ”‚ - checkWin() โ”‚ โ”‚              โ”‚ โ”‚              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ธ Screenshots

Main Menu

  +----------------------------------+
  |     SELECT A GAME TO PLAY        |
  +----------------------------------+
  | 1. Rock-Paper-Scissors           |
  | 2. Tic-Tac-Toe                   |
  | 3. Number Guessing               |
  +----------------------------------+

Tic-Tac-Toe Gameplay

==================================================
              TIC TAC TOE
==================================================

Player1 (X)  vs  Computer (O)

  X  |  O  |  3
-----|-----|-----
  4  |  X  |  6
-----|-----|-----
  7  |  8  |  O

Player1's turn. Enter your move (1-9): 

High Scores

============================================================
                    HIGH SCORES
============================================================

--- TIC-TAC-TOE GAME ---
Rank  Player              Score     Games     Wins
--------------------------------------------------------
1     Alice               300       3         3
2     Bob                 150       2         1

๐Ÿ”ฎ Future Improvements

  • Add file persistence for scores (save/load from disk)
  • Implement Alpha-Beta pruning for faster Minimax
  • Add more games (Hangman, Connect Four, etc.)
  • Cross-platform support (Linux/macOS)
  • Implement undo/redo functionality
  • Add game statistics and analytics
  • Network multiplayer support

About

A feature-rich C++ console mini arcade featuring Tic-Tac-Toe (with Minimax AI), Number Guessing, and Rock-Paper-Scissors, complete with a unified scoring and leaderboard system.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages