File size: 2,219 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Four-player Ludo

Build an offline Ludo game in HTML, CSS and JavaScript. Open the root `index.html` directly in a browser. Show the board, four pieces (in base or on the track), the active player, the latest roll and a victory message. Keep pieces visible even when they share a square.

## Rules

- Each player has one piece, a separate base, and a distinct starting square on a circular track of at least four squares. Players take turns rolling a six-sided die. A piece in base enters the track only on a 6, landing on its starting square with zero steps of progress. Other rolls in base leave it in place.
- A piece already on the track moves by the number rolled, wrapping around as needed. A 6 retains the turn; otherwise pass to the next player in order.
- The first player to accumulate at least one lap of steps after leaving base wins, even if the final roll overshoots. End the game with the winner as the current player. There are no captures, skipped squares or exact-roll requirements. After a win, rolls no longer change state.

## State interface

Expose `window.gameTest`: `reset()`, `setRolls(numbers)`, `roll()`, and `state()`. `setRolls` supplies the next rolls in order. `roll()` uses the same rules and rendering as the roll button, consuming a queued number if present; normal play uses random rolls.

Return `{players:[{id, pos, start, steps}, ...], currentPlayer, lastRoll, trackLength}`. `currentPlayer` is a zero-based index cycling through 0–3. `pos` is `-1` in base and the zero-based track position otherwise; `steps` counts actual progress after entering the track. On reset, all pieces return to base, steps and queued rolls clear, `lastRoll` is `null`, the victory message clears, and player 0 starts.

## Acceptance Checklist

- The offline page renders, and pieces visibly follow moves made through the state interface.
- All four players start in their bases, enter at distinct starts on a 6, and move by the exact roll after entering. Queued rolls, turn order, extra turns and wraparound follow the rules.
- Each player can win by reaching or overshooting one lap. Rolls after victory leave state unchanged; reset restores all pieces and the initial turn without a stale roll.