test(compare): trace scenario action effects
This commit is contained in:
@@ -120,6 +120,19 @@ function comparisonRunBattle(array $fixture): array
|
|||||||
$rawAttackerNation = $fixture['attackerNation'];
|
$rawAttackerNation = $fixture['attackerNation'];
|
||||||
$rawDefenderCity = $fixture['defenderCity'];
|
$rawDefenderCity = $fixture['defenderCity'];
|
||||||
$rawDefenderNation = $fixture['defenderNation'];
|
$rawDefenderNation = $fixture['defenderNation'];
|
||||||
|
// 비교 fixture에 명시된 경우에만 ref runtime의 scenario action chain을
|
||||||
|
// 활성화합니다. 일반 비교 fixture의 기존 동작은 그대로 유지합니다.
|
||||||
|
$scenarioEffect = $fixture['scenarioEffect'] ?? null;
|
||||||
|
if ($scenarioEffect === '' || $scenarioEffect === 'None') {
|
||||||
|
$scenarioEffect = null;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$scenarioEffect !== null
|
||||||
|
&& (!is_string($scenarioEffect) || getScenarioEffectClass($scenarioEffect) === null)
|
||||||
|
) {
|
||||||
|
throw new \InvalidArgumentException('scenarioEffect is invalid');
|
||||||
|
}
|
||||||
|
GameConst::$scenarioEffect = $scenarioEffect;
|
||||||
|
|
||||||
$tracingRng = new ComparisonTracingRNG(new LiteHashDRBG($seed));
|
$tracingRng = new ComparisonTracingRNG(new LiteHashDRBG($seed));
|
||||||
$warRng = new RandUtil($tracingRng);
|
$warRng = new RandUtil($tracingRng);
|
||||||
@@ -182,6 +195,17 @@ function comparisonRunBattle(array $fixture): array
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$attackerLogs = $attacker->getLogger()->rollback();
|
||||||
|
$defenderLogs = [];
|
||||||
|
foreach ($defenderList as $defenderUnit) {
|
||||||
|
if (!($defenderUnit instanceof WarUnitGeneral)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$snapshot = buildWarTraceUnitSnapshot($defenderUnit);
|
||||||
|
$defenderLogs[(string)$snapshot['id']] = $defenderUnit->getLogger()->rollback();
|
||||||
|
}
|
||||||
|
$cityLogs = $city->getLogger()->rollback();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'engine' => 'ref',
|
'engine' => 'ref',
|
||||||
'seed' => $seed,
|
'seed' => $seed,
|
||||||
@@ -191,6 +215,11 @@ function comparisonRunBattle(array $fixture): array
|
|||||||
'finishedDefenders' => $finishedDefenders,
|
'finishedDefenders' => $finishedDefenders,
|
||||||
'events' => $events,
|
'events' => $events,
|
||||||
'rng' => $tracingRng->calls,
|
'rng' => $tracingRng->calls,
|
||||||
|
'logs' => [
|
||||||
|
'attacker' => $attackerLogs,
|
||||||
|
'defenders' => $defenderLogs,
|
||||||
|
'city' => $cityLogs,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,21 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void
|
|||||||
}
|
}
|
||||||
UniqueConst::$hiddenSeed = $hiddenSeed;
|
UniqueConst::$hiddenSeed = $hiddenSeed;
|
||||||
}
|
}
|
||||||
|
// 비교 fixture는 전역 상태에 의존하지 않도록 effect 기본값을 null로 고정하고,
|
||||||
|
// 명시된 경우에만 해당 effect를 활성화합니다.
|
||||||
|
GameConst::$scenarioEffect = null;
|
||||||
|
if (array_key_exists('scenarioEffect', $world)) {
|
||||||
|
$scenarioEffect = $world['scenarioEffect'];
|
||||||
|
if ($scenarioEffect === '' || $scenarioEffect === 'None') {
|
||||||
|
$scenarioEffect = null;
|
||||||
|
}
|
||||||
|
if ($scenarioEffect !== null) {
|
||||||
|
if (!is_string($scenarioEffect) || getScenarioEffectClass($scenarioEffect) === null) {
|
||||||
|
throw new \InvalidArgumentException('setup.world.scenarioEffect is invalid');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameConst::$scenarioEffect = $scenarioEffect;
|
||||||
|
}
|
||||||
if (array_key_exists('staticEventHandlers', $world)) {
|
if (array_key_exists('staticEventHandlers', $world)) {
|
||||||
$handlersByEvent = $world['staticEventHandlers'];
|
$handlersByEvent = $world['staticEventHandlers'];
|
||||||
if (!is_array($handlersByEvent)) {
|
if (!is_array($handlersByEvent)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user