0

我正在开发一个 java 运动日程生成器,我的问题是它没有生成足够的游戏,我将它(我认为)设置为 32 天,每个团队每天一场比赛,但由于某种原因从未输出那么多,在 17-29 之间变化。我已经经历了几次,但我仍然无法弄清楚问题所在。请帮忙!这就是我到目前为止所拥有的:提前谢谢!

    public class FourThirtyTwoSched {
//Who has the team played and how many times
static int[][] schedulePlayed = new int[4][4];

//Has the team played today?
static int[][] playedToday = new int [32][4];
public static void main(String[] args) {
    //Initiate Random objects
    Random rand = new Random(4);
    Random replace = new Random(4);
    //Sets the arrays
    //Column = reference team
    for(int i = 0; i < schedulePlayed.length; i++){
        schedulePlayed[i][0] = 8;
        schedulePlayed[i][1] = 8;
        schedulePlayed[i][2] = 8;
        schedulePlayed[i][3] = 8;
    }
    for(int j = 0; j 
            < 32; j++){
        playedToday[j][0] = 1;
        playedToday[j][1] = 1;
        playedToday[j][2] = 1;
        playedToday[j][3] = 1;
    }

    //Initiate Time
    int day = 0;

        while(day < 32){
        while((playedToday[day][0] + playedToday[day][1] + playedToday[day][2] + playedToday[day][3]) != 0){

        int vs = 0;
        int team = 0;
        vs = rand.nextInt(4);
        team = rand.nextInt(4);
        //ensure random is valid
        while(playedToday[day][vs] == 0 || schedulePlayed[vs][team] == 0 || playedToday[day][team] == 0){
            vs = replace.nextInt(4);
            team = replace.nextInt(4);  }            
        if (playedToday[day][vs] > 0 && schedulePlayed[vs][team] > 0 && playedToday[day][team] > 0){
            //Only prints if not bye
            if (true) {
            System.out.println(team + " v. " + vs);
            }}
    //prevents a team from playing multiple times per day- or against same team more than 8 times
            schedulePlayed[vs][team]--;
            playedToday[day][vs]--;
            playedToday[day][team]--;

        }
        //day count up one
        day++;      
        System.out.println("");
        }

    }
}
4

0 回答 0