- Home /
Random Fixture Generation
Hello. I want to create a Sports simulator, in this case a football simulator. I have a PremierLeague
list of 6 teams , which each team being an instance of a custom class, Team
At start I add the 6 teams to the list :
PremierLeague.Add(new Team { TeamName = "Liverpool", Attack = 90, Midfield = 85, Defence = 89, Points = 8, GamesPlayed = 0, GoalDifference = 0 });
PremierLeague.Add(new Team { TeamName = "Manchester Utd", Attack = 81, Midfield = 80, Defence = 74, Points = 7, GamesPlayed = 0, GoalDifference = 0 });
PremierLeague.Add(new Team { TeamName = "Tottenham", Attack = 85, Midfield = 80, Defence = 80, Points = 10, GamesPlayed = 0, GoalDifference = 0 });
PremierLeague.Add(new Team { TeamName = "Leicester City", Attack = 81, Midfield = 78, Defence = 76, Points = 2, GamesPlayed = 0, GoalDifference = 1 });
PremierLeague.Add(new Team { TeamName = "West Ham", Attack = 76, Midfield = 74, Defence = 72, Points = 2, GamesPlayed = 0, GoalDifference = 2 });
PremierLeague.Add(new Team { TeamName = "Aston Villa", Attack = 70, Midfield = 71, Defence = 70, Points = 2, GamesPlayed = 0, GoalDifference = -1 });
I have already created a function to sort them by points.
After that, I created a new class, Match
that has 4 parameters: 1 home Team 1 away team and their respective int scores:
public class Match
{
public Team HomeTeam;
public Team AwayTeam;
public int HomeGoals;
public int AwayGoals;
}
I have created a function that assigns scores result based on the team stats.
This all works as expected, but what I need is for the game to generate Matchups between all teams in the league. I thought I should create another Matchweek
class:
public class Matchweek //length = n. of teams / 2
{
public Match Match1;
public Match Match2;
public Match Match3;
}
that would consist of 3 (6/2) matches. What I can't figure out how to do is how to assign 3 matches to 10 (2*(6-1)) Matchweeks so that a new list of Matchweeks would feature 10 matchweeks containing all possible matchups between the teams in the league and a reverse fixture (inverting who is away and who is playing at home)
I've thought about this quite a bit and can't think of a solution but maybe my programming skills are too limited to achieve this as of yet so I wanted to know if anybody has some suggestions to achieve this? Thanks in advance
Your answer
Follow this Question
Related Questions
Trouble with Add-ing and Retrieving from a List of Custom Class 1 Answer
UNITYSCRIPT - Class's and Instances - Functions/Methods - Correct Usage 0 Answers
How to search a certain variable in a list of a created class (C#) 1 Answer
Trying to make a simple quest system, but i stuck how to do 0 Answers
Save an array with custom classes 1 Answer