Skip to content

feat: add 2-player and 3-player mode options to Ludo game#7255

Open
Shrutii-Rai wants to merge 1 commit into
dhairyagothi:Mainfrom
Shrutii-Rai:feature/add-2-3-player-modes
Open

feat: add 2-player and 3-player mode options to Ludo game#7255
Shrutii-Rai wants to merge 1 commit into
dhairyagothi:Mainfrom
Shrutii-Rai:feature/add-2-3-player-modes

Conversation

@Shrutii-Rai
Copy link
Copy Markdown
Contributor

🔗 Related Issue

Closes #7206

📋 Summary

This PR adds 2-player and 3-player mode support to the Ludo game.Previously, the game only offered "4 Players" and "Player vs Computers" modes. Now players can choose from 2, 3, or 4 player modes, making the game flexible for smaller groups which is how Ludo is commonly played in real life.

✨ Type of Change

  • ✨ New feature or UI/UX enhancement

🛠️ Changes Made

index.html:

  • Added two new mode buttons: "2 Players" and "3 Players" on the mode selection screen.
  • Name entry cards now show/hide dynamically based on selected player count (2P shows 2 cards, 3P shows 3 cards, 4P shows all 4).

script.js:

  • Added selectedPlayerCount variable to track chosen mode.
  • Added goToNames(count) function that controls which name input cards are visible.
  • Added nextActivePlayer() function — ensures turns skip inactive players correctly instead of a simple modulo
  • 2-player mode activates Red and Green (diagonal positions , most balanced gameplay)
  • 3-player mode activates Red, Blue, and Green
  • Inactive player tokens are set to step: 57 at game start so they are invisible on the board and never interfere with gameplay
  • All game logic (turn rotation, timer timeout, AI turns, token cutting) updated to use nextActivePlayer() so all modes work correctly

🧪 Testing and Verification

Local Validation

  • I have run node scripts/validateProjects.js locally and it passed with zero errors.

Browser Compatibility Check

  • Tested and verified in Google Chrome
  • Tested and verified in Mozilla Firefox

Responsive & Accessibility Checks

  • Verified responsive layout on Mobile viewports (using DevTools)
  • Verified responsive layout on Tablet viewports
  • Keyboard navigation and focus outlines checked
  • Semantic HTML and ARIA labels checked

📸 Screenshots

Before: Only 2 buttons , "4 Players" and "Player vs Computers"

After: 4 buttons , "2 Players", "3 Players", "4 Players",
"Player vs Computers" (screenshot attached below 👇)
Screenshot 2026-06-07 234401


✅ Contributor Checklist

  • My code follows the code style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation / README files accordingly.
  • My changes generate no new warnings or console errors.
  • There are no unrelated changes or formatter noise in this PR.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

@Shrutii-Rai is attempting to deploy a commit to the Dhairya Gothi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@Shrutii-Rai
Copy link
Copy Markdown
Contributor Author

Shrutii-Rai commented Jun 7, 2026

Hi @dhairyagothi ,Submitted this PR for issue #7206 as part of GSSoC contribution.

Quick summary of what I implemented:

  • Added 2 Players and 3 Players mode buttons on the mode selection screen
  • Name entry screen dynamically shows only relevant player name inputs
  • Added nextActivePlayer() logic so turns rotate correctly among only the active players , no bugs with skipping or wrong turn order
  • Inactive player tokens are hidden from the board from game start
  • Tested all 3 modes (2P, 3P, 4P) and Player vs Computers , all working

Screenshot of the updated mode screen is attached in the PR. Happy to
make any adjustments if needed!

@dhairyagothi dhairyagothi added gssoc:approved Approved by admin level:intermediate Intermediate difficulty task type:refactor Refactoring/improvement labels Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved by admin level:intermediate Intermediate difficulty task type:refactor Refactoring/improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add 2 Player and 3 Player Mode Options to Ludo Game

2 participants