package com.youjiuye.map;
import java.util.ArrayList;
import java.util.List;
public class FootballTeam {
private String name;
private double score;
private int integral;
private List<FootballTeam> armsList = new ArrayList<FootballTeam>();
private static List<FootballTeam> list = new ArrayList<FootballTeam>();
static {
list.add(new FootballTeam("America"));
list.add(new FootballTeam("Chan"));
list.add(new FootballTeam("Japan"));
list.add(new FootballTeam("Russia"));
list.add(new FootballTeam("England"));
list.add(new FootballTeam("Australian"));
list.add(new FootballTeam("Malaysia"));
list.add(new FootballTeam("India"));
list.add(new FootballTeam("Philippines"));
list.add(new FootballTeam("Afghan"));
list.add(new FootballTeam("Pakistan"));
list.add(new FootballTeam("Nz"));
list.add(new FootballTeam("Brazil"));
list.add(new FootballTeam("Beligan"));
list.add(new FootballTeam("Korea"));
list.add(new FootballTeam("Italy"));
}
public FootballTeam() {
}
public FootballTeam(String name) {
super();
this.name = name;
}
public List<FootballTeam> getArmsList() {
return armsList;
}
public void setArmsList(List<FootballTeam> armsList) {
this.armsList = armsList;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static List<FootballTeam> getList() {
return list;
}
public static void setList(List<FootballTeam> list) {
FootballTeam.list = list;
}
@Override
public boolean equals(Object obj) {
FootballTeam ft = (FootballTeam) obj;
return this.name == ft.name;
}
@Override
public String toString() {
return "FootballTeam [name=" + name + "]";
}
}
package com.youjiuye.map;
import java.util.ArrayList;
import java.util.List;
public class Work03 {
public static void main(String[] args) {
List<FootballTeam> ft = FootballTeam.getList();
List<FootballTeam> firstgamefts = new ArrayList<FootballTeam>();
for (int i = 0; i < 4; i++) {
int j = 4;
groupGameCoil(ft, firstgamefts, i, j);
}
System.out.println("16进8");
System.out.println(firstgamefts);
List<FootballTeam> secondgamefts = new ArrayList<FootballTeam>();
for (int i = 0; i < 2; i++) {
int j = 4;
groupGameCoil(firstgamefts, secondgamefts, i, j);
}
System.out.println("8进4");
System.out.println(secondgamefts);
List<FootballTeam> thirdgamefts = new ArrayList<FootballTeam>();
List<FootballTeam> dft1 = grouping(secondgamefts, 2);
List<FootballTeam> dft2 = grouping(secondgamefts, 2);
compare(thirdgamefts, dft1);
compare(thirdgamefts, dft2);
System.out.println("4进2");
System.out.println(thirdgamefts);
List<FootballTeam> fourthgamefts = new ArrayList<FootballTeam>();
compare(fourthgamefts, thirdgamefts);
System.out.println("冠军");
System.out.println(fourthgamefts);
List<FootballTeam> list = fourthgamefts.get(0).getArmsList();
System.out.println("冠军之路:");
System.out.println(list);
}
public static void compare(List<FootballTeam> thirdgamefts, List<FootballTeam> dft) {
for (FootballTeam footballTeam : dft) {
footballTeam.setScore(Math.random() * 100);
}
if (dft.get(0).getScore() >= dft.get(1).getScore()) {
thirdgamefts.add(dft.get(0));
dft.get(0).getArmsList().add(dft.get(1));
} else {
thirdgamefts.add(dft.get(1));
dft.get(0).getArmsList().add(dft.get(1));
}
}
public static void groupGameCoil(List<FootballTeam> ft, List<FootballTeam> gamefts, int i, int j) {
List<FootballTeam> list = grouping(ft, j);
List<FootballTeam> gameft1 = groupingGame(list);
ensureCoilin(gamefts, gameft1);
ensureCoilin(gamefts, list);
}
public static void ensureCoilin(List<FootballTeam> gamefts, List<FootballTeam> gameft1) {
if (gameft1.get(0).getScore() >= gameft1.get(1).getScore()) {
gamefts.add(gameft1.get(0));
gameft1.get(0).getArmsList().add(gameft1.get(1));
} else {
gamefts.add(gameft1.get(1));
gameft1.get(1).getArmsList().add(gameft1.get(0));
}
}
public static List<FootballTeam> groupingGame(List<FootballTeam> list1) {
List<FootballTeam> gameft = new ArrayList<FootballTeam>();
for (int i = 0; i < 2; i++) {
int j = (int) (Math.random() + 2);
list1.get(j).setScore(Math.random() * 100);
gameft.add(list1.get(j));
list1.remove(j);
}
return gameft;
}
public static List<FootballTeam> grouping(List<FootballTeam> ft, int i) {
List<FootballTeam> groupList = new ArrayList<FootballTeam>();
while (groupList.size() < i) {
int j = (int) (Math.random() * ft.size());
groupList.add(ft.get(j));
ft.remove(ft.get(j));
}
return groupList;
}
}