Snake and Ladder Game

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-06-01

Problem Statement

Design the low-level architecture of the classic board game Snake and Ladder. The game involves players moving across a board from position 1 to 100 by rolling a dice. Some cells have snakes (which pull the player down) or ladders (which push the player up). The first player to reach exactly 100 wins.


🔷 Functional Requirements:

1.Start a Game:
•Initialize the game with:
•Board size (default 100 cells)
•Snakes: list of (start, end) pairs
•Ladders: list of (start, end) pairs
•Number of players and their names/IDs
2.Gameplay:
•Players take turns in a round-robin fashion.
•Each player rolls a dice (1–6) and moves forward.
•If a player lands at the start of a ladder, they move to the ladder’s end.
•If a player lands at the head of a snake, they slide to the tail.
3.Winning Condition:
•A player wins if they land exactly on cell 100.
•If a dice roll overshoots 100, the move is skipped.
4.Track Game State:
•Track player positions, current turn, and moves.
•Print board status or log moves if needed.


🔷 Constraints & Assumptions:

•No concurrent play — it's a turn-based game.
•No UI or persistence is needed — just simulate using CLI or in-memory objects.
•Each cell can have at most one snake or ladder (not both).
•Assume fair 6-faced dice.


🔶 Expected Design Focus:

•Classes like:
•Snake, Ladder, Board, Player, Dice, Game, GameManager
•Emphasize:
•OOP principles (encapsulation, modularity)
•Extensibility: make it easy to add features like multiple dice or power-ups
•Clean turn-handling and move evaluation logic


🔷 Optional (Bonus Features):

•Add a 2-dice mode
•Support undo move feature
•Add support for special tiles (e.g., teleport, skip turn)
•Allow different board sizes (e.g., 10x10, 20x20)
•Support logging of each round/move


✅ Sample Flow:

1plaintext 2CopyEdit 31. Game starts with 2 players: Alice and Bob. 42. Alice rolls a 4 → moves from 0 to 4. 53. Cell 4 has a ladder to 14 → Alice jumps to 14. 64. Bob rolls a 5 → moves to 5. 75. Bob lands on a snake head → slides down to 2. 8... 9First to reach cell 100 wins.


Solution

Comments