-
Notifications
You must be signed in to change notification settings - Fork 0
Add Two Game Modes and Cumulative Chess-Style Timers #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: CodeKunalTomar <111980003+CodeKunalTomar@users.noreply.github.com>
Co-authored-by: CodeKunalTomar <111980003+CodeKunalTomar@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request successfully transforms OptiConnect from a single-mode AI challenge into a dual-mode game with two distinct gameplay options. The implementation replaces the Fischer-style timer system (5:00 + 5s increment) with a cumulative countdown timer (2:00 total, no increment) that creates more intense time pressure.
Key Changes:
- Added two game modes: VS AI (human vs Elite AI) and Two-Player (local multiplayer)
- Replaced Fischer-style increment timers with cumulative countdown timers (2:00 per player, no increment)
- Introduced mode-specific messaging and UI labels that adapt based on the selected game mode
- Added visual timer states: normal, active (green glow), warning (orange ≤30s), and critical (red pulse ≤10s)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| index.js | Implements dual-mode game logic with cumulative timers, mode selection handlers, mode-specific messaging system, and Player 2 turn handling for Two-Player mode |
| index.html | Adds mode selection UI with VS AI and Two-Player buttons, updates timer panel visibility logic, and adjusts initial timer display to 2:00 |
| Connect-4.js | Adds player2-move message handler and makePlayer2Move() function in worker to support Two-Player mode alongside existing human and computer move handling |
| Connect-4.css | Adds mode selection button styling with hover/selected states, updates timer styling with warning/critical visual states, and implements pulse-critical animation |
| README.md | Updates documentation to reflect two game modes, cumulative timer system, and removes references to difficulty selection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dropCursorChip(coords.row, function() { | ||
| if (isWin) { | ||
| endGame('p2-win', winningChips); | ||
| // In Two-Player mode, use two-player win message; in AI mode, use AI win message |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions "Two-Player mode" but should use the actual mode value '2player' (without the dash) for consistency with how the mode is checked elsewhere in the code. The logic is correct but the comment could confuse future maintainers.
| // In Two-Player mode, use two-player win message; in AI mode, use AI win message | |
| // If gameMode is '2player', use two-player win message; otherwise, use AI win message |
| // Update warning and critical states for Player 1 | ||
| $player1Timer.removeClass('warning critical'); | ||
| if (player1Time > 0 && player1Time <= CRITICAL_TIME) { | ||
| $player1Timer.addClass('critical'); | ||
| } else if (player1Time > 0 && player1Time <= WARNING_TIME) { | ||
| $player1Timer.addClass('warning'); | ||
| } |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning state condition checks player1Time > 0 && player1Time <= WARNING_TIME, but the critical state also checks player1Time > 0 && player1Time <= CRITICAL_TIME. Since CRITICAL_TIME (10) is less than WARNING_TIME (30), when time is at or below CRITICAL_TIME, both conditions could be true before removeClass is called. However, this is handled correctly by removing both classes first (line 157), then applying the appropriate one. The logic works as intended but could be clearer by using player1Time <= CRITICAL_TIME for critical and player1Time > CRITICAL_TIME && player1Time <= WARNING_TIME for warning to make the mutual exclusivity explicit.
| <div class = "timer timer-p1" id = "player-timer"> | ||
| <div class = "timer-label">YOU</div> | ||
| <div class = "timer-value">5:00</div> | ||
| <div class = "timer-value">2:00</div> | ||
| </div> | ||
| <div class = "timer" id = "ai-timer"> | ||
| <div class = "timer timer-p2" id = "ai-timer"> | ||
| <div class = "timer-label">AI</div> | ||
| <div class = "timer-value">5:00</div> | ||
| <div class = "timer-value">2:00</div> | ||
| </div> |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timer elements have both class-based selectors (timer-p1, timer-p2) and ID attributes (player-timer, ai-timer) from the old implementation. While the JavaScript correctly uses the class selectors, the IDs are now obsolete and should be removed to avoid confusion and maintain cleaner markup.
| } | ||
|
|
||
| .mode-btn:focus { | ||
| outline: none; |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing outline on focus creates an accessibility issue for keyboard users who need visual indication of which element has focus. Consider using a custom focus style instead of removing it entirely.
| outline: none; | |
| outline: none; | |
| box-shadow: 0 0 0 3px #fff, 0 0 8px 2px #593f6b; | |
| border-color: #fff; |
| function startPlayer2Turn() { | ||
| setBlurb('p2-turn-2player'); | ||
| $('.click-columns div').addClass('hover'); | ||
|
|
||
| // Start player 2 timer | ||
| startTimer(2); | ||
|
|
||
| // if mouse is already over a column, show cursor chip there | ||
| const col = $('.click-columns div:hover').index(); | ||
| if(col !== -1) { | ||
| createCursorChip(2, col); | ||
| } | ||
|
|
||
| $('.click-columns') | ||
| .on('mouseenter', function() { | ||
| const col = $('.click-columns div:hover').index(); | ||
| createCursorChip(2, col); | ||
| }) | ||
| .on('mouseleave', function() { | ||
| destroyCursorChip(); | ||
| }); | ||
|
|
||
| $('.click-columns div') | ||
| .on('mouseenter', function() { | ||
| const col = $(this).index(); | ||
| moveCursorChip(col); | ||
| }) | ||
| .on('click', function() { | ||
| $('.click-columns, .click-columns div').off(); | ||
|
|
||
| const col = $(this).index(); | ||
| worker.postMessage({ | ||
| messageType: 'player2-move', | ||
| col: col | ||
| }); | ||
| }); | ||
| } |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions startHumanTurn and startPlayer2Turn have significant code duplication (lines 257-290 vs 373-406). The only differences are the player number (1 vs 2) passed to createCursorChip/startTimer and the message type sent to the worker. Consider refactoring into a single function that accepts player number and message type as parameters to reduce duplication and improve maintainability.
Transform OptiConnect from single-mode AI challenge to dual-mode game with VS AI and Two-Player options, replacing Fischer-style timers (5:00 + 5s increment) with cumulative countdown timers (2:00 total, no increment).
Timer System
Game Modes
Worker Protocol
Added
player2-movemessage type for Two-Player mode alongside existinghuman-moveandcomputer-move:Messaging
Mode-specific message variants for appropriate context:
p1-win(AI mode) vsp1-win-2playertimeout-p1-ai("You ran out of time") vstimeout-p1-2player("Player 1 ran out of time")UI Changes
Mode selection with visual icons (🤖 VS AI, 👥 2 Player), hover states, and selected styling. Timer panel visibility toggled based on game state.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
code.jquery.com/usr/bin/curl curl -o jquery.min.js REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Overview
Transform OptiConnect into a highly challenging, engaging Connect-4 experience with:
Detailed Requirements
1. Remove Difficulty System
Files to modify:
index.html,index.js,Connect-4.cssindex.js2. Two Game Modes
Mode Selection UI:
VS AI Mode:
Two-Player Mode:
3. Chess-Style Cumulative Timer System
IMPORTANT: This is a cumulative timer, NOT per-move reset
How it works:
Timer Display:
In VS AI mode:
4. Implement Elite AI (Target: 80% Win Rate)
File to modify:
Connect-4.jsThe AI should be significantly stronger:
5. Timer Implementation
File to modify:
index.js