turbo_tag module

Module: Turbo Tag Game Simulation

This module simulates a game of Turbo Tag, a dynamic team sport emphasizing strategy and agility. It is played on a rectangular field with a goal at each end, involving two teams with a variable number of players. The primary objective is to score points through tagging, ball possession, and goal scoring.

Game Rules:

  1. Team Composition: Teams can have 5 to 9 players. Each additional player beyond five reduces the team’s total band count by 2.

  2. Starting the Game: Begins with a jump ball at the center. The team that secures the ball gains initial possession.

  3. Scoring Points:

    • Goal Score: Throwing the ball into the opponent’s goal scores 3 points.

    • Band Capture: Tagging an opponent allows stealing a band, earning 1 point. If the tagged player holds bands of more than one color, the tagging player steals a band of their own team’s color. The tagger only steals a band of the opposing team’s color if the tagged player has only bands of that color.

    • End of game bonuses, described below.

  4. Tagging Mechanism:

    • Players can tag opponents to steal their bands.

    • A player must wait at least 30 seconds before re-tagging the same opponent.

    • If a tagged player holds the ball, the ball is transferred to the nearest opponent. If this tag occurs within 5 meters of the tagging player’s team’s goal, the tag is also worth one point (this is called a “block-by-tag”).

  5. Time Limit: Two 25-minute halves with a break in between.

  6. Scoring System:

    • Each goal: 3 points.

    • Each band captured: 1 point.

    • Bonus for capturing all opponent bands: At the end of the game, each player that has zero bands of their own color awards their opponent 10 points.

    • Single color bonus: At the end of the game, each band that a team holds of their opposing team’s color is worth an additional bonus point.

class turbo_tag.Ball

Bases: object

Represents the ball used in Turbo Tag.

current_holder

The player currently holding the ball.

Type:

Player or None

transfer_possession(new_holder: Player)

Transfers possession of the ball to a new holder.

Parameters:

new_holder (Player) – The player who is the new holder of the ball.

class turbo_tag.Game(team1: Team, team2: Team)

Bases: object

Represents a game of Turbo Tag.

team1

The first team in the game.

Type:

Team

team2

The second team in the game.

Type:

Team

ball

The ball used in the game.

Type:

Ball

time_left

The time left in the game (in minutes).

Type:

int

end_game()

Ends the game and calculates final scores.

class turbo_tag.Player(name: str, team: Team, initial_bands: int)

Bases: object

Represents a player in the Turbo Tag game.

name

The name of the player.

Type:

str

team

The team the player belongs to.

Type:

Team

bands

A dictionary tracking the count of blue and red bands the player has.

Type:

dict

last_tag_time

The last time the player tagged someone (given in seconds since the start of the game).

Type:

int or None

has_ball

Flag indicating whether the player currently has the ball.

Type:

bool

tag(opponent: Player, current_time: int, ball: Ball, distance_from_goal: int)

Tags an opponent, attempting to steal a band and transfer ball possession.

Parameters:
  • opponent (Player) – The player being tagged.

  • current_time (int) – The current time (given in seconds since the start of the game).

  • ball (Ball) – The ball object in the game.

  • distance_from_goal (int) – used to calculate block-by-tag

class turbo_tag.Team(name: str, player_count: int, team_color: str)

Bases: object

Represents a team in the Turbo Tag game.

name

The name of the team.

Type:

str

score

The current score of the team.

Type:

int

players

A list of Player objects on the team.

Type:

list

team_color

The color of the team’s bands.

Type:

str

opponent

The opposing team

Type:

Team

adjust_band_count(player_count: int, team_color: str)

Adjusts the initial band count for each player based on the team size.

Parameters:
  • player_count (int) – The number of players on the team.

  • team_color (str) – The color of the team’s bands.

calculate_end_game_bonus()

Calculates and adds end-game bonus points to the team’s score.

score_goal()

Updates the team’s score when a goal is scored.