Signal Sprint Board
Problem
Signal Sprint is a tabletop race game with one token, a start at position 0, and a fixed finish. Some landing positions contain a shortcut or setback that moves the token to another position. The complete landing table is supplied with the board, so the same object can represent different board layouts.
Design SignalSprintBoard to move the token according to that configured table, report its position, and reset it for another race.
Requirements
- Initialize the token. Construction sets the stored position to
0. - Advance the token.
advance(steps)sets the stored positionptolandingDestinations[p + steps]. - Reset the token.
reset()sets the stored position to0. - Return the position.
position()returns the stored position. - Preserve the position on read. Calling
position()does not change the stored position.
API
| Signature | Returns | Behavior |
|---|---|---|
SignalSprintBoard(finish: integer, landingDestinations: integer[]) | Not applicable | Creates a board with the supplied finish and landing configuration. |
advance(steps: integer) | void | Applies the configured transition. |
reset() | void | Restores the initial token state. |
position() | integer | Reads the current position. |
Examples
Given finish = 10 and:
landingDestinations = [0, 1, 7, 3, 4, 2, 6, 4, 8, 9, 10]
| Step | Operation | Result | Stored position |
|---|---|---|---|
| 1 | position() | 0 | 0 |
| 2 | advance(2) | No return value | 7 |
| 3 | position() | 7 | 7 |
| 4 | position() | 7 | 7 |
| 5 | advance(1) | No return value | 8 |
| 6 | reset() | No return value | 0 |
| 7 | position() | 0 | 0 |
Position 2 contains a shortcut to 7, so the first advance ends at 7. The entry at position 7 is not followed during the same move; each call applies exactly one configured transition.
Constraints
2 <= finish <= 100.landingDestinationshas exactlyfinish + 1entries.landingDestinations[0] == 0andlandingDestinations[finish] == finish.- Every landing destination is between
0andfinish, inclusive. 1 <= steps <= 6.- Every call to
advanceoccurs before the stored position reachesfinishand satisfiesposition() + steps <= finish. - At most
100public method calls occur in one testcase.
Notes
The driver validates all constructor data and operation preconditions before learner code runs. Calls on one board are sequential, and inputs outside the declared domain are not passed to the public API.