41 lines
1 KiB
C#
41 lines
1 KiB
C#
|
|
namespace WebEMSim
|
|
{
|
|
internal class Helpers
|
|
{
|
|
|
|
public static T GetRandomFromList<T>(List<T> list)
|
|
{
|
|
return list[Random.Shared.Next(list.Count)];
|
|
}
|
|
|
|
public static T GetRandomFromListAndRemove<T>(List<T> list)
|
|
{
|
|
T chosenOne = GetRandomFromList(list);
|
|
|
|
list.Remove(chosenOne);
|
|
|
|
return chosenOne;
|
|
}
|
|
|
|
public static List<Match> GenerateMatches(List<Team> teams)
|
|
{
|
|
List<Match> matches = [];
|
|
|
|
for (int teamAIdx = 0; teamAIdx < teams.Count - 1; teamAIdx++)
|
|
{
|
|
for (int teamBIdx = teamAIdx + 1; teamBIdx < teams.Count; teamBIdx++)
|
|
{
|
|
matches.Add(new Match(teams[teamAIdx], teams[teamBIdx]));
|
|
}
|
|
}
|
|
|
|
return matches.OrderBy(x => Random.Shared.Next()).ToList(); // why x ??
|
|
}
|
|
|
|
public static char NumberToLetter(int number)
|
|
{
|
|
return (char)(number+0x41);
|
|
}
|
|
}
|
|
}
|