namespace Highscore;
///
/// Processing of gamer scores to determine an overall highscore
///
public static class HighscoreProcessing
{
private const char Separator = ';';
///
/// Executes the program.
///
public static void Run()
{
var scores = LoadScoresFromFile("Data/scores.csv");
var bestScores = FindBestScorePerUser(scores);
SortGameScores(bestScores);
WriteOutputFileAndPrint(bestScores, "Data/highscore.csv");
}
///
/// Writes the provided instances to a file at the supplied path.
/// The CSV format is Score;Date;Player.
///
/// Game scores to persist
/// Path to write to
public static void WriteOutputFileAndPrint(GameScore[] highscore, string filePath)
{
// TODO
}
///
/// Loads the CSV file at the supplied path and attempts to parse its content to
/// create an array of instances utilizing .
///
/// Path to read from
/// Array of parsed items; empty array if file does not exist or is empty
public static GameScore[] LoadScoresFromFile(string filePath)
{
// TODO
return [];
}
///
/// Attempts to parse a CSV formatted string to a object.
///
/// String to parse
/// Successfully parsed object; null if parsing fails
/// True if parsed successfully; false otherwise
public static bool TryParseGameScore(string line, out GameScore? gameScore)
{
// TODO
gameScore = null;
return false;
}
///
/// Based on the provided full set of game scores for each user the best score is determined.
/// If a user has two or more entries with the same score the oldest (earliest) entry is considered to
/// be the highest.
///
/// Collection of all scores; may contain multiple entries for one user
/// An array containing the highest score of each user, based on passed scores
public static GameScore[] FindBestScorePerUser(GameScore[] allScores)
{
// TODO
return [];
}
///
/// Sorts the provided instances so that those with the
/// highest score (older date is preferred if score is equal) are ranked first.
/// Sorting happens in-place.
///
/// Scores to sort
public static void SortGameScores(GameScore[] scores)
{
// TODO
}
///
/// Trims empty (null) entries from the provided array.
///
/// The array to process
/// A new array containing only the non-null entries from the passed array
public static GameScore[] TrimArray(GameScore?[] arrayToTrim)
{
// TODO
return [];
}
}