-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecretMatchMaker.java
More file actions
85 lines (77 loc) · 2.88 KB
/
SecretMatchMaker.java
File metadata and controls
85 lines (77 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.LinkedList;
public class SecretMatchMaker {
private Hashtable<Person, Person> perfectMatches;
public SecretMatchMaker() {
perfectMatches = new Hashtable<>();
}
@Override
public String toString() {
return "SecretMatchMaker{" +
"perfectMatches=" + perfectMatches +
'}';
}
public int ceremony(Picks p){
int beams =0;
//System.out.println(p.size());
for(int i=0; i<p.size(); i++ ) {
Match pair = p.getPair(i);
//System.out.println(i);
if(isMatch(pair.getP1(), pair.getP2())){
beams++;
}
}
return beams;
}
public boolean isMatch(Person p1, Person p2){
boolean ismatch = false;
if (perfectMatches.get(p1) == p2 || perfectMatches.get(p2) == p1) {
ismatch = true;
}
return ismatch;
}
public LinkedList<Person> makeCast(String[][] names, boolean[][] gender){
LinkedList<Person> contestants = new LinkedList<>();
for(int i=0; i< names[0].length; i++){
Person a = new Person(names[0][i], gender[0][i]);
Person b = new Person(names[1][i], gender[1][i]);
perfectMatches.put(a, b);
contestants.add(a);
contestants.add(b);
}
Collections.shuffle(contestants);
return contestants;
}
public LinkedList<Person> makeCastNoShuffle(String[][] names, boolean[][] gender, LinkedList<Integer> order){
LinkedList<Person> contestants = new LinkedList<>();
LinkedList<Person> contestants1 = new LinkedList<>();
LinkedList<Person> contestants2 = new LinkedList<>();
for(int i=0; i< names[0].length; i++){
Person a = new Person(names[0][i], gender[0][i]);
Person b = new Person(names[1][i], gender[1][i]);
contestants1.add(a);
contestants2.add(b);
}
contestants.addAll(contestants1);
contestants.addAll(contestants2);
for(int i=0; i< contestants1.size(); i++){
// System.out.println("i= " +i+" m= "+ contestants1.get(i).getName() + " f= " + contestants2.get(order.get(i)-1).getName() + " order="+ order.get(i));
perfectMatches.put(contestants1.get(i), contestants2.get(order.get(i)-1));
}
return contestants;
}
public LinkedList<Person> makeCast(String[][] names){
LinkedList<Person> contestants = new LinkedList<>();
for(int i=0; i< names[0].length; i++){
Person a = new Person(names[0][i]);
Person b = new Person(names[1][i]);
perfectMatches.put(a, b);
contestants.add(a);
contestants.add(b);
}
Collections.shuffle(contestants);
return contestants;
}
}