我正在开发一个软件,我需要创建一个具有一系列标准的9个玩家的阵容,我开始怀疑这是不是一个不可能的问题,或者是否因为没有计算能力在有用的时间内解决它。 如果有人可以帮助或指导我,我会感谢他们巨大的。 一个简单的伪代码或逻辑指导将是完美的。
以下是标准: 来自6个不同球队的91名球员,每人都有成本。 5个位置:其中4个是成对的,另一个是独奏位置。 配对位置不能拥有同一原始团队的2名玩家。 阵容不能超过同一支球队的3名球员。 阵容的最终成本不能高于60000 $
我知道我会因为非常重复和不必要的代码而感到厌恶,但我太偏执了..
int totalSal = 0;
while (numPG != 2 && numSG != 2 && numC != 1 && numPF != 2 && numSF != 2 && totalSal < 60000) {//enquanto o salario total < 60000
for (int i = 0; i < listOfPlayers.getNumPlayers(); i++) {//para cada jogador
if (team1 == 3) {
t1blocked = true;
} else if (team2 == 3) {
t2blocked = true;
} else if (team3 == 3) {
t3blocked = true;
} else if (team4 == 3) {
t4blocked = true;
} else if (team5 == 3) {
t5blocked = true;
} else if (team6 == 3) {
t6blocked = true;
}
System.out.println("Seeing player number " + i);
if (numPG < 2 && totalSal <= 20000) {
Player selected = listOfPlayers.getPlayerAt(i);
if (selected.getPos().contains("PG") && selected.getSalary() <= 15000 && selected.getUsed() == false) {
if (selected.getTeam().contains("POR") && !t1blocked) {
team1++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
} else if (selected.getTeam().contains("OKC") && !t2blocked) {
team2++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
} else if (selected.getTeam().contains("WAS") && !t3blocked) {
team3++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
} else if (selected.getTeam().contains("PHO") && !t4blocked) {
team4++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
} else if (selected.getTeam().contains("LAL") && !t5blocked) {
team5++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
} else if (selected.getTeam().contains("DAL") && !t6blocked) {
team6++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPG++;
}
}
}
if (team1 == 3) {
t1blocked = true;
} else if (team2 == 3) {
t2blocked = true;
} else if (team3 == 3) {
t3blocked = true;
} else if (team4 == 3) {
t4blocked = true;
} else if (team5 == 3) {
t5blocked = true;
} else if (team6 == 3) {
t6blocked = true;
}
if (numSG < 2 && totalSal <= 30000) {
Player selected = listOfPlayers.getPlayerAt(i);
if (selected.getPos().contains("SG") && selected.getSalary() <= 15000 && selected.getUsed() == false) {
if (selected.getTeam().contains("POR") && !t1blocked) {
team1++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
} else if (selected.getTeam().contains("OKC") && !t2blocked) {
team2++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
} else if (selected.getTeam().contains("WAS") && !t3blocked) {
team3++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
} else if (selected.getTeam().contains("PHO") && !t4blocked) {
team4++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
} else if (selected.getTeam().contains("LAL") && !t5blocked) {
team5++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
} else if (selected.getTeam().contains("DAL") && !t6blocked) {
team6++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSG++;
}
}
}
if (team1 == 3) {
t1blocked = true;
} else if (team2 == 3) {
t2blocked = true;
} else if (team3 == 3) {
t3blocked = true;
} else if (team4 == 3) {
t4blocked = true;
} else if (team5 == 3) {
t5blocked = true;
} else if (team6 == 3) {
t6blocked = true;
}
if (numSF < 2 && totalSal <= 40000) {
Player selected = listOfPlayers.getPlayerAt(i);
if (selected.getPos().contains("SF") && selected.getSalary() <= 15000 && selected.getUsed() == false) {
if (selected.getTeam().contains("POR") && !t1blocked) {
team1++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
} else if (selected.getTeam().contains("OKC") && !t2blocked) {
team2++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
} else if (selected.getTeam().contains("WAS") && !t3blocked) {
team3++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
} else if (selected.getTeam().contains("PHO") && !t4blocked) {
team4++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
} else if (selected.getTeam().contains("LAL") && !t5blocked) {
team5++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
} else if (selected.getTeam().contains("DAL") && !t6blocked) {
team6++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numSF++;
}
}
}
if (team1 == 3) {
t1blocked = true;
} else if (team2 == 3) {
t2blocked = true;
} else if (team3 == 3) {
t3blocked = true;
} else if (team4 == 3) {
t4blocked = true;
} else if (team5 == 3) {
t5blocked = true;
} else if (team6 == 3) {
t6blocked = true;
}
if (numPF < 2 && totalSal <= 50000) {
Player selected = listOfPlayers.getPlayerAt(i);
if (selected.getPos().contains("PF") && selected.getSalary() <= 15000 && selected.getUsed() == false) {
if (selected.getTeam().contains("POR") && !t1blocked) {
team1++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
} else if (selected.getTeam().contains("OKC") && !t2blocked) {
team2++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
} else if (selected.getTeam().contains("WAS") && !t3blocked) {
team3++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
} else if (selected.getTeam().contains("PHO") && !t4blocked) {
team4++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
} else if (selected.getTeam().contains("LAL") && !t5blocked) {
team5++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
} else if (selected.getTeam().contains("DAL") && !t6blocked) {
team6++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numPF++;
}
}
}
if (team1 == 3) {
t1blocked = true;
} else if (team2 == 3) {
t2blocked = true;
} else if (team3 == 3) {
t3blocked = true;
} else if (team4 == 3) {
t4blocked = true;
} else if (team5 == 3) {
t5blocked = true;
} else if (team6 == 3) {
t6blocked = true;
}
if (numC < 1 && totalSal <= 60000) {
Player selected = listOfPlayers.getPlayerAt(i);
if (selected.getPos().contains("C") && selected.getSalary() <= 15000 && selected.getUsed() == false) {
if (selected.getTeam().contains("POR") && !t1blocked) {
team1++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
} else if (selected.getTeam().contains("OKC") && !t2blocked) {
team2++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
} else if (selected.getTeam().contains("WAS") && !t3blocked) {
team3++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
} else if (selected.getTeam().contains("PHO") && !t4blocked) {
team4++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
} else if (selected.getTeam().contains("LAL") && !t5blocked) {
team5++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
} else if (selected.getTeam().contains("DAL") && !t6blocked) {
team6++;
totalSal += selected.getSalary();
System.out.println("Selected the player:" + selected);
System.out.println("Added player. Total salary = $" + totalSal + "\n");
numC++;
}
}
}
if (numRestarts == 10){
break;
}
if (numPG < 2 && numSG < 2 && numC < 1 && numPF < 2 && numSF < 2 && (totalSal > 60000) || totalSal < 59000) {
System.err.println("Restarting");
numRestarts++;
restart();
}
}
}
System.out.println("Number of PG: " + numPG);
System.out.println("Number of PF: " + numPF);
System.out.println("Number of SF: " + numSF);
System.out.println("Number of SG: " + numSG);
System.out.println("Number of C: " + numC);
System.out.println("Members of POR: " + team1);
System.out.println("Members of OKC: " + team2);
System.out.println("Members of WAS: " + team3);
System.out.println("Members of PHO: " + team4);
System.out.println("Members of LAL: " + team5);
System.out.println("Members of DAL: " + team6);
System.out.println("Total Salary of lineup: $" + totalSal);
}
public void restart() {
team1 = 0;
team2 = 0;
team3 = 0;
team4 = 0;
team5 = 0;
team6 = 0;
numPG = 0;
numPF = 0;
numSF = 0;
numSG = 0;
numC = 0;
t1blocked = false;
t2blocked = false;
t3blocked = false;
t4blocked = false;
t5blocked = false;
t6blocked = false;
}
private int numRestarts = 0;
private int numC = 0;
private int numPF = 0;
private int numSF = 0;
private int numSG = 0;
private int numPG = 0;
private int numEntry = 0;
private int team1 = 0; //POR
private int team2 = 0; //OKC
private int team3 = 0; //WAS
private int team4 = 0; //PHO
private int team5 = 0; //LAL
private int team6 = 0; //DAL
private boolean t1blocked = false;
private boolean t2blocked = false;
private boolean t3blocked = false;
private boolean t4blocked = false;
private boolean t5blocked = false;
private boolean t6blocked = false;