-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStrategies.java
83 lines (67 loc) · 2.31 KB
/
Strategies.java
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
package BattleSimulator;
public class Strategies
{
// each method pairs up units according to preferences in given ways
public static BasicUnit[][] aggressive(Army army1, Army army2)
{
BasicUnit[][] targetPairs = new BasicUnit[army1.getTotalUnits()][2];
for (int i = 0; i < army1.getTotalUnits(); i++)
{
targetPairs[i][0] = army1.wholeArmy.get(i);
targetPairs[i][1] = targetPairs[i][0].getAttackTarget(army2);
}
return targetPairs;
}
public static BasicUnit[][] defensive(Army army1)
{
BasicUnit[][] targetPairs = new BasicUnit[army1.getTotalUnits()][2];
for (int i = 0; i < army1.getTotalUnits(); i++)
{
targetPairs[i][0] = army1.wholeArmy.get(i);
targetPairs[i][1] = targetPairs[i][0].getDefenseTarget(army1);
targetPairs[i][0].setBasicAttack(0.65);
}
return targetPairs;
}
public static BasicUnit[][] mixed(Army army1, Army army2)
{
BasicUnit[][] targetPairs = new BasicUnit[army1.getTotalUnits()][2];
for (int i = 0; i < army1.getTotalUnits(); i++)
{
int number = 1 + (int)(Math.random() * 2);
targetPairs[i][0] = army1.wholeArmy.get(i);
if (number == 1)
targetPairs[i][1] = targetPairs[i][0].getAttackTarget(army2);
else
targetPairs[i][1] = targetPairs[i][0].getDefenseTarget(army1);
}
return targetPairs;
}
public static BasicUnit[][] cooperativeAggressive(Army army1, Army army2)
{
BasicUnit[][] targetPairs = new BasicUnit[army1.getTotalUnits()][2];
targetPairs[0][0] = army1.wholeArmy.get(0);
targetPairs[0][1] = targetPairs[0][0].getAttackTarget(army2);
String currentType = targetPairs[0][0].getType();
int max = 1;
for (int i = 1; i < army1.getTotalUnits(); i++)
{
targetPairs[i][0] = army1.wholeArmy.get(i);
if (army1.wholeArmy.get(i).getType().equals(currentType) && max < 5)
{
targetPairs[i][0] = army1.wholeArmy.get(i);
targetPairs[i][1] = targetPairs[i - 1][1];
max++;
System.out.printf("%35s attacks %-28s\n", targetPairs[i][0].getName(), targetPairs[i][1].getName());
}
else
{
currentType = army1.wholeArmy.get(i).getType();
targetPairs[i][0] = army1.wholeArmy.get(i);
targetPairs[i][1] = targetPairs[i][0].getAttackTarget(army2);
max = 1;
}
}
return targetPairs;
}
}