Skip to content

Commit be38023

Browse files
author
Bytekeeper
committed
Added medic test and fixed overflows in Evaluator
1 parent 70f4938 commit be38023

File tree

4 files changed

+78
-54
lines changed

4 files changed

+78
-54
lines changed

src/main/java/org/bk/ass/Evaluator.java

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public double evaluate(Collection<Agent> agentsA, Collection<Agent> agentsB) {
3535
agentsB.forEach(a -> a.onDeathHandler.accept(a, finalAgentsB));
3636
finalAgentsA.addAll(agentsA);
3737
finalAgentsB.addAll(agentsB);
38-
int damageToA = new DamageBoard(finalAgentsB).sumDamageTo(finalAgentsA);
39-
int damageToB = new DamageBoard(finalAgentsA).sumDamageTo(finalAgentsB);
38+
double damageToA = new DamageBoard(finalAgentsB).sumDamageTo(finalAgentsA);
39+
double damageToB = new DamageBoard(finalAgentsA).sumDamageTo(finalAgentsB);
40+
4041
int regenToA = regeneration(finalAgentsA);
4142
int regenToB = regeneration(finalAgentsB);
4243
damageToA -= regenToA;
@@ -48,14 +49,12 @@ public double evaluate(Collection<Agent> agentsA, Collection<Agent> agentsB) {
4849
damageToB = 0;
4950
}
5051
double evalA =
51-
(double) damageToA
52-
/ (finalAgentsA.stream()
52+
damageToA / (finalAgentsA.stream()
5353
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
5454
.sum()
5555
+ EPS);
5656
double evalB =
57-
(double) damageToB
58-
/ (finalAgentsB.stream()
57+
damageToB / (finalAgentsB.stream()
5958
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
6059
.sum()
6160
+ EPS);
@@ -74,12 +73,6 @@ private int regeneration(Collection<Agent> agents) {
7473
.mapToInt(
7574
a -> {
7675
int healed = 0;
77-
if (a.regeneratesHealth) {
78-
healed = parameters.healthRegen;
79-
}
80-
if (a.maxShieldsShifted > 0) {
81-
healed += parameters.shieldRegen;
82-
}
8376
if (a.isHealer) {
8477
healed += healables * parameters.heal;
8578
}
@@ -126,12 +119,12 @@ private void sumGroundDamage(Agent agent) {
126119
}
127120

128121
private void sumAirDamage(Agent agent) {
129-
Weapon weapon = agent.groundWeapon;
122+
Weapon weapon = agent.airWeapon;
130123
double damageToApply = calculateDamage(agent, weapon);
131-
if (agent.airWeapon.damageType == DamageType.CONCUSSIVE) {
124+
if (weapon.damageType == DamageType.CONCUSSIVE) {
132125
airConcussiveDamage += (int) damageToApply;
133126
airConcussiveHits += weapon.hits;
134-
} else if (agent.airWeapon.damageType == DamageType.EXPLOSIVE) {
127+
} else if (weapon.damageType == DamageType.EXPLOSIVE) {
135128
airExplosiveDamage += (int) damageToApply;
136129
airExplosiveHits += weapon.hits;
137130
} else {
@@ -141,23 +134,19 @@ private void sumAirDamage(Agent agent) {
141134
}
142135

143136
private double calculateDamage(Agent attacker, Weapon weapon) {
144-
double rangeFactor = 1.0 + weapon.maxRange * parameters.rangeScale;
145-
double speedFactor = 1.0 + attacker.speed * parameters.speedScale;
146-
double radialSplashFactor = weapon.splashType == SplashType.RADIAL_ENEMY_SPLASH || weapon.splashType == SplashType.RADIAL_SPLASH ? 1.0 + parameters.radialSplashFactor * weapon.innerSplashRadius : 1.0;
147-
double lineSplashFactor = weapon.splashType == SplashType.LINE_SPLASH ? 1.0 + parameters.lineSplashFactor * weapon.innerSplashRadius : 1.0;
148-
double bounceSplashFactor = weapon.splashType == SplashType.BOUNCE ? parameters.bounceSplashFactor : 1.0;
137+
double rangeFactor = weapon.maxRange * parameters.rangeScale;
138+
double speedFactor = attacker.burrowedAttacker ? 0.0 : attacker.speed * parameters.speedScale;
139+
double radialSplashFactor = weapon.splashType == SplashType.RADIAL_ENEMY_SPLASH || weapon.splashType == SplashType.RADIAL_SPLASH ? parameters.radialSplashScale * weapon.innerSplashRadius : 0.0;
140+
double lineSplashFactor = weapon.splashType == SplashType.LINE_SPLASH ? parameters.lineSplashScale * weapon.innerSplashRadius : 0.0;
141+
double bounceSplashFactor = weapon.splashType == SplashType.BOUNCE ? parameters.bounceSplashFactor : 0.0;
149142

150143
return weapon.damageShifted
151-
* rangeFactor
152-
* speedFactor
153-
* radialSplashFactor
154-
* lineSplashFactor
155-
* bounceSplashFactor
144+
* (1.0 + rangeFactor + speedFactor + radialSplashFactor + lineSplashFactor + bounceSplashFactor)
156145
/ attacker.maxCooldown;
157146
}
158147

159-
int sumDamageTo(Collection<Agent> targets) {
160-
int damageSum = 0;
148+
double sumDamageTo(Collection<Agent> targets) {
149+
double damageSum = 0;
161150
for (Agent target : targets) {
162151
if (!target.detected) {
163152
continue;
@@ -219,27 +208,23 @@ public static class Parameters {
219208
final double shieldScale;
220209
final double speedScale;
221210
final double rangeScale;
222-
final double radialSplashFactor;
223-
final double lineSplashFactor;
211+
final double radialSplashScale;
212+
final double lineSplashScale;
224213
final double bounceSplashFactor;
225-
final int heal;
226-
final int healthRegen;
227-
final int shieldRegen;
214+
final double heal;
228215

229216
public Parameters(double[] source) {
230217
shieldScale = source[0];
231218
speedScale = source[1];
232219
rangeScale = source[2];
233-
radialSplashFactor = source[3];
234-
lineSplashFactor = source[4];
220+
radialSplashScale = source[3];
221+
lineSplashScale = source[4];
235222
bounceSplashFactor = source[5];
236-
heal = (int) source[6];
237-
healthRegen = (int) source[7];
238-
shieldRegen = (int) source[8];
223+
heal = source[6] * 500000;
239224
}
240225

241226
public Parameters() {
242-
this(new double[] {62.55550402780286, 455.5108652989783, 16.644298951231356, 0.0881036657313995, 534.3720029493211, 2.2237277860926357, 506.53351985609726, 780.675841755981, 778.571115050493});
227+
this(new double[]{2.0608350462547205, 8.19938619214691, 0.19223277374228906, 7.706789576045348, 6.154650149331842, 5.884458141154542, 0.8991451082849068});
243228
}
244229
}
245230
}

src/test/java/org/bk/ass/EvaluatorParameterTuner.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
import java.util.stream.Collectors;
1717

1818
public class EvaluatorParameterTuner {
19+
private static int PARAMS = 7;
1920

2021
public static void main(String[] args) throws Exception {
2122
BWDataProvider.injectValues();
2223

2324
SplittableRandom prng = new SplittableRandom();
2425
List<Par> candidates = new ArrayList<>();
25-
int[] miss = new int[9];
26+
int[] miss = new int[PARAMS];
2627
for (int i = 0; i < 20; i++) {
27-
double[] d = new double[9];
28+
double[] d = new double[PARAMS];
2829
for (int j = 0; j < d.length; j++) {
29-
d[j] = prng.nextDouble(0.0001, 1000.0);
30+
d[j] = prng.nextDouble(0.00001, 10.0);
3031
}
3132
Par e = new Par(d);
3233
if (e.score == TEST_METHODS.length) {
@@ -36,28 +37,28 @@ public static void main(String[] args) throws Exception {
3637
candidates.add(e);
3738
}
3839
int best = 0;
39-
for (int i = 0; i < 5000000; i++) {
40+
for (int i = 0; i < 100000; i++) {
4041
int ci = prng.nextInt(candidates.size() * 12 / 10);
4142
Par sub;
4243
if (ci < candidates.size()) {
4344
Par par = candidates.get(ci);
4445

4546
int index = prng.nextInt(par.d.length);
4647

47-
sub = IntRange.of(0, 50).stream()
48+
sub = IntRange.of(0, 5).stream()
4849
.mapToObj(d -> {
4950
double[] next = Arrays.copyOf(par.d, par.d.length);
50-
next[index] = prng.nextDouble(0.0001, 1000.0);
51+
next[index] = prng.nextDouble(0.0001, 10.0);
5152
return new Par(next);
5253
}).max(Comparator.comparingInt(p -> p.score)).get();
5354
if (sub.score == par.score) {
5455
miss[index]++;
5556
continue;
5657
}
5758
} else {
58-
double[] d = new double[9];
59+
double[] d = new double[PARAMS];
5960
for (int j = 0; j < d.length; j++) {
60-
d[j] = prng.nextDouble(0.0001, 1000.0);
61+
d[j] = prng.nextDouble(0.0001, 10.0);
6162
}
6263
sub = new Par(d);
6364
}
@@ -90,7 +91,7 @@ public static void main(String[] args) throws Exception {
9091
System.exit(0);
9192

9293
Genotype<DoubleGene> genotype =
93-
Genotype.of(DoubleChromosome.of(0.0001, 20.0, 6), DoubleChromosome.of(300, 1300, 3));
94+
Genotype.of(DoubleChromosome.of(0.0001, 3.0, 6), DoubleChromosome.of(1, 1000, 1));
9495

9596
Function<Genotype<DoubleGene>, Integer> eval =
9697
gt -> {

src/test/java/org/bk/ass/EvaluatorTest.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Collections;
1212
import java.util.List;
1313
import java.util.stream.Collectors;
14+
import java.util.stream.Stream;
1415

1516
import static org.assertj.core.api.Assertions.assertThat;
1617

@@ -79,7 +80,7 @@ void _7MutasVs8Hydras() {
7980
double result = evaluator.evaluate(agentsA, agentsB);
8081

8182
// THEN
82-
assertThat(result).isGreaterThan(0.6);
83+
assertThat(result).isBetween(0.4, 0.6);
8384
}
8485

8586
@Test
@@ -133,7 +134,7 @@ void _7MutasVs14Marines() {
133134
double result = evaluator.evaluate(a, b);
134135

135136
// THEN
136-
assertThat(result).isLessThan(0.45);
137+
assertThat(result).isLessThan(0.5);
137138
}
138139

139140
@Test
@@ -155,7 +156,7 @@ void _2LurkersVs6Marines() {
155156
double result = evaluator.evaluate(a, b);
156157

157158
// THEN
158-
assertThat(result).isGreaterThan(0.7);
159+
assertThat(result).isGreaterThan(0.6);
159160
}
160161

161162
@Test
@@ -205,7 +206,7 @@ void _6MutasVs1Bunker() {
205206
double result = evaluator.evaluate(a, b);
206207

207208
// THEN
208-
assertThat(result).isGreaterThan(0.51);
209+
assertThat(result).isGreaterThan(0.5);
209210
}
210211

211212
@Test
@@ -250,7 +251,7 @@ void GoonVsTank() {
250251
double result = evaluator.evaluate(a, b);
251252

252253
// THEN
253-
assertThat(result).isGreaterThan(0.51);
254+
assertThat(result).isGreaterThan(0.5);
254255
}
255256

256257
@Test
@@ -306,7 +307,7 @@ void reaverVs12Lings() {
306307
double result = evaluator.evaluate(a, b);
307308

308309
// THEN
309-
assertThat(result).isBetween(0.2, 0.4);
310+
assertThat(result).isBetween(0.2, 0.45);
310311
}
311312

312313
@Test
@@ -321,6 +322,23 @@ void reaverVs9Lings() {
321322
double result = evaluator.evaluate(a, b);
322323

323324
// THEN
324-
assertThat(result).isBetween(0.6, 0.8);
325+
assertThat(result).isBetween(0.5, 0.8);
326+
}
327+
328+
@Test
329+
void MvsMM() {
330+
// GIVEN
331+
List<Agent> a = IntRange.of(0, 4).stream().mapToObj(unused -> factory.of(UnitType.Terran_Marine)).collect(Collectors.toList());
332+
List<Agent> b = Stream.concat(
333+
IntRange.of(0, 3).stream().mapToObj(unused -> factory.of(UnitType.Terran_Marine)),
334+
IntRange.of(0, 1).stream().mapToObj(unused -> factory.of(UnitType.Terran_Medic)))
335+
.collect(Collectors.toList());
336+
337+
338+
// WHEN
339+
double result = evaluator.evaluate(a, b);
340+
341+
// THEN
342+
assertThat(result).isLessThan(0.3);
325343
}
326344
}

src/test/java/org/bk/ass/SimulatorTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ void stimmedVsUnstimmed() {
3939
assertThat(simulator.getAgentsB()).isNotEmpty();
4040
}
4141

42+
@Test
43+
void mmVsM() {
44+
// GIVEN
45+
simulator.addAgentA(factory.of(UnitType.Terran_Marine));
46+
simulator.addAgentA(factory.of(UnitType.Terran_Marine));
47+
simulator.addAgentA(factory.of(UnitType.Terran_Marine));
48+
simulator.addAgentA(factory.of(UnitType.Terran_Marine));
49+
simulator.addAgentB(factory.of(UnitType.Terran_Marine));
50+
simulator.addAgentB(factory.of(UnitType.Terran_Marine));
51+
simulator.addAgentB(factory.of(UnitType.Terran_Medic));
52+
simulator.addAgentB(factory.of(UnitType.Terran_Medic));
53+
54+
// WHEN
55+
simulator.simulate(-1);
56+
57+
// THEN
58+
assertThat(simulator.getAgentsA()).isEmpty();
59+
assertThat(simulator.getAgentsB()).isNotEmpty();
60+
}
61+
4262
@Test
4363
void MMVsSunkens() {
4464
// GIVEN

0 commit comments

Comments
 (0)