Matches.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MISTBowl_Brackets
  6. {
  7. public static class Matches
  8. {
  9. static readonly Hashtable matches = new Hashtable(0);
  10. public static void AddMatch(params Team[] teams)
  11. {
  12. try
  13. {
  14. if (teams.Length < 2)
  15. throw new ArgumentOutOfRangeException();
  16. foreach (List<Team> teamPair in Combinations.GetAllCombinations(teams, 2))
  17. {
  18. for (int i = 0; i < 2; i++)
  19. {
  20. if (matches[teams[i].teamId + "v" + teams[1 - i].teamId] == null)
  21. matches.Add(teams[i].teamId + "v" + teams[1 - i].teamId, 1);
  22. else
  23. matches[teams[i].teamId + "v" + teams[1 - i].teamId] = (int)matches[teams[i].teamId + "v" + teams[1 - i].teamId] + 1;
  24. }
  25. }
  26. }
  27. catch (Exception e)
  28. {
  29. Traceback.Write("At void AddMatch(Team, params Team[]) (class Matches):");
  30. throw e;
  31. }
  32. }
  33. public static int GetMatchCount(Team team1, Team opposition)
  34. {
  35. try
  36. {
  37. object count = matches[team1.teamId + "v" + opposition.teamId];
  38. return count == null ? (int)(matches[team1.teamId + "v" + opposition.teamId] = 0) : (int)count;
  39. }
  40. catch (Exception e)
  41. {
  42. Traceback.Write("At int GetMatchCount(string, string) (class Matches):");
  43. throw e;
  44. }
  45. }
  46. }
  47. }