You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-35Lines changed: 44 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,15 +18,16 @@
18
18
---
19
19
## I. Abstract
20
20
21
-
OptiConnect is a challenging, browser-based Connect-4 experience featuring a **single elite AI opponent** and **chess-style countdown timers**. This game combines sophisticated AI algorithms with time pressure to create an engaging, competitive experience that tests both strategic thinking and decision-making under time constraints.
21
+
OptiConnect is a challenging, browser-based Connect-4 experience featuring **two game modes**(VS AI and Two-Player) with **chess-style cumulative timers**. This game combines sophisticated AI algorithms with time pressure to create an engaging, competitive experience that tests both strategic thinking and decision-making under time constraints.
22
22
23
23
The game features:
24
+
-**Two Game Modes**: Challenge the Elite AI or play against a friend locally with Two-Player mode
24
25
-**Elite AI Opponent**: A powerful AI using depth-9 minimax search with alpha-beta pruning, transposition tables, and positional heuristics - designed to win approximately 80% of games against human players
25
-
-**Chess-Style Timers**: Each player starts with 5 minutes and gains a 5-second increment after each move, creating urgency and excitement
26
+
-**Chess-Style Cumulative Timers**: Each player starts with 2 minutes total time that counts down during their turns, creating intense time pressure
26
27
-**Non-Blocking Architecture**: All AI computation runs in a Web Worker thread, ensuring smooth 60fps UI performance
27
28
-**Advanced Optimizations**: Bitboard representation, Zobrist hashing, center-column move ordering, and opening book
28
29
29
-
The AI is calibrated to be challenging yet beatable, encouraging players to improve their analytical skills through repeated play. Can you be among the 20% who defeat the elite AI?
30
+
In VS AI mode, the AI is calibrated to be challenging yet beatable, encouraging players to improve their analytical skills through repeated play. Can you be among the 20% who defeat the elite AI?
30
31
31
32
---
32
33
## II. Local Deployment Protocol
@@ -83,18 +84,19 @@ The key architectural upgrade is the role of `index.js` as an intermediary that
| **`index.html`** | Provides the Document Object Model (DOM) structure, timer displays, Start Game button, and the primary game interface. It serves as the static entry point for the application. |
87
-
| **`Connect-4.css`** | Governs the responsive layout using modern CSS properties, manages all chip and board animations via keyframes and transitions, styles the timer displays with active/warning states, and defines an accessible, high-contrast color scheme. |
88
-
| **`Connect-4.js`** | **(Web Worker Context)** Contains the pure, stateful logic of the game engine. This includes the board data structures, the elite AI implementation with depth-9 minimax search, win/tie detection algorithms, position evaluation, move ordering, and opening book. It runs entirely off the main thread. |
89
-
| **`index.js`** | **(Main Thread Controller)** Acts as the application's central nervous system. It handles all user input events, manages timer state and countdown logic, controls game state transitions, spawns and communicates with the AI Worker via the `postMessage`/`onmessage` API, and updates the UI. |
87
+
| **`index.html`** | Provides the Document Object Model (DOM) structure, game mode selection (VS AI / Two-Player), timer displays, Start Game button, and the primary game interface. It serves as the static entry point for the application. |
88
+
| **`Connect-4.css`** | Governs the responsive layout using modern CSS properties, manages all chip and board animations via keyframes and transitions, styles the game mode selection and timer displays with active/warning/critical states, and defines an accessible, high-contrast color scheme. |
89
+
| **`Connect-4.js`** | **(Web Worker Context)** Contains the pure, stateful logic of the game engine. This includes the board data structures, the elite AI implementation with depth-9 minimax search, win/tie detection algorithms, position evaluation, move ordering, and opening book. It runs entirely off the main thread and handles both human and AI moves. |
90
+
| **`index.js`** | **(Main Thread Controller)** Acts as the application's central nervous system. It handles game mode selection, all user input events, manages timer state and countdown logic, controls game state transitions, spawns and communicates with the AI Worker via the `postMessage`/`onmessage` API, and updates the UI. |
90
91
91
92
### Key Features:
93
+
- **Two Game Modes**: VS AI (Human vs Elite AI) and Two-Player (local multiplayer on same device)
92
94
- **Elite AI**: Fixed depth-9 minimax search with alpha-beta pruning, transposition tables, center-column move ordering, opening book, and positional heuristics for an ~80% win rate
93
-
- **Chess-Style Timers**: 5-minute initialtimewith 5-second increment per move, creating time pressure and urgency
94
-
- **Timer States**: Active highlighting (green glow), warning state (red with pulse animation when <30 seconds), and timeout detection
95
+
- **Chess-Style Cumulative Timers**: 2-minute totaltimeper player that counts down only during their turns (no increment)
96
+
- **Timer States**: Active highlighting (green glow), warning state (orange at ≤30 seconds), critical state (red with fast pulse at ≤10 seconds), and timeout detection
95
97
- **Concurrency Management:** Spawns and manages a dedicated Web Worker, isolating all computationally intensive AI logic to a separate thread
96
98
- **Non-Blocking UI:** Decouples UI event handling from AI calculation, guaranteeing 60fps experience even during deep search
97
-
- **State Machine Implementation:** Cleanly manages UI and timer state transitions for all playable events
99
+
- **State Machine Implementation:** Cleanly manages UI and timer state transitions for all playable events including mode selection
98
100
- **Animation Orchestration:** Handles triggering of CSS animations and board updates while properly pausing timers during animations
99
101
100
102
---
@@ -113,51 +115,58 @@ The AI is designed to be highly challenging, winning approximately 80% of games
113
115
- **Iterative Deepening**: Searches progressively deeper, using best moves from shallower searches to improve move ordering
114
116
115
117
### Timer System:
116
-
- **Initial Time**: 5 minutes (300 seconds) per player
117
-
- **Increment**: +5 seconds added after each move (Fischer-style)
118
-
- **Warning Threshold**: Timer turns red and pulses when below 30 seconds
118
+
- **Initial Time**: 2 minutes (120 seconds) per player
119
+
- **Cumulative Timer**: Time counts down only during your turn, stops when opponent's turn begins (no increment)
120
+
- **Warning Threshold**: Timer turns orange when below 30 seconds
121
+
- **Critical Threshold**: Timer turns red and pulses rapidly when below 10 seconds
119
122
- **Timeout Detection**: Game ends immediately if either player's time reaches zero
120
123
- **Pause on Animation**: Timers automatically pause during chip drop animations and game-over state
121
124
125
+
### Game Modes:
126
+
- **VS AI Mode**: Human (Player 1 - Red) plays against the Elite AI (Player 2 - Yellow). Human always moves first. AI uses depth-9 search for challenging gameplay.
127
+
- **Two-Player Mode**: Local multiplayer where two players share the same device. Player 1 (Red) vs Player 2 (Yellow). Player 1 always moves first.
128
+
122
129
### Protocol Example (`index.js` orchestrates):
123
130
```javascript
124
-
// 1. Game starts - reset timers to 5:00 each
125
-
startGame() → playerTime = 300, aiTime = 300
131
+
// 1. Player selects mode (VS AI or Two-Player) and clicks Start Game
| **Game Modes** | VS AI (Human vs Elite AI) and Two-Player (local multiplayer) | Flexible gameplay that accommodates solo challenge against AI or local competitive play between two humans. Both modes use the same timer system and game rules. |
155
164
| **Game Board** | 7x7 grid (a deliberate deviation from the standard 6x7) | Enlarges the state space and branching factor, presenting a unique and more complex challenge for the AI and altering the lines of play established in solved-game theory for the 6x7 board. |
156
165
| **Victory Condition** | Formation of a contiguous line of four tokens (horizontal, vertical, or diagonal) | Evaluated via efficient bitboard operations that check win conditions in O(1) time per move using bitwise AND operations. |
157
-
| **Elite AI Opponent** | Fixed depth-9 minimax with advanced optimizations | Provides a highly challenging opponent with ~80% win rate, encouraging repeated play and skill development. Uses alpha-beta pruning, transposition tables, and positional heuristics. |
158
-
| **Chess-Style Timers** | 5:00 initial + 5s increment per move | Creates time pressure and urgency. Timers highlight active player (green glow), show warning when low (red pulse), and end game on timeout. Pauses during animations. |
166
+
| **Elite AI Opponent** | Fixed depth-9 minimax with advanced optimizations | Provides a highly challenging opponent with ~80% win rate in VS AI mode, encouraging repeated play and skill development. Uses alpha-beta pruning, transposition tables, and positional heuristics. |
167
+
| **Chess-Style Cumulative Timers** | 2:00 total time per player (counts down during turn)| Creates intense time pressure with no time back. Timers show active player (green glow), warning at ≤30s (orange), critical at ≤10s (red pulse), and end game on timeout. Pauses during animations. |
159
168
| **Move Validation** | Gravity-based column check and overflow prevention | Guarantees strict rule compliance and ensures the integrity of the game state by rejecting invalid moves before they are processed. |
160
-
| **Visual Feedback** | CSS/JS-driven hover, drop, winning-line highlights, and timer states | Delivers real-time, responsive user interactions with clear visual cues about game state, time pressure, and potential moves. |
169
+
| **Visual Feedback** | CSS/JS-driven mode selection, hover, drop, winning-line highlights, and timer states | Delivers real-time, responsive user interactions with clear visual cues about game mode, game state, time pressure, and potential moves. |
161
170
162
171
---
163
172
## VII. Performance & Benchmarking
@@ -191,9 +200,9 @@ This implementation now includes three major algorithmic optimizations that sign
191
200
---
192
201
## VIII. Historical & Educational Context
193
202
- **Academic Tradition:** This project continues the legacy of **Allis, Allen, and Tromp**, who established Connect-4 as a canonical problem for studying adversarial search, perfect play, and computational benchmarking.
194
-
- **Modern Twist:** While maintaining academic rigor, OptiConnect adds a competitive gaming layer with a challenging elite AI and chess-style time pressure, making it both educational and engaging.
203
+
- **Modern Twist:** While maintaining academic rigor, OptiConnect adds a competitive gaming layer with two game modes (VS AI and Two-Player) and chess-style cumulative time pressure, making it both educational and engaging.
195
204
- **Pedagogical Platform:** Demonstrates classical adversarial search (Minimax with Alpha-Beta pruning), modern web architecture, advanced optimization techniques (bitboards, transposition tables, Zobrist hashing), and real-time timer management. Provides a clear example of **concurrency, Web Workers, asynchronous event handling, bit manipulation, position caching, and separation of concerns** in application design.
196
-
- **Game Design Philosophy:** The fixed elite AI (no difficulty selection) and timer system create a pure competitive experience that encourages skill development, similar to chess training against a strong engine with time controls.
205
+
- **Game Design Philosophy:** The two game modes with cumulative timers create both competitive and casual play experiences. VS AI mode offers a pure competitive challenge against a strong engine, while Two-Player mode enables local multiplayer fun with the same time pressure mechanics.
197
206
198
207
---
199
208
## IX. Roadmap
@@ -202,7 +211,7 @@ This implementation now includes three major algorithmic optimizations that sign
0 commit comments