Skip to content

About

Real-time multiplayer 24 card math game featuring buzzer-race & bluffing mechanics, adaptive AI bots, and pure Web Audio API synthesis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿƒ Twenty-Four Arena: Speed Buzzer & Bluffing Challenge

JavaScript Vite Web Audio API CSS3 Tests Passing MIT License

A modern, competitive reimagining of the classic 24 card math game featuring speed-buzzer races, psychological bluffing mechanics, adaptive AI bots, exact fractional arithmetic, and zero-dependency Web Audio API synthesis.


๐Ÿ“Œ Table of Contents


๐Ÿ’ก About the Project

Twenty-Four Arena draws inspiration from the classic arithmetic card game "24", where players are dealt 4 numbers (1โ€“9) and must combine them using elementary operations (+, -, ร—, รท) to yield an exact result of 24.

However, this version introduces high-stakes social and strategic tension:

  1. Speed Buzzer Race: Players race against each other and the clock to buzz in as soon as they spot a solution.
  2. Psychological Bluffing: Players can hit the buzzer even without a confirmed solutionโ€”solely to avoid becoming the last player!
  3. The Accuser's Dilemma: The slowest player to buzz becomes the Accuser and must pick one earlier player to prove their math on the interactive workbench within 30 seconds.
  4. Life Stakes (3 โค๏ธ): If verified, the Accuser loses 1 life. If the challenged player fails or was bluffing, the challenged player loses 1 life.
  5. Impossible Hands Claim: Approximately ~20% of 4-digit combinations are mathematically impossible to solve. Observant players can buzz with an "Impossible / No Solution" claim to turn the tables!

โœจ Key Features

  • ๐ŸŽฎ Flexible Multiplayer (2โ€“4 Players): Play locally on a single keyboard with friends or against autonomous AI opponents.
  • ๐Ÿค– Adaptive Bot AI with 3 Difficulty Profiles:
    • Easy: Relaxed human-like reaction delays, occasional calculation misses.
    • Medium: Balanced reflexes, capable of tactical bluffing under time pressure.
    • Hard: Sub-second cognitive speed, detects complex fractional paths and impossible hands.
  • ๐Ÿ“ Interactive Proof Workbench: Step-by-step calculation workbench with intermediate result cards, live calculation history pills, Undo, and Reset functionality.
  • ๐Ÿ”Š Zero-Dependency Acoustic Synthesizer: Powered by pure Web Audio API without any external audio asset files. Features authentic brass desk bell acoustics with harmonic overtones, card snaps, buzzer errors, and victory fanfares.
  • ๐Ÿ’Ž Modern Neo-Arcade Glassmorphism UI: Dark-mode aesthetic with vibrant glowing accents, fluid animations, responsive layouts, and celebration confetti particle physics.
  • ๐Ÿงช Unit-Tested Math Engine: Automated test suite guaranteeing accuracy across edge cases (including non-integer intermediate values like $8 / (1 - 1/3) = 24$).

๐Ÿ“œ Game Rules & Mechanics

flowchart TD
    A[Start Round: Deal 4 Cards] --> B[Speed Buzzer Race: 60s Timer]
    B -->|Player Buzzes In| C{Have all players buzzed?}
    C -->|No| B
    C -->|Yes / Timer Expires| D[Slowest Player Becomes Accuser]
    D --> E[Accuser Challenges 1 Previous Player]
    E --> F[Interactive Proof Stage: 30s Timer]
    F -->|Successfully Proves 24| G[Accuser Loses 1 Life]
    F -->|Fails / Bluff Exposed| H[Challenged Player Loses 1 Life]
    G --> I{Is there a single survivor?}
    H --> I
    I -->|No| A
    I -->|Yes| J[Grand Champion Crowned]
Loading

๐Ÿง  Architecture & Algorithms

1. Exact Fraction Arithmetic Engine (Fraction)

Standard IEEE 754 floating-point arithmetic introduces rounding inaccuracies (e.g. 8 / (3 - 8/3) evaluates to 24.000000000000004 or fails strict equality checks).

The Fraction class in src/solver.js guarantees deterministic rational precision:

  • Stores values as integer numerator (num) and denominator (den).
  • Computes the Greatest Common Divisor (GCD) via the Euclidean algorithm to simplify fractions after every operation.
  • Arithmetic methods (add, sub, mul, div) operate exclusively on integers.

2. Algorithmic 24 Solver (Binary Expression Trees)

To verify whether a deal is solvable, the algorithm exhaustively evaluates all number permutations ($4! = 24$) and all operator combinations ($4^3 = 64$) across 5 distinct binary expression tree topologies:

  1. ((a op b) op c) op d
  2. (a op (b op c)) op d
  3. (a op b) op (c op d)
  4. a op ((b op c) op d)
  5. a op (b op (c op d))

A total of $24 \times 64 \times 5 = 7,680$ expression branches are analyzed in under 2 milliseconds per round.

3. Adaptive AI Controller & Bluffing Heuristics

