Стабилизировать бота уровня 10 при задержках

This commit is contained in:
2026-08-18 03:33:53 +03:00
parent 6790a84d86
commit 9e418df184
4 changed files with 118 additions and 16 deletions
@@ -107,19 +107,56 @@ public final class LateLevelPlaythroughTest {
}
}
@Test
public void masteryProcessionSurvivesThrottledFinalRelayDecisions() {
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
GameDriver driver = GameDriver.withFinalRelayDelay(activity, 96L);
LevelPlaytestBot.Result result = new LevelPlaytestBot().run(
driver,
LateLevelScenarios.levelTen(),
65_000L
);
assertTrue(result.diagnostic(), result.completed());
assertEquals("throttling must not add accidental volunteers", 3, result.deaths());
assertEquals("all three intended bodies must remain", 3, result.corpseCount());
assertTrue("the conductive relay must still open the final door",
result.doorOpened());
}
}
private static final class GameDriver implements LevelPlaytestBot.Driver {
private final Instrumentation instrumentation;
private final GameView gameView;
private final long minimumDecisionMillis;
private final boolean throttleFinalRelayOnly;
private GameView.AutomationSnapshot lastSnapshot;
private GameDriver(Instrumentation instrumentation, GameView gameView) {
private GameDriver(Instrumentation instrumentation, GameView gameView,
long minimumDecisionMillis, boolean throttleFinalRelayOnly) {
this.instrumentation = instrumentation;
this.gameView = gameView;
this.minimumDecisionMillis = minimumDecisionMillis;
this.throttleFinalRelayOnly = throttleFinalRelayOnly;
}
static GameDriver from(ActivityScenario<MainActivity> activity) {
return create(activity, 32L, false);
}
static GameDriver withFinalRelayDelay(ActivityScenario<MainActivity> activity,
long minimumDecisionMillis) {
return create(activity, minimumDecisionMillis, true);
}
private static GameDriver create(ActivityScenario<MainActivity> activity,
long minimumDecisionMillis,
boolean throttleFinalRelayOnly) {
GameView[] view = new GameView[1];
activity.onActivity(current -> view[0] = current.gameViewForAutomation());
return new GameDriver(InstrumentationRegistry.getInstrumentation(), view[0]);
return new GameDriver(InstrumentationRegistry.getInstrumentation(), view[0],
minimumDecisionMillis, throttleFinalRelayOnly);
}
@Override
@@ -138,13 +175,22 @@ public final class LateLevelPlaythroughTest {
public GameView.AutomationSnapshot snapshot() {
GameView.AutomationSnapshot[] value = new GameView.AutomationSnapshot[1];
instrumentation.runOnMainSync(() -> value[0] = gameView.automationSnapshot());
return value[0];
lastSnapshot = value[0];
return lastSnapshot;
}
@Override
public void waitForNextDecision(long millis) {
try {
Thread.sleep(millis);
boolean inFinalRelayWindow = throttleFinalRelayOnly
&& lastSnapshot != null
&& lastSnapshot.levelNumber() == 10
&& lastSnapshot.deaths() == 3
&& lastSnapshot.playerX() >= 1_200f
&& lastSnapshot.playerX() <= 1_700f;
Thread.sleep(inFinalRelayWindow
? Math.max(millis, minimumDecisionMillis)
: millis);
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
throw new AssertionError("Late-level bot interrupted", interrupted);