Use streams for raise dead filter output (#7585)

This commit is contained in:
2026-06-21 13:12:03 -07:00
committed by GitHub
parent 1ca9e8678c
commit e8b18d0805
@@ -5,6 +5,8 @@
#include <gtest/gtest.h>
#include <filesystem>
#include <iostream>
#include <sstream>
#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
#include "src/main/cpp/net/eagle0/shardok/ai/AICommandFilter.hpp"
@@ -730,28 +732,25 @@ TEST_F(MCTSSetupPhaseTest, ExactRaiseDeadReproduction) {
// Check for RAISE_DEAD commands before running AI
const auto preCheckCommands = engine->GetAvailableCommandsForAIPlayer(attackerPlayerId);
int raiseDeadCountBefore = 0;
printf("Checking %zu total commands for player %d\n",
preCheckCommands->size(),
attackerPlayerId);
std::ostringstream filterSummary;
filterSummary << "Checking " << preCheckCommands->size() << " total commands for player "
<< attackerPlayerId << '\n';
for (size_t i = 0; i < preCheckCommands->size(); ++i) {
auto cmdType = (*preCheckCommands)[i]->GetCommandType();
if (cmdType == net::eagle0::shardok::common::CommandType::RAISE_DEAD_COMMAND) {
raiseDeadCountBefore++;
printf("Found RAISE_DEAD command #%d\n", raiseDeadCountBefore);
filterSummary << "Found RAISE_DEAD command #" << raiseDeadCountBefore << '\n';
}
}
printf("Total RAISE_DEAD commands available: %d\n\n", raiseDeadCountBefore);
filterSummary << "Total RAISE_DEAD commands available: " << raiseDeadCountBefore << "\n\n";
// Test command filtering
printf("=== Testing Command Filter ===\n");
printf("State units before AI runs:\n");
filterSummary << "=== Testing Command Filter ===\n"
<< "State units before AI runs:\n";
for (unsigned int i = 0; i < engine->GetCurrentGameState()->units()->size() && i < 6; ++i) {
const auto* u = engine->GetCurrentGameState()->units()->Get(i);
printf(" Unit %u: AP=%d, pos=(%d,%d)\n",
i,
u->remaining_action_points(),
u->location().row(),
u->location().column());
filterSummary << " Unit " << i << ": AP=" << u->remaining_action_points() << ", pos=("
<< u->location().row() << ',' << u->location().column() << ")\n";
}
auto testAPDCache = std::make_shared<ActionPointDistancesCache>();
const auto filteredIndices = AICommandFilter::FilterCommands(
@@ -763,9 +762,8 @@ TEST_F(MCTSSetupPhaseTest, ExactRaiseDeadReproduction) {
[this](net::eagle0::shardok::storage::fb::BattalionTypeId typeId) {
return settings->GetGetter().GetBattalionType(typeId);
});
printf("After filtering: %zu commands (from %zu total)\n",
filteredIndices.size(),
preCheckCommands->size());
filterSummary << "After filtering: " << filteredIndices.size() << " commands (from "
<< preCheckCommands->size() << " total)\n";
int raiseDeadAfterFilter = 0;
for (size_t idx : filteredIndices) {
if ((*preCheckCommands)[idx]->GetCommandType() ==
@@ -773,7 +771,8 @@ TEST_F(MCTSSetupPhaseTest, ExactRaiseDeadReproduction) {
raiseDeadAfterFilter++;
}
}
printf("RAISE_DEAD commands after filter: %d\n\n", raiseDeadAfterFilter);
filterSummary << "RAISE_DEAD commands after filter: " << raiseDeadAfterFilter << "\n\n";
std::cout << filterSummary.str();
// Run AI and see what it chooses
const auto choiceResults = attackerAI.ChooseCommandIndex(*engine);
@@ -782,17 +781,21 @@ TEST_F(MCTSSetupPhaseTest, ExactRaiseDeadReproduction) {
ASSERT_LT(choiceResults.chosenIndex, commands->size());
const auto& chosenCommand = (*commands)[choiceResults.chosenIndex];
printf("AI chose command type: %d\n", static_cast<int>(chosenCommand->GetCommandType()));
std::ostringstream choiceSummary;
choiceSummary << "AI chose command type: " << static_cast<int>(chosenCommand->GetCommandType())
<< '\n';
// Check if RAISE_DEAD was chosen
if (chosenCommand->GetCommandType() ==
net::eagle0::shardok::common::CommandType::RAISE_DEAD_COMMAND) {
printf("*** RAISE_DEAD REPRODUCED! Check /tmp/mcts_raise_dead_reproduction.txt ***\n");
printf("This confirms the behavior from original gameplay.\n");
choiceSummary << "*** RAISE_DEAD REPRODUCED! Check "
"/tmp/mcts_raise_dead_reproduction.txt ***\n"
<< "This confirms the behavior from original gameplay.\n";
} else {
printf("AI chose different command (type %d instead of RAISE_DEAD)\n",
static_cast<int>(chosenCommand->GetCommandType()));
printf("Check /tmp/mcts_raise_dead_reproduction.txt for decision tree\n");
choiceSummary << "AI chose different command (type "
<< static_cast<int>(chosenCommand->GetCommandType())
<< " instead of RAISE_DEAD)\n"
<< "Check /tmp/mcts_raise_dead_reproduction.txt for decision tree\n";
}
// Log available RAISE_DEAD commands
@@ -803,7 +806,8 @@ TEST_F(MCTSSetupPhaseTest, ExactRaiseDeadReproduction) {
raiseDeadCount++;
}
}
printf("Available RAISE_DEAD commands: %d\n", raiseDeadCount);
choiceSummary << "Available RAISE_DEAD commands: " << raiseDeadCount << '\n';
std::cout << choiceSummary.str();
}
} // namespace shardok