Sure! Here's an example of a drafting system for a sport using Python code, with teams having a budget and a pool of available players. In this example, we will assume the sport is basketball.
import random
class Player:
def __init__(self, name, position, rating, cost):
self.name = name
self.position = position
self.rating = rating
self.cost = cost
class Team:
def __init__(self, name, budget):
self.name = name
self.budget = budget
self.players = []
def add_player(self, player):
if self.budget >= player.cost:
self.players.append(player)
self.budget -= player.cost
return True
else:
return False
def get_total_rating(self):
total_rating = 0
for player in self.players:
total_rating += player.rating
return total_rating
def __str__(self):
return f"Team: {self.name}, Budget: {self.budget}"
def create_players():
players = [
Player("Player 1", "Forward", 8, 10),
Player("Player 2", "Guard", 7, 8),
Player("Player 3", "Center", 9, 12),
Player("Player 4", "Forward", 6, 6),
Player("Player 5", "Guard", 9, 10),
Player("Player 6", "Center", 8, 11),
Player("Player 7", "Forward", 7, 7),
Player("Player 8", "Guard", 8, 9),
Player("Player 9", "Center", 7, 10),
Player("Player 10", "Forward", 9, 13)
]
return players
def draft_players(teams, players):
pool = random.sample(players, len(players))
for player in pool:
for team in teams:
if team.add_player(player):
players.remove(player)
print(f"{player.name} drafted to {team.name}")
break
def display_teams(teams):
for team in teams:
print(f"\n{team.name}'s Team:")
for player in team.players:
print(f"{player.name} ({player.position}) - Rating: {player.rating}, Cost: {player.cost}")
print("------")
# Create teams
team1 = Team("Team 1", 20)
team2 = Team("Team 2", 20)
# Add teams to a list
teams = [team1, team2]
# Create players
players = create_players()
# Draft players
draft_players(teams, players)
# Display teams with drafted players
display_teams(teams)
In this example, we have a Player class with attributes such as name, position, rating, and cost. The Team class has attributes like name, budget, and a list of players. The Team class also has methods to add players, get the total rating of the team, and display the team's information.
The create_players function creates a list of players with their respective attributes. The draft_players function randomly selects players from the pool and tries to add them to the teams based on each team's budget. If a player is successfully drafted, it is removed from the pool and added to the team's player list.
Finally, the display_teams function is used to print the teams' details along with the drafted players.
Please note that this is just a simple example, and you can modify or expand it based on your specific requirements and needs.