Skip to content
216 changes: 178 additions & 38 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from src.driver.driver import Driver
from src.engine.engine import *
from src.race.race import Race
from src.race.raceResults import RaceResults
from src.series.series import Series
from src.team.team import Team
from src.team.teamFactory import TeamFactory
Expand All @@ -14,107 +15,246 @@ def main():
# instantiate the 2023 Formula One Championship
formula_one_2023 = Championship(series = formula_one, year = 2023)

# instantiate drivers

alb = Driver(surname = "Albon", givenname = "Alexander", number = 23, nationality = "Thailand")
alo = Driver(surname = "Alonso", givenname = "Fernando", number = 14, nationality = "Spain")
bot = Driver(surname = "Bottas", givenname = "Valtteri", number = 77, nationality = "Finland")
dev = Driver(surname = "de Vries", givenname = "Nyck", number = 21, nationality = "Netherlands")
gas = Driver(surname = "Gasly", givenname = "Pierre", number = 10, nationality = "France")
ham = Driver(surname = "Hamilton", givenname = "Lewis", number = 44, nationality = "United Kingdom")
hul = Driver(surname = "Hülkenberg", givenname = "Nico", number = 27, nationality = "Germany")
lec = Driver(surname = "Leclerc", givenname = "Charles", number = 16, nationality = "Monaco")
mag = Driver(surname = "Magnussen", givenname = "Kevin", number = 20, nationality = "Denmark")
nor = Driver(surname = "Norris", givenname = "Lando", number = 4, nationality = "United Kingdom")
oco = Driver(surname = "Ocon", givenname = "Esteban", number = 31, nationality = "France")
per = Driver(surname = "Pérez", givenname = "Sergio", number = 11, nationality = "Mexico")
pia = Driver(surname = "Piastri", givenname = "Oscar", number = 81, nationality = "Australia")
rus = Driver(surname = "Russell", givenname = "George", number = 63, nationality = "United Kingdom")
sai = Driver(surname = "Sainz", suffix = "Jr.", givenname = "Carlos", number = 55, nationality = "Spain")
sar = Driver(surname = "Sargeant", givenname = "Logan", number = 2, nationality = "United States")
stroll = Driver(surname = "Stroll", givenname = "Lance", number = 18, nationality = "Canada") # str is a reserved word
tsu = Driver(surname = "Tsunoda", givenname = "Yuki", number = 22, nationality = "Japan")
ver = Driver(surname = "Verstappen", givenname = "Max", number = 1, nationality = "Netherlands")
zho = Driver(surname = "Zhou", givenname = "Guanyu", number = 24, nationality = "China", surname_first = True)

# create teams using TeamFactory

formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamFerrariEngine(
name = "Alfa Romeo",
country = "Switzerland",
drivers = [
Driver(surname = "Bottas", givenname = "Valtteri", number = 77, nationality = "Finland"),
Driver(surname = "Zhou", givenname = "Guanyu", number = 24, nationality = "China", surname_first = True)
]
drivers = [bot, zho]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamHondaRBPTEngine(
name = "AlphaTauri",
country = "Italy",
drivers = [
Driver(surname = "de Vries", givenname = "Nyck", number = 21, nationality = "Netherlands"),
Driver(surname = "Tsunoda", givenname = "Yuki", number = 22, nationality = "Japan")
]
drivers = [dev, tsu]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamRenaultEngine(
name = "Alpine",
country = "France",
drivers = [
Driver(surname = "Gasly", givenname = "Pierre", number = 10, nationality = "France"),
Driver(surname = "Ocon", givenname = "Esteban", number = 31, nationality = "France")
]
drivers = [gas, oco]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamMercedesEngine(
name = "Aston Martin",
country = "United Kingdom",
drivers = [
Driver(surname = "Alonso", givenname = "Fernando", number = 14, nationality = "Spain"),
Driver(surname = "Stroll", givenname = "Lance", number = 18, nationality = "Canada")
]
drivers = [alo, stroll]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamFerrariEngine(
name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is
country = "Italy",
drivers = [
Driver(surname = "Leclerc", givenname = "Charles", number = 16, nationality = "Monaco"),
Driver(surname = "Sainz", suffix = "Jr.", givenname = "Carlos", number = 55, nationality = "Spain")
]
drivers = [lec, sai]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamFerrariEngine(
name = "Haas",
country = "United States",
drivers = [
# TODO add drivers
]
drivers = [hul, mag]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamMercedesEngine(
name = "McLaren",
country = "United Kingdom",
drivers = [
Driver(surname = "Norris", givenname = "Lando", number = 4, nationality = "United Kingdom"),
Driver(surname = "Piastri", givenname = "Oscar", number = 81, nationality = "Australia")
]
drivers = [nor, pia]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamMercedesEngine(
name = "Mercedes", # this is my favorite team
country = "Germany",
drivers = [
Driver(surname = "Hamilton", givenname = "Lewis", number = 44, nationality = "United Kingdom"),
Driver(surname = "Russell", givenname = "George", number = 63, nationality = "United Kingdom")
]
drivers = [ham, rus]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamHondaRBPTEngine(
name = "Red Bull", # you're not going to believe this, but Red Bull is actually a better team right now than Ferrari
country = "Austria",
drivers = [
# TODO add drivers
]
drivers = [per, ver]
)
)
formula_one_2023.addTeamToChampionship(
TeamFactory.createTeamMercedesEngine(
name = "Williams",
country = "United Kingdom",
drivers = [
# TODO add drivers
]
drivers = [alb, sar]
)
)

# add races and race results and print info

# bahrain grand prix

bahrain_gp = Race(
name = "Bahrain Grand Prix",
country = "Bahrain",
city = "Sakhir",
circuit = "Bahrain International Circuit"
)
print(bahrain_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = bahrain_gp,
rankings = [
ver, per, alo, sai, ham, stroll, rus, bot, gas, alb, tsu, sar, mag, dev, hul, zho, nor, oco, lec, pia
],
fastestLap = zho
)
)

# saudi arabian grand prix

saudi_gp = Race(
name = "Saudi Arabian Grand Prix",
country = "Saudi Arabia",
city = "Jeddah",
circuit = "Jeddah Corniche Circuit"
)
print(saudi_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = saudi_gp,
rankings = [
per, ver, alo, rus, ham, sai, lec, oco, gas, mag, tsu, hul, zho, dev, pia, sar, nor, bot, alb, stroll
],
fastestLap = ver
)
)

# australian grand prix

australian_gp = Race(
name = "Australian Grand Prix",
country = "Australia",
city = "Melbourne",
circuit = "Albert Park Circuit"
)
print(australian_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = australian_gp,
rankings = None, # TODO
fastestLap = None # TODO
)
)

# azerbaijan grand prix

azerbaijan_gp = Race(
name = "Azerbaijan Grand Prix",
country = "Azerbaijan",
city = "Baku",
circuit = "Baku City Circuit"
)
print(azerbaijan_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = azerbaijan_gp,
rankings = None, # TODO
fastestLap = None # TODO
)
)

# miami grand prix

miami_gp = Race(
name = "Miami Grand Prix",
country = "United States",
city = "Miami",
circuit = "Miami International Autodrome"
)
print(miami_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = miami_gp,
rankings = None, # TODO
fastestLap = None # TODO
)
)

# monaco grand prix

monaco_gp = Race(
name = "Monaco Grand Prix",
country = "Monaco",
city = "Monaco",
circuit = "Circuit de Monaco"
)
print(monaco_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = monaco_gp,
rankings = None, # TODO
fastestLap = None # TODO
)
)

# print standings to the console
# spanish grand prix

spanish_gp = Race(
name = "Spanish Grand Prix",
country = "Spain",
city = "Barcelona",
circuit = "Circuit de Barcelona-Catalunya"
)
print(spanish_gp.__str__())
formula_one_2023.holdRace(
RaceResults(
race = spanish_gp,
rankings = None, # TODO
fastestLap = None # TODO
)
)

# future races for the 2023 season

canadian_gp = Race(
name = "Canadian Grand Prix",
country = "Canada",
city = "Montreal",
circuit = "Circuit Gilles Villeneuve"
)

austrian_gp = Race(
name = "Austrian Grand Prix",
country = "Austria",
city = "Spielberg",
circuit = "Red Bull Ring"
)

# TODO add the rest of the future races for 2023

# print current standings to the console

print("\nTeam Standings")
for x in formula_one_2023.getTeamStandings():
Expand Down
38 changes: 31 additions & 7 deletions src/championship/championship.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,41 @@ def getTeamStandings(self) -> List[str]:

return printable

def holdRace(self, race: Race, results: RaceResults):
def holdRace(self, race_results: RaceResults):
'''
holds a race and updates standings given the results

params:
race: Race
results: RaceResults
race_results: RaceResults
'''
if not isinstance(race, Race):
raise TypeError(f"{race} must be of type Race, not {type(race)}")

# type checking

if not isinstance(race_results, RaceResults):
raise TypeError(f"{race_results} must be of type RaceResults, not {type(race_results)}")

if not isinstance(race_results.race, Race):
raise TypeError(f"{race_results.race} must be of type Race, not {type(race_results.race)}")

# type check the results
if not isinstance(race_results.results, dict):
raise TypeError(f"{race_results.results} must be of type dict, not {type(race_results.results)}")

# TODO update standings based on the results

tms = list(self.team_standings.keys())

for i in range(len(tms)):
if not isinstance(tms[i], Team):
raise TypeError(f"")

drs = list(tms[i].drivers)

for j in range(len(drs)):
if not isinstance(drs[j], Driver):
raise TypeError(f"")

new_points = race_results.getPointsForDriver(drs[j])

self.team_standings[tms[i]] += new_points
self.driver_standings[drs[j]] += new_points

# TODO update standings based on the results
7 changes: 5 additions & 2 deletions src/race/race.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ class Race():
"""
TODO
"""
def __init__(self, name: str, country: str, city: str):
def __init__(self, name: str, country: str, city: str, circuit: str):
if not isinstance(name, str):
raise TypeError(f"{name} must be of type str, not {type(name)}")
if not isinstance(country, str):
raise TypeError(f"{country} must be of type str, not {type(country)}")
if not isinstance(city, str):
raise TypeError(f"{city} must be of type str, not {type(city)}")
if not isinstance(circuit, str):
raise TypeError(f"{circuit} must be of type str, not {type(circuit)}")

self.name = name
self.country = country
self.city = city
self.circuit = circuit

def __str__(self) -> str:
return f"{self.name} Grand Prix ({self.city}, {self.country})"
return f"{self.name} ({self.circuit} in {self.city}, {self.country})"
2 changes: 2 additions & 0 deletions src/race/raceResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver):

points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

rankings.insert(0, None)

for i in range(1,21):
if not isinstance(rankings[i], Driver):
raise TypeError(f"{rankings[i]} must be of type Driver, not {type(rankings[i])}")
Expand Down
Loading