-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardAlgorithm.java
More file actions
46 lines (38 loc) · 1.29 KB
/
HardAlgorithm.java
File metadata and controls
46 lines (38 loc) · 1.29 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
public class HardAlgorithm implements DifficultyAlgorithm {
private boolean useAlternateStrategy = false;
private int lossCount = 0;
@Override
public String selectCard(String[] cards) {
int highestScore = Integer.MIN_VALUE;
String selectedCard = null;
for (String card : cards) {
String[] cardData = card.split(",");
String element = cardData[0];
int powerNumber = Integer.parseInt(cardData[1]);
String color = cardData[2];
int score = powerNumber;
if (!useAlternateStrategy) {
// Code for unique color and element
score += (element.hashCode() * color.hashCode());
} else {
// Code for different element and color
score += (element.hashCode() - color.hashCode());
}
if (score > highestScore) {
highestScore = score;
selectedCard = card;
}
}
return selectedCard;
}
public void incrementLossCount() {
this.lossCount++;
if (lossCount >= 2) {
this.useAlternateStrategy = !useAlternateStrategy;
this.lossCount = 0;
}
}
public void resetLossCount() {
this.lossCount = 0;
}
}