1. RaceHistory
• Purpose:
RaceHistory is a data structure that stores the results of all races that have been completed.
• Structure:
It contains a list of RaceData objects, each representing a single race, including details like car name, track name, lap times, position, and mileage.
• Usage:
• When a race finishes, a new RaceData entry is created and added to RaceHistory.
• RaceHistory is saved to and loaded from disk (usually as JSON) to persist results across sessions.
---
2. RacePositionStats
• Purpose:
RacePositionStats is a utility class for aggregating and analyzing race results, specifically to count how many times each racer finished in each position (1st, 2nd, ..., 11th).
• Structure:
• It uses a dictionary:
Dictionary racerPlacements
where the key is the racer's name, and the value is an array of counts for each position.
• Usage:
• For each race result, you call AddResult(racerName, position).
• The class then increments the count for that racer's finishing position.
• The GetSummary() method returns a human-readable summary of all placements.
---
3. RaceStatsUtility
• Purpose:
RaceStatsUtility is a static helper class that provides methods for summarizing and reporting on race results.
• Key Method:
• GetFinalRaceSummary(CRCarInfo.RaceHistory history)
This method takes a RaceHistory object and uses RacePositionStats to aggregate the results.
• Usage:
• It loops through all races in RaceHistory, adding each racer's result to RacePositionStats.
• It then returns a summary string showing how many times each racer finished in each position.
---
4. GetFinalRaceSummary
• Purpose:
This is the main method you call at the end of the campaign (e.g., after the last track/race).
• How it works:
• It receives the full RaceHistory (all races played so far).
• It creates a RacePositionStats instance.
• For each race, it records the finishing position for each racer.
• It generates a summary, such as:
RacerA: 1st: 2, 2nd: 1, 3rd: 0, ...
RacerB: 1st: 0, 2nd: 2, 3rd: 1, ...
• This lets you see, for example, who won the most races, who was most consistent, etc.
---
How They Work Together
1. During each race:
• When a race ends, a RaceData object is created and added to RaceHistory.
• RaceHistory is saved for persistence.
2. At the end of the campaign (final race):
• The game loads the full RaceHistory.
• GetFinalRaceSummary is called (via RaceStatsUtility).
• The summary is displayed to the player, showing overall performance across all races.
---
Example Flow
1. Race 1 finishes:
• RaceData for each racer is added to RaceHistory.
2. Race 2 finishes:
• More RaceData entries are added.
3. Final race finishes:
• All results are in RaceHistory.
• GetFinalRaceSummary(RaceHistory) is called.
• The player sees a summary of who placed 1st, 2nd, etc., the most times.
---
In summary:
• RaceHistory stores all race results.
• RacePositionStats counts placements for each racer.
• RaceStatsUtility.GetFinalRaceSummary aggregates and formats the results for display at the end of the campaign.
Analyzed By: Anton Opic & Claude Sonnet 4
