mercredi 2 mai 2018

Generate homeTeam/awayTeam pairs in League Manager application

Hey i want to create random pairs of teams to generate matches! A team cannot play with itself and the same match cannot be played ! There are 16 teams 2 rounds, 15 matches each round!I have a fixtures list, a teams list and a matches list ! here is the code i wrote so far for this method:

public void generateFixtures() {

    List<Match> fixtureMatches = new ArrayList<Match>();

    for(int i = 1; i<=NUMBER_OF_FIXTURES; i++) {
        for(int j = 0; j<4; j+=2) {
            Random rand = new Random();

            int t1 = rand.nextInt(15) + 0;
            int t2 = rand.nextInt(15) + 0;
            if(t2==t1) {
                t2 = rand.nextInt(15)+0;

            }
            SQLiteDatabase.insertInMatch(i, teams.get(t1).getTeamName(), teams.get(t2).getTeamName());

            Match m = new Match(teams.get(t1), teams.get(t2));
            fixtureMatches.add(m);
        }
        Fixture f = new Fixture(i, fixtureMatches);
        League.getInstance().fixtures.add(f);
    }
}

Thanks in advance!!!




Aucun commentaire:

Enregistrer un commentaire