私はJavaスポーツスケジュールジェネレーターに取り組んでいます.私の問題は、それが十分なゲームを生成していないことです.私はそれを32日間に設定し、チームごとに1日1試合に設定しています. 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("");
}
}
}