Skip to content

Commit a9838b1

Browse files
author
Bytekeeper
committed
Some firebat related tweaks for the evaluator.
1 parent f2a054a commit a9838b1

File tree

6 files changed

+106
-11
lines changed

6 files changed

+106
-11
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "org.bk"
9-
version = "1.1"
9+
version = "1.2"
1010

1111
java {
1212
sourceCompatibility = JavaVersion.VERSION_1_8
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.bk.ass;
2+
3+
import org.bk.ass.bt.ExecutionContext;
4+
import org.bk.ass.bt.TreeNode;
5+
6+
public class StopWatch {
7+
private long started = System.nanoTime();
8+
private long stopped = Long.MIN_VALUE;
9+
10+
public long stop() {
11+
long now = System.nanoTime();
12+
if (stopped < started) {
13+
stopped = now;
14+
}
15+
return stopped;
16+
}
17+
18+
public int ms() {
19+
return (int) ((stop() - started) / 1_000_000);
20+
}
21+
22+
public void registerWith(ExecutionContext context, TreeNode node) {
23+
context.registerExecutionTime(node, ms());
24+
}
25+
}

src/main/java/org/bk/ass/sim/AgentUtil.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public static int reduceDamageByTargetSizeAndDamageType(
116116
public static void randomizePositions(Collection<Agent> agents, int ax, int ay, int bx, int by) {
117117
SplittableRandom posRnd = new SplittableRandom(1337L);
118118
for (Agent agent : agents) {
119-
agent.x = posRnd.nextInt(ax, bx - ax + 1);
120-
agent.y = posRnd.nextInt(ay, by - ay + 1);
119+
agent.x = posRnd.nextInt(ax, bx + 1);
120+
agent.y = posRnd.nextInt(ay, by + 1);
121121
}
122122
}
123123
}

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public EvalWithAgents optimizeEval(Collection<Agent> agentsA, Collection<Agent>
9393
for (Agent a : agentsA) {
9494
agentsToBeat.remove(a);
9595
EvaluationResult eval = evaluate(agentsToBeat, agentsB);
96-
if (eval.value > evalToBeat.value || eval.value == evalToBeat.value && evalToBeat == EVAL_NO_COMBAT) {
96+
if (eval.value > evalToBeat.value
97+
|| eval.value == evalToBeat.value && evalToBeat == EVAL_NO_COMBAT) {
9798
evalToBeat = eval;
9899
} else {
99100
agentsToBeat.add(a);
@@ -295,13 +296,13 @@ public Parameters(double[] source) {
295296
public Parameters() {
296297
this(
297298
new double[] {
298-
2.0608350462547205,
299-
8.19938619214691,
300-
0.19223277374228906,
301-
7.706789576045348,
302-
6.154650149331842,
303-
5.884458141154542,
304-
0.8991451082849068
299+
3.6326962940790546,
300+
6.831398819548727,
301+
0.22335278133755543,
302+
2.9421377239626465,
303+
8.546407556172563,
304+
9.522322351571518,
305+
3.0851183828490942
305306
});
306307
}
307308
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.bk.ass.bt;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.List;
6+
import java.util.concurrent.atomic.AtomicReference;
7+
import org.junit.jupiter.api.Test;
8+
9+
class ExecutionContextTest {
10+
@Test
11+
void shouldFillUpStackTrace() {
12+
// GIVEN
13+
AtomicReference<List<TreeNode>> trace = new AtomicReference<>();
14+
TreeNode leafNode =
15+
new TreeNode() {
16+
@Override
17+
public void exec() {}
18+
19+
@Override
20+
public void exec(ExecutionContext executionContext) {
21+
trace.set(executionContext.getNodeStack());
22+
}
23+
};
24+
Sequence level1Sequence = new Sequence(leafNode);
25+
Sequence sut = new Sequence(level1Sequence);
26+
27+
// WHEN
28+
sut.exec(new ExecutionContext());
29+
30+
// THEN
31+
assertThat(trace.get()).containsExactly(level1Sequence, leafNode);
32+
}
33+
}

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

+36
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,40 @@ void optimizeAwayLingsVsZealotsWithEnoughMutas() {
473473
// THEN
474474
assertThat(result.agents).allMatch(it -> it.isFlyer);
475475
}
476+
477+
@Test
478+
void _5firebatsVs9ZZealotsAreDead() {
479+
// GIVEN
480+
List<Agent> a =
481+
IntRange.of(0, 5).stream()
482+
.mapToObj(unused -> factory.of(UnitType.Terran_Firebat))
483+
.collect(Collectors.toList());
484+
List<Agent> b =
485+
IntRange.of(0, 9).stream().mapToObj(unused -> factory.of(UnitType.Protoss_Zealot))
486+
.collect(Collectors.toList());
487+
488+
// WHEN
489+
EvaluationResult result = evaluator.evaluate(a, b);
490+
491+
// THEN
492+
assertThat(result.value).isLessThan(0.2);
493+
}
494+
495+
@Test
496+
void _9firebatsVs9ZZealotsAreEvenlyMatched() {
497+
// GIVEN
498+
List<Agent> a =
499+
IntRange.of(0, 9).stream()
500+
.mapToObj(unused -> factory.of(UnitType.Terran_Firebat))
501+
.collect(Collectors.toList());
502+
List<Agent> b =
503+
IntRange.of(0, 9).stream().mapToObj(unused -> factory.of(UnitType.Protoss_Zealot))
504+
.collect(Collectors.toList());
505+
506+
// WHEN
507+
EvaluationResult result = evaluator.evaluate(a, b);
508+
509+
// THEN
510+
assertThat(result.value).isBetween(0.4, 0.6);
511+
}
476512
}

0 commit comments

Comments
 (0)