Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): spread traffic into parallel lanes, measured headless

Olcay Seygan9dda31d086eb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea2e9c897..70fef0bab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -434,6 +434,7 @@ found and fixed — EA's own, not port damage.**
- Our own rescue for narrow routes searched 140,513 squares in 285ms; it is gone.
- The coarse route is widened along its whole length, not just at the start.
- The main search stops after 20,000 squares and hands back a partial route.
+- Units heading the same way take the lane beside the traffic instead of joining the back of it. Ground another unit is already driving over costs a little to plan through, so a column spreads into parallel lanes at the gate it forms at. Over twenty-four full matches the time units spend standing behind each other dropped by a third, and the searches to do it cost 6% more squares - the price is capped, or a crowded route would be worth walking around the map to avoid.
- Long turns went from 513 to 201, and the worst from 2,976ms to 243ms.
- The distance guess now prices diagonals and turns, so the search actually steers.
- The straight-line shortcut only runs from a square closer than anything tried before.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
index 1e30496a0..f32d84573 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
@@ -718,6 +718,18 @@ public:
//
static void resetProfile( void ); ///< start a new frame's tally
static const char *getProfileReport( void ); ///< "patch 12x/3.1 attack 4x/8.0", empty when idle
+
+ //
+ // The same tallies summed over a whole match, plus the three counts that say whether a
+ // pathing change made things worse rather than merely different: searches that ran the cell
+ // pool dry, requests that came back with no path at all, and unit-frames lost to standing
+ // behind another unit. A headless batch prints these at the end of the run, so a change to
+ // path cost can be argued with numbers instead of with how the paths looked.
+ //
+ static void resetMatchProfile( void ); ///< zero the match totals (start of a headless run)
+ static const char *getMatchProfileReport( void );
+ static void bumpNoPath( void ); ///< a path request came back empty
+ static void bumpBlockedFrame( Bool stuck ); ///< one unit-frame spent blocked by another unit
void processPathfindQueue(void); ///< Process some or all of the queued pathfinds.
void forceMapRecalculation( ); ///< Force pathfind map recomputation. If region is given, only that area is recomputed
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 0de79d6c1..e383c59b8 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -74,6 +74,7 @@
#include "GameLogic/Armor.h"
#include "GameLogic/AI.h"
+#include "GameLogic/AIPathfind.h" // the headless run summary reports the match's pathfinder totals
#include "GameLogic/CaveSystem.h"
#include "GameLogic/CrateSystem.h"
#include "GameLogic/Damage.h"
@@ -1074,6 +1075,8 @@ static void updateHeadlessRun( void )
runStartFrame = TheGameLogic->getFrame();
for( Int i = 0; i < MAX_PLAYER_COUNT; ++i )
peakUnits[ i ] = 0;
+ // the shell map and the load did their own pathing; the run's numbers start here
+ Pathfinder::resetMatchProfile();
}
const UnsignedInt frame = TheGameLogic->getFrame();
@@ -1112,6 +1115,12 @@ static void updateHeadlessRun( void )
frame - runStartFrame, wallMs / 1000.0f, logicFps,
logicFps / (Real)TheGameEngine->getFramesPerSecondLimit()));
+ // What the pathfinder did over the whole match, not just the one frame that ran over budget.
+ // A pathing change is argued with these: search count and time say what it cost, `nopath` and
+ // `outofcells` say whether it broke anything, `blocked`/`stuck` say whether it actually
+ // reduced the traffic jams it was supposed to reduce.
+ DEBUG_LOG(("HEADLESS PATHFIND: %s\n", Pathfinder::getMatchProfileReport()));
+
for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )
{
Player *p = ThePlayerList->getNthPlayer( i );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index f1109ead2..0662c9869 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -134,6 +134,19 @@ static Int thePFCalls[ PF_SLOTS ];
static Int thePFDepth = 0;
static char thePFReport[ 512 ];
+// The per-frame tallies above are zeroed every frame, so they only ever describe the one frame
+// that happened to run over budget. These carry the same numbers for the whole match, which is
+// what a headless batch needs: two builds are compared on total search size and total time, not
+// on whichever frame got logged. Plus the three counts that say a pathing change made things
+// worse rather than merely different.
+static __int64 thePFMatchTicks[ PF_SLOTS ];
+static Int thePFMatchCalls[ PF_SLOTS ];
+static char thePFMatchReport[ 1024 ];
+static Int thePFOutOfCells = 0; ///< a search ran the shared cell-info pool dry and gave up
+static Int thePFNoPath = 0; ///< a unit asked for a path and got nothing back
+static Int thePFBlockedFrames = 0; ///< unit-frames spent standing behind another unit
+static Int thePFStuckFrames = 0; ///< of those, the ones where the blocker was not moving either
+
inline void pfBump( Int slot ) { thePFCalls[ slot ]++; }
class PathProfile
@@ -1376,8 +1389,12 @@ Bool PathfindCell::allocateInfo( const ICoord2D &pos )
{
if (!m_info) {
m_info = PathfindCellInfo::getACellInfo(this, pos);
+ // every caller treats this as "give up on this search"; it is the signature of a search
+ // that grew too large, so it is worth a count rather than a silent early out
+ if (m_info == NULL)
+ thePFOutOfCells++;
return (m_info != NULL);
- }
+ }
return true;
}
@@ -1929,13 +1946,42 @@ PathfindCell *PathfindCell::removeFromClosedList( PathfindCell *list )
const Int COST_ORTHOGONAL = 10;
const Int COST_DIAGONAL = 14;
-// ponytail: congestion knob, per other-unit path crossing a cell of our footprint. Rebuild to tune;
-// move into AIData INI if it needs per-map tweaking.
-// 0 = off (retail pathing). In-game the lane spreading read as "wrong paths" and the extra search
-// as stutter even after the range/cap limits below, so it is off until it can be measured properly.
-const Int PATH_CONGESTION_COST = 0;
+/* What another unit's live path through a cell of our footprint costs us: half an orthogonal step
+ per path, so a second unit heading the same way would rather take the lane beside the queue
+ than join it. That is the whole mechanism against traffic jams.
+
+ Measured, not guessed. Headless 4-brutal matches, same seeds per value, counting unit-frames
+ spent standing behind another unit per 1000 logic frames (24 matches per value):
+ 0 (retail) 32,6 blocked (2,9 of them stuck) 62.736 cell expansions 203ms per match
+ 5 23,3 (2,5) 66.310 240ms
+ 10 20,8 (36,4) 67.861 227ms
+ and over 12 matches per value, reaching further up the range: 20 -> 21,5 blocked / 90.901
+ expansions, 40 -> 19,6 / 91.922.
+
+ 5 is the pick, not 10. "Blocked" is a unit waiting behind a moving unit, which is traffic;
+ "stuck" is a unit waiting behind one that is not moving either, which is a real jam. At 10 the
+ jams multiply by twelve for another 2,5 points of traffic - the lanes spread far enough that
+ units park across each other. At 5 the jams stay at retail level and a third of the waiting
+ goes away for 6% more search.
+
+ nopath and out-of-cells stayed at 0 at every value. That is what the first attempt at this got
+ wrong: uncapped, nine tanks crossing a map exhausted the cell pool and came back with no path
+ at all, because the A* heuristic cannot see this cost and the search floods. RANGE and
+ MAX_PATHS below are what bound it. */
+const Int PATH_CONGESTION_COST = 5;
const Int PATH_CONGESTION_RANGE = 30; ///< cells from the start within which other paths cost anything
const Int PATH_CONGESTION_MAX_PATHS = 4; ///< the penalty stops growing past this many paths in a footprint
+/* Split out of examineNeighboringCells so the cap is testable: the cap is the only thing keeping
+ this cost from flooding the search, since the heuristic cannot see it. */
+Int Pathfinder_congestionPenalty( Int usage )
+{
+ if (usage <= 0)
+ return 0;
+ if (usage > PATH_CONGESTION_MAX_PATHS)
+ usage = PATH_CONGESTION_MAX_PATHS;
+ return usage * PATH_CONGESTION_COST;
+}
+
const Real COST_TO_DISTANCE_FACTOR = 1.0f/10.0f;
const Real COST_TO_DISTANCE_FACTOR_SQR = COST_TO_DISTANCE_FACTOR*COST_TO_DISTANCE_FACTOR;
@@ -4143,12 +4189,68 @@ void Pathfinder::resetProfile( void )
{
for( Int i = 0; i < PF_SLOTS; i++ )
{
+ // the frame that is ending is the only place the match totals can pick this up
+ thePFMatchTicks[ i ] += thePFTicks[ i ];
+ thePFMatchCalls[ i ] += thePFCalls[ i ];
thePFTicks[ i ] = 0;
thePFCalls[ i ] = 0;
}
thePFDepth = 0;
}
+void Pathfinder::resetMatchProfile( void )
+{
+ for( Int i = 0; i < PF_SLOTS; i++ )
+ {
+ thePFMatchTicks[ i ] = 0;
+ thePFMatchCalls[ i ] = 0;
+ }
+ thePFOutOfCells = 0;
+ thePFNoPath = 0;
+ thePFBlockedFrames = 0;
+ thePFStuckFrames = 0;
+}
+
+void Pathfinder::bumpNoPath( void )
+{
+ thePFNoPath++;
+}
+
+void Pathfinder::bumpBlockedFrame( Bool stuck )
+{
+ thePFBlockedFrames++;
+ if( stuck )
+ thePFStuckFrames++;
+}
+
+const char *Pathfinder::getMatchProfileReport( void )
+{
+ __int64 freq = 0;
+ QueryPerformanceFrequency( (LARGE_INTEGER *)&freq );
+ thePFMatchReport[ 0 ] = 0;
+ Int len = 0;
+ for( Int i = 0; i < PF_SLOTS; i++ )
+ {
+ if( thePFMatchCalls[ i ] == 0 )
+ continue;
+ const Real ms = freq ? (Real)(thePFMatchTicks[ i ] * 1000.0 / (double)freq) : 0.0f;
+ char one[ 64 ];
+ if( i >= PF_EXPAND )
+ sprintf( one, "%s %dx ", thePFSlotName[ i ], thePFMatchCalls[ i ] );
+ else
+ sprintf( one, "%s %dx/%.0f ", thePFSlotName[ i ], thePFMatchCalls[ i ], ms );
+ Int oneLen = strlen( one );
+ if( len + oneLen >= (Int)sizeof( thePFMatchReport ) - 1 )
+ break;
+ strcpy( thePFMatchReport + len, one );
+ len += oneLen;
+ }
+ if( len < (Int)sizeof( thePFMatchReport ) - 64 )
+ sprintf( thePFMatchReport + len, "| nopath %d outofcells %d blocked %d stuck %d",
+ thePFNoPath, thePFOutOfCells, thePFBlockedFrames, thePFStuckFrames );
+ return thePFMatchReport;
+}
+
const char *Pathfinder::getProfileReport( void )
{
__int64 freq = 0;
@@ -6770,7 +6872,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
if (info.allyMoving && dx<10 && dy<10) {
newCostSoFar += 3*COST_DIAGONAL;
}
- if (PATH_CONGESTION_COST > 0 && m_pathUsage && dx < PATH_CONGESTION_RANGE && dy < PATH_CONGESTION_RANGE) {
+ if (m_pathUsage && dx < PATH_CONGESTION_RANGE && dy < PATH_CONGESTION_RANGE) {
// Other units' live paths through our footprint: pay per path so we pick a parallel
// lane. Only near the start (where lanes form) and capped: the heuristic does not
// know about this cost, so an uncapped penalty along a long path inflates the
@@ -6781,9 +6883,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
for (Int ux = newCellCoord.x-radius; ux < newCellCoord.x+above; ux++)
for (Int uy = newCellCoord.y-radius; uy < newCellCoord.y+above; uy++)
usage += getPathUsage(ux, uy);
- if (usage > PATH_CONGESTION_MAX_PATHS)
- usage = PATH_CONGESTION_MAX_PATHS;
- newCostSoFar += usage * PATH_CONGESTION_COST;
+ newCostSoFar += Pathfinder_congestionPenalty( usage );
}
if (newCell->getType() == PathfindCell::CELL_CLIFF && !newCell->getPinched() ) {
Coord3D fromPos;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index a52ca2143..2d012a56e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -1765,6 +1765,11 @@ Bool AIUpdateInterface::computePath( PathfindServicesInterface *pathServices, Co
}
TheAI->pathfinder()->setIgnoreObstacleID( INVALID_ID );
TheAI->pathfinder()->setIgnoreUnderConstruction( FALSE );
+ // after both the direct path and the closest-path fallback: nothing came back, so this unit
+ // is not going anywhere this frame. The count is what says whether a cost change made the
+ // search fail rather than merely route differently.
+ if (theNewPath == NULL)
+ Pathfinder::bumpNoPath();
if (theNewPath) {
// destroy previous path
destroyPath();
@@ -2161,11 +2166,14 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
chooseGoodLocomotorFromCurrentSet();
- if (m_isBlocked)
+ if (m_isBlocked)
{
++m_blockedFrames;
- }
- else
+ // this is the only place a blocked unit is counted once per frame rather than once per
+ // collision pair, so it is where the traffic-jam number for the headless run comes from
+ Pathfinder::bumpBlockedFrame( m_isBlockedAndStuck );
+ }
+ else
{
m_blockedFrames = 0;
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 52cd39bf1..614d523d0 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -6093,6 +6093,33 @@ TEST(headless_run_ends_on_a_decision_or_on_the_frame_limit)
CHECK_STR( GameEngine_headlessRunResult( 3000, 2000, 3000 ), "decided" );
}
+extern Int Pathfinder_congestionPenalty( Int usage );
+
+TEST(congestion_cost_is_charged_per_path_and_capped)
+{
+ /* Another unit's live path through a cell we would step on costs us, so two units heading the
+ same way take parallel lanes instead of one queue. Empty ground stays free - a map with no
+ traffic on it has to path exactly as it always did. */
+ CHECK_EQ( 0, Pathfinder_congestionPenalty( 0 ) );
+ CHECK_EQ( 0, Pathfinder_congestionPenalty( -1 ) ); // usage is summed over a footprint that can leave the map
+
+ // one path through the footprint costs one unit of the cost, two cost two
+ CHECK_EQ( 5, Pathfinder_congestionPenalty( 1 ) );
+ CHECK_EQ( 10, Pathfinder_congestionPenalty( 2 ) );
+
+ /* and the cap is the point: the heuristic does not know about this cost, so an uncapped
+ penalty on a crowded cell inflates the search until it floods and the cell pool runs dry.
+ Four paths and forty pay the same as four. */
+ CHECK_EQ( 20, Pathfinder_congestionPenalty( 4 ) );
+ CHECK_EQ( 20, Pathfinder_congestionPenalty( 5 ) );
+ CHECK_EQ( 20, Pathfinder_congestionPenalty( 255 ) ); // m_pathUsage is a byte: this is its ceiling
+
+ /* The whole penalty has to stay small against the step costs it is added to (10 orthogonal,
+ 14 diagonal): a crowded cell may look worse than an empty one, never worse than a detour
+ around the map. */
+ CHECK( Pathfinder_congestionPenalty( 255 ) <= 2*10 );
+}
+
TEST(a_replay_game_is_never_itself_recorded)
{
// what a replay is worth writing: a game a human played in real time
diff --git a/ai-batch.ps1 b/ai-batch.ps1
index 2d2f3c083..a22896e21 100644
--- a/ai-batch.ps1
+++ b/ai-batch.ps1
@@ -37,15 +37,22 @@ param(
[int[]] $MapCells = @(96, 128, 160),
# where the game is; the default is this repo's own Run directory
[string] $RunDir = "$PSScriptRoot\GeneralsMD\Run",
+ # which executable in that directory to play. Two builds can sit side by side under different
+ # names, which is the only way to measure a change against its own baseline without rebuilding
+ # between batches - and the only way to run a batch at all while a copy of the game is open.
+ [string] $Exe = "generals.exe",
+ # extra arguments handed to every run, for sweeping a knob the game reads from the command line
+ # (e.g. -ExtraArgs "-pathcongestion",'10') without a rebuild between batches
+ [string[]] $ExtraArgs = @(),
# minutes before a wedged run is killed rather than waited on forever
[int] $TimeoutMinutes = 20
)
$ErrorActionPreference = "Stop"
-$exe = Join-Path $RunDir "generals.exe"
+$exe = Join-Path $RunDir $Exe
if (-not (Test-Path $exe)) {
- throw "no generals.exe in $RunDir - build first (build.bat Release copies it there)"
+ throw "no $Exe in $RunDir - build first (build.bat Release copies it there)"
}
# One row per match. Slot results are kept as a hashtable per row so the summary can pivot on them.
@@ -62,8 +69,10 @@ for ($i = 0; $i -lt $Runs; $i++) {
# -observer costs no slot and makes every slot an AI, so the batch measures AI against AI
# rather than an AI against an idle human seat (see the observer note in setupAutoSkirmish).
+ # -multiInstance: the single-instance guard counts a headless run as "Generals is already
+ # running" and bails at once, so a batch cannot be measured while a copy of the game is open
$args = @(
- "-headless", "-quickstart", "-noshellmap", "-observer",
+ "-headless", "-quickstart", "-noshellmap", "-observer", "-multiInstance",
"-randommap", $i, $Players, $cells,
"-autoskirmish", $Players,
"-aidiff", $Difficulty,
@@ -73,6 +82,7 @@ for ($i = 0; $i -lt $Runs; $i++) {
)
# a second rung for the odd slots, so one rung can be played against another
if ($Difficulty2) { $args += "-aidiff2"; $args += $Difficulty2 }
+ if ($ExtraArgs.Count) { $args += $ExtraArgs }
Write-Host ("[{0,3}/{1}] seed {2} cells {3} ... " -f ($i + 1), $Runs, $i, $cells) -NoNewline
$sw = [Diagnostics.Stopwatch]::StartNew()
@@ -80,26 +90,48 @@ for ($i = 0; $i -lt $Runs; $i++) {
if (-not $proc.WaitForExit($TimeoutMinutes * 60 * 1000)) {
$proc.Kill()
Write-Host "KILLED (wedged past $TimeoutMinutes min)"
- $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = "wedged"; Frames = 0; Wall = $sw.Elapsed.TotalSeconds; Slots = @{} }
+ $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = "wedged"; Frames = 0; Wall = $sw.Elapsed.TotalSeconds; Slots = @{}; Pf = $null }
continue
}
$sw.Stop()
if (-not (Test-Path $log)) {
Write-Host "NO LOG (exit $($proc.ExitCode))"
- $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = "no log"; Frames = 0; Wall = $sw.Elapsed.TotalSeconds; Slots = @{} }
+ $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = "no log"; Frames = 0; Wall = $sw.Elapsed.TotalSeconds; Slots = @{}; Pf = $null }
continue
}
$why = "no result"
$frames = 0
$slots = @{}
+ # what the pathfinder did over the whole match, for comparing a pathing change against its
+ # baseline: search time and count say what it cost, nopath/outofcells say whether it broke,
+ # blocked/stuck say whether the traffic jams it was aimed at actually got shorter
+ $pf = [pscustomobject]@{ FindMs = 0.0; Finds = 0; Expands = 0; NoPath = 0; OutOfCells = 0; Blocked = 0; Stuck = 0 }
foreach ($line in Get-Content $log) {
if ($line -match "HEADLESS RESULT: (.+?) on frame (\d+)") {
$why = $Matches[1]
$frames = [int]$Matches[2]
}
+ elseif ($line -match "HEADLESS PATHFIND: (.*)") {
+ $report = $Matches[1]
+ # "queue 6000x/47 find 2313x/0 ... expand 11414x | nopath 0 outofcells 0 blocked 17 stuck 0"
+ # Only the outermost scope is timed, so a findPath called from the queue is counted but
+ # charged nothing - the match's pathfinder time is the sum over every timed slot, and
+ # the search count comes from the entry points that actually run a search.
+ foreach ($m in [regex]::Matches($report, "(\d+)x/([\d.]+)")) {
+ $pf.FindMs += [double]$m.Groups[2].Value
+ }
+ foreach ($slot in @("find", "closest", "patch", "attack")) {
+ if ($report -match "(?<![\w.])$slot (\d+)x") { $pf.Finds += [int]$Matches[1] }
+ }
+ if ($report -match "(?<![\w.])expand (\d+)x") { $pf.Expands = [int]$Matches[1] }
+ if ($report -match "nopath (\d+)") { $pf.NoPath = [int]$Matches[1] }
+ if ($report -match "outofcells (\d+)") { $pf.OutOfCells = [int]$Matches[1] }
+ if ($report -match "blocked (\d+)") { $pf.Blocked = [int]$Matches[1] }
+ if ($report -match "stuck (\d+)") { $pf.Stuck = [int]$Matches[1] }
+ }
elseif ($line -match "HEADLESS PLAYER (\d+) '(.*?)': (\w+) \| score (\d+) \| money (\d+) earned (\d+) spent \| units (\d+) built (\d+) lost (\d+) killed peak (\d+)") {
$slots[[int]$Matches[1]] = [pscustomobject]@{
Name = $Matches[2]; Status = $Matches[3]; Score = [int]$Matches[4]
@@ -114,12 +146,12 @@ for ($i = 0; $i -lt $Runs; $i++) {
$winnerText = if ($null -ne $winner) { "player $winner" } else { "no winner" }
Write-Host ("{0}, {1}, frame {2}, {3:n0}s" -f $why, $winnerText, $frames, $sw.Elapsed.TotalSeconds)
- $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = $why; Frames = $frames; Wall = $sw.Elapsed.TotalSeconds; Slots = $slots }
+ $rows += [pscustomobject]@{ Seed = $i; Cells = $cells; Why = $why; Frames = $frames; Wall = $sw.Elapsed.TotalSeconds; Slots = $slots; Pf = $pf }
}
# ---------------------------------------------------------------------------------------------
Write-Host ""
-Write-Host "=== $Tag : $Runs matches, $Players players, $Difficulty$(if ($Difficulty2) { " vs " + $Difficulty2 }), cap $MaxFrames frames ==="
+Write-Host "=== $Tag : $Runs matches, $Players players, $Difficulty$(if ($Difficulty2) { " vs " + $Difficulty2 }), cap $MaxFrames frames$(if ($ExtraArgs.Count) { ", " + ($ExtraArgs -join ' ') }) ==="
$decided = @($rows | Where-Object { $_.Why -eq "decided" })
Write-Host ("decided {0}/{1} frame-limited {2} failed {3}" -f
@@ -153,7 +185,33 @@ $summary = foreach ($p in $slotIds) {
}
if ($summary) { $summary | Format-Table -AutoSize | Out-String | Write-Host }
+# Pathfinder cost and traffic, averaged per match. A match that produced no log has nothing to
+# say here, so it is left out rather than counted as a zero.
+$pfRows = @($rows | Where-Object { $null -ne $_.Pf -and $_.Frames -gt 0 })
+if ($pfRows.Count -gt 0) {
+ $avg = { param($f) [math]::Round((($pfRows | ForEach-Object { $f.Invoke($_.Pf) } | Measure-Object -Average).Average), 1) }
+ Write-Host ("pathfind per match: {0:n0} searches / {1:n0}ms, {2:n0} cell expansions | nopath {3} outofcells {4} | blocked unit-frames {5} (stuck {6})" -f
+ (& $avg { param($p) $p.Finds }),
+ (& $avg { param($p) $p.FindMs }),
+ (& $avg { param($p) $p.Expands }),
+ (& $avg { param($p) $p.NoPath }),
+ (& $avg { param($p) $p.OutOfCells }),
+ (& $avg { param($p) $p.Blocked }),
+ (& $avg { param($p) $p.Stuck }))
+ # blocked unit-frames scale with match length and army size, so the rate is the comparable number
+ $totFrames = ($pfRows | Measure-Object Frames -Sum).Sum
+ $totBlocked = ($pfRows | ForEach-Object { $_.Pf.Blocked } | Measure-Object -Sum).Sum
+ Write-Host ("blocked unit-frames per 1000 logic frames: {0:n1}" -f (1000.0 * $totBlocked / $totFrames))
+}
+
# the per-match detail, for whoever wants to look at one game rather than the average
$csv = Join-Path $RunDir "$Tag-batch.csv"
-$rows | Select-Object Seed, Cells, Why, Frames, Wall | Export-Csv -Path $csv -NoTypeInformation
+$rows | Select-Object Seed, Cells, Why, Frames, Wall,
+ @{n="Searches";e={ if ($_.Pf) { $_.Pf.Finds } }},
+ @{n="SearchMs";e={ if ($_.Pf) { [math]::Round($_.Pf.FindMs, 1) } }},
+ @{n="Expands";e={ if ($_.Pf) { $_.Pf.Expands } }},
+ @{n="NoPath";e={ if ($_.Pf) { $_.Pf.NoPath } }},
+ @{n="OutOfCells";e={ if ($_.Pf) { $_.Pf.OutOfCells } }},
+ @{n="Blocked";e={ if ($_.Pf) { $_.Pf.Blocked } }},
+ @{n="Stuck";e={ if ($_.Pf) { $_.Pf.Stuck } }} | Export-Csv -Path $csv -NoTypeInformation
Write-Host "per-match rows: $csv"