Located in src/bot.js:

  • Calculates dynamic delay intervals tailored to the selected difficulty tier.
  • If a valid solution exists, bots buzz based on difficulty-weighted probability distributions.
  • If a deal is mathematically unsolvable, Hard bots claim no_solution, while Medium bots may execute a tactical bluff to avoid being caught in last place.
  • During the proof stage, bots systematically reconstruct stored solution steps or fumble realistically if caught bluffing.

4. Pure Synthesized Audio (Web Audio API)

Implemented in src/audio.js, the audio engine generates sound waves directly inside the browser:

  • Metallic Desk Bell: Models the natural resonant frequencies of a physical metal service bell using a fundamental sine frequency (~980 Hz) paired with 3 overtone harmonics with exponential decay curves.
  • Card Snap: High-frequency transient micro-envelope.
  • Buzzer Error: Distorted sawtooth waveform.
  • Victory Fanfare: Ascending major arpeggio sequence (C5 โ€“ E5 โ€“ G5 โ€“ C6).

โŒจ๏ธ Keyboard Hotkeys

For local multiplayer on a shared keyboard, each player station is assigned a physical hotkey:

Player Avatar Keyboard Hotkey
Player 1 ๐ŸฆŠ Q
Player 2 ๐Ÿผ C
Player 3 ๐Ÿฆ N
Player 4 ๐Ÿฆ‰ P

(All buzzers and workbench controls can also be triggered directly via mouse clicks or touch screens).


๐Ÿ“‚ Directory Structure

Twenty-Four/
โ”œโ”€โ”€ index.html              # Main HTML markup & screen containers (Lobby, Arena, Proof)
โ”œโ”€โ”€ package.json            # Project dependencies, scripts, and metadata
โ”œโ”€โ”€ vite.config.js          # Vite bundler configuration
โ”œโ”€โ”€ test-solver.js          # Unit testing suite for exact fraction & solver algorithms
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.js             # Application entry point
โ”‚   โ”œโ”€โ”€ state.js            # Centralized Reactive State Store (Observer / Pub-Sub pattern)
โ”‚   โ”œโ”€โ”€ solver.js           # Exact Fraction engine & 24 permutation solver
โ”‚   โ”œโ”€โ”€ bot.js              # Autonomous AI controller & bluffing heuristics
โ”‚   โ”œโ”€โ”€ audio.js            # Pure Web Audio API sound synthesizer
โ”‚   โ”œโ”€โ”€ confetti.js         # Canvas particle confetti celebration engine
โ”‚   โ”œโ”€โ”€ ui.js               # DOM manipulation & event controller
โ”‚   โ””โ”€โ”€ styles/
โ”‚       โ”œโ”€โ”€ main.css        # Theme variables, typography, reset rules
โ”‚       โ”œโ”€โ”€ components.css  # Buttons, cards, badges, modal overlays
โ”‚       โ”œโ”€โ”€ lobby.css       # Lobby configuration & player setup styles
โ”‚       โ”œโ”€โ”€ arena.css       # Card table, scoreboard, buzzer stations
โ”‚       โ””โ”€โ”€ proof.css       # Interactive proof workbench & history tags
โ””โ”€โ”€ dist/                   # Production-ready compiled build

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (version 18+ recommended)
  • Git

Installation Steps

  1. Clone the repository:

    git clone https://github.com/DaffaArigoh/twenty-four-arena.git
    cd twenty-four-arena
  2. Install dependencies:

    npm install
  3. Start the local development server:

    npm run dev
  4. Open your browser and navigate to: http://localhost:3000


๐Ÿงช Running Unit Tests

To verify exact fractional arithmetic calculations and edge-case permutations:

npm test

Expected test output:

=== Testing Fraction Arithmetic ===
8 / (3 - 1/3) = 3 3

=== Testing Solver Cases ===
Cards: [1, 2, 3, 4] -> HasSolution: true (Expected: true) - PASS
   Sample: ((1 + 2) + 3) ร— 4 = 24
Cards: [3, 8, 3, 8] -> HasSolution: true (Expected: true) - PASS
   Sample: 8 รท (3 - (8 รท 3)) = 24
Cards: [1, 5, 5, 5] -> HasSolution: true (Expected: true) - PASS
   Sample: (5 - (1 รท 5)) ร— 5 = 24
...
 ALL SOLVER TESTS PASSED!

๐ŸŒ Deployment Guide

This project can be deployed instantly to any static hosting provider:

Option 1: Vercel (Recommended)

  1. Log in to Vercel.
  2. Click "Add New Project" and import twenty-four-arena.
  3. Vercel automatically detects the Vite build configuration.
  4. Click Deploy โ€” your live application will be available in seconds.

Option 2: GitHub Pages

  1. Run npm run build to output the optimized static bundle into dist/.
  2. Configure a GitHub Actions workflow to publish the dist/ directory to the gh-pages branch.

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

About

Real-time multiplayer 24 card math game featuring buzzer-race & bluffing mechanics, adaptive AI bots, and pure Web Audio API synthesis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages