Whose Turn Is It
Implement a class TurnTracker for a board game in which the players take turns in a fixed order. Write these methods:
TurnTracker(players)sets up the game.playerslists the names in turn order, and the first name in the list has the first turn of round1.whose_turn()returns the name of the player whose turn it is.end_turn()ends the current turn and gives the turn to the next player in the list. After the last player in the list, the turn goes back to the first player and a new round begins. Returns the name of the player who has the turn now.round_number()returns the number of the round being played, counting from1.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
TurnTracker(["ann","bo","cy"])
whose_turn() returns "ann"
end_turn() returns "bo"
end_turn() returns "cy"
round_number() returns 1
end_turn() returns "ann"
round_number() returns 2
whose_turn() returns "ann"
The turn goes ann, bo, cy, and after cy it wraps back to ann, which starts round 2.
Constraints
1 <= len(players) <= 6- The names in
playersare different, each1to8lowercase letters. - Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.