mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 20:55:44 +00:00
Performance test (#4275)
* missing dep * cleanup * Add AI Performance Runner implementation plan Create comprehensive plan for automated AI performance testing tool that replicates the manual "Perf" button testing from Unity client. The tool will provide reproducible performance measurements without requiring client interaction. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * slow progress * getting there * it runs * it runs * fully runs * fully runs * omg is it working * removed a lot of loggin * summary data * Update AI performance runner to use CommandChoiceResults metrics - Replace timing-based metrics with search depth and evaluation counts - Use CommandChoiceResults returned by ShardokAIClient methods - Display key performance metrics: depth achieved, commands evaluated vs available - Calculate average search depth and evaluation rate across turns - Show turn-by-turn breakdown with command types chosen - Remove obsolete timing measurements in favor of AI budget-based metrics 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add evaluation rate by depth analysis - Replace meaningless average evaluation rate with depth-specific rates - Show evaluation percentage at each depth level achieved - Account for turns that reached higher depths (100% assumed for lower depths) - Display how many turns reached each depth level - Provides meaningful insight into time budget utilization at each search level 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Force optimization for AI performance runner binary - Add -O3 and -DNDEBUG flags to copts for ai_performance_runner binary - Ensures the performance testing tool always runs optimized regardless of build mode - Critical for accurate AI performance measurements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * bad eval * run gazelle * Revert copts optimization and add ai_perf_test.sh script - Revert BUILD.bazel copts changes (insufficient for global optimization) - Add scripts/ai_perf_test.sh that runs with "bazel run -c opt" - Script defaults to 10 turns and accepts additional arguments - Global -c opt dramatically improves AI performance (depth 3 vs depth 2) - Ensures all AI dependencies are optimized for accurate performance testing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * review comments --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# AI Performance Test Runner Script
|
||||
# Runs the AI performance test with optimized builds and 10 turns
|
||||
|
||||
echo "Running AI performance test with optimized build..."
|
||||
echo "=============================================="
|
||||
|
||||
# Run with optimized compilation and 10 turns
|
||||
bazel run -c opt //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner -- --turns=10 "$@"
|
||||
@@ -6,6 +6,7 @@ cc_library(
|
||||
hdrs = ["AIAttackerStrategySelector.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
@@ -26,6 +27,7 @@ cc_library(
|
||||
hdrs = ["AIAttackGroups.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -60,6 +62,7 @@ cc_library(
|
||||
hdrs = ["AIDefenderStrategySelector.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
@@ -80,6 +83,7 @@ cc_library(
|
||||
hdrs = ["AIDistanceDebuf.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -112,6 +116,7 @@ cc_library(
|
||||
hdrs = ["AIScoreUtilities.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -127,6 +132,7 @@ cc_library(
|
||||
hdrs = ["AICommandFilter.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -146,6 +152,7 @@ cc_library(
|
||||
hdrs = ["AIScoreCalculator.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -165,6 +172,7 @@ cc_library(
|
||||
hdrs = ["AIStrategy.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
@@ -178,6 +186,7 @@ cc_library(
|
||||
hdrs = ["AIUnitScoreCalculator.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
@@ -193,6 +202,7 @@ cc_library(
|
||||
hdrs = ["AIVictoryConditionScoreCalculator.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
@@ -246,6 +256,7 @@ cc_library(
|
||||
hdrs = ["AITimeBudget.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
@@ -263,6 +274,7 @@ cc_library(
|
||||
hdrs = ["IterativeDeepeningAI.hpp"],
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/test/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// Created by Dan Crosby on 2025-01-15.
|
||||
//
|
||||
|
||||
#include "AIPerformanceRunner.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "PerformanceTestGameStateBuilder.hpp"
|
||||
#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/ai/ShardokAIClient.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/library/ShardokEngine.hpp"
|
||||
#include "src/main/protobuf/net/eagle0/shardok/common/command_type.pb.h"
|
||||
|
||||
using namespace shardok;
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Parse command line arguments into a configuration struct.
|
||||
*/
|
||||
auto ParseCommandLineArgs(int argc, char* argv[]) -> PerformanceTestConfig {
|
||||
PerformanceTestConfig config;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string arg(argv[i]);
|
||||
|
||||
if (arg == "--help" || arg == "-h") {
|
||||
std::cout << "Shardok AI Performance Runner\n"
|
||||
<< "Usage: " << argv[0] << " [options]\n"
|
||||
<< "\n"
|
||||
<< "Options:\n"
|
||||
<< " --map=NAME Map name (default: Alah)\n"
|
||||
<< " --turns=N Number of turns to test (default: 5)\n"
|
||||
<< " --defender=BOOL AI is defender (default: false)\n"
|
||||
<< " --verbose Enable verbose output\n"
|
||||
<< " --help, -h Show this help message\n";
|
||||
std::exit(0);
|
||||
} else if (arg.starts_with("--map=")) {
|
||||
config.mapName = arg.substr(6);
|
||||
} else if (arg.starts_with("--turns=")) {
|
||||
config.numTurns = std::stoi(arg.substr(8));
|
||||
} else if (arg.starts_with("--defender=")) {
|
||||
std::string value = arg.substr(11);
|
||||
config.defenderToggle = (value == "true" || value == "1");
|
||||
} else if (arg == "--verbose") {
|
||||
config.verbose = true;
|
||||
} else {
|
||||
std::cerr << "Unknown argument: " << arg << "\n";
|
||||
std::cerr << "Use --help for usage information.\n";
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::cout << "Starting AI Performance Runner..." << std::endl;
|
||||
|
||||
// Set exec path so FilesystemUtils can find resource files
|
||||
FilesystemUtils::SetExecPath(argv[0]);
|
||||
|
||||
try {
|
||||
std::cout << "Shardok AI Performance Runner\n";
|
||||
std::cout << "==============================\n";
|
||||
|
||||
// Parse command line arguments
|
||||
auto config = ParseCommandLineArgs(argc, argv);
|
||||
|
||||
if (config.verbose) {
|
||||
std::cout << "Configuration:\n";
|
||||
std::cout << " Map: " << config.mapName << "\n";
|
||||
std::cout << " Turns: " << config.numTurns << "\n";
|
||||
std::cout << " AI is defender: " << (config.defenderToggle ? "Yes" : "No") << "\n";
|
||||
}
|
||||
|
||||
// Initialize game settings
|
||||
auto settings = PerformanceTestGameStateBuilder::InitializeGameSettings();
|
||||
|
||||
// Create test game state
|
||||
auto gameState = PerformanceTestGameStateBuilder::CreatePerfTestGameState(
|
||||
settings,
|
||||
config.defenderToggle);
|
||||
|
||||
// Create engine
|
||||
ShardokEngine engine(settings, gameState);
|
||||
|
||||
// Test basic functionality
|
||||
auto currentState = engine.GetCurrentGameState();
|
||||
|
||||
// Create AI client for testing
|
||||
const PlayerId aiPlayerId = 0;
|
||||
const bool isDefender = config.defenderToggle;
|
||||
const auto* hexMap = currentState->hex_map();
|
||||
const auto settingsGetter = settings->GetGetter();
|
||||
|
||||
ShardokAIClient aiClient(aiPlayerId, isDefender, hexMap, settingsGetter);
|
||||
|
||||
// Create a second AI client for the human player during setup
|
||||
// This ensures consistent state handling during setup phase
|
||||
const PlayerId humanPlayerId = 1;
|
||||
ShardokAIClient humanSetupAI(humanPlayerId, !isDefender, hexMap, settingsGetter);
|
||||
|
||||
// Complete setup phase - AI makes intelligent placement decisions
|
||||
if (currentState->status()->state() ==
|
||||
net::eagle0::shardok::storage::fb::GameStatus_::State_SET_UP) {
|
||||
while (currentState->status()->state() ==
|
||||
net::eagle0::shardok::storage::fb::GameStatus_::State_SET_UP) {
|
||||
PlayerId currentPlayer = currentState->current_player();
|
||||
auto availableCommands = engine.GetAvailableCommandProtos(currentPlayer, false);
|
||||
|
||||
if (availableCommands.empty()) {
|
||||
std::cout << "No commands available for player "
|
||||
<< static_cast<int>(currentPlayer) << "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentPlayer == aiPlayerId) {
|
||||
// Let AI make intelligent placement decisions
|
||||
auto choiceResults = aiClient.ChooseCommandIndex(engine);
|
||||
engine.PostCommand(currentPlayer, choiceResults.chosenIndex);
|
||||
} else {
|
||||
// Human player: use AI for setup to ensure consistent state handling
|
||||
auto choiceResults = humanSetupAI.ChooseCommandIndex(engine);
|
||||
engine.PostCommand(currentPlayer, choiceResults.chosenIndex);
|
||||
}
|
||||
|
||||
currentState = engine.GetCurrentGameState();
|
||||
}
|
||||
}
|
||||
|
||||
// Test AI performance for configured number of turns
|
||||
std::cout << "Running AI performance test for " << config.numTurns << " turns...\n";
|
||||
|
||||
std::vector<AIPerformanceMetrics> metrics;
|
||||
|
||||
for (int turn = 0; turn < config.numTurns; ++turn) {
|
||||
// Check if AI can make a move
|
||||
const auto availableCommands = engine.GetAvailableCommandProtos(aiPlayerId, false);
|
||||
if (availableCommands.empty()) {
|
||||
std::cout << " No commands available for AI player. Ending test.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
// Get AI decision with performance metrics
|
||||
auto choiceResults = aiClient.ChooseCommandIndex(engine);
|
||||
|
||||
std::cout << " AI chose command index: " << choiceResults.chosenIndex << "\n";
|
||||
std::cout << " Depth achieved: " << choiceResults.depthAchieved << "\n";
|
||||
std::cout << " Commands evaluated: " << choiceResults.commandCountEvaluated << "/"
|
||||
<< choiceResults.availableCommandCount << "\n";
|
||||
|
||||
// Create metrics for this turn
|
||||
AIPerformanceMetrics turnMetrics;
|
||||
turnMetrics.commandNumber = turn + 1;
|
||||
turnMetrics.totalCommands = static_cast<int>(choiceResults.availableCommandCount);
|
||||
turnMetrics.depthAchieved = choiceResults.depthAchieved;
|
||||
turnMetrics.commandsEvaluated = static_cast<int>(choiceResults.commandCountEvaluated);
|
||||
turnMetrics.selectedCommandType = net::eagle0::shardok::common::CommandType_Name(
|
||||
availableCommands[choiceResults.chosenIndex].type());
|
||||
|
||||
metrics.push_back(turnMetrics);
|
||||
|
||||
if (config.verbose) {
|
||||
std::cout << " Command: " << turnMetrics.selectedCommandType << "\n";
|
||||
std::cout << " Search depth: " << turnMetrics.depthAchieved << "\n";
|
||||
std::cout << " Commands evaluated: " << turnMetrics.commandsEvaluated << "\n";
|
||||
std::cout << " Applying command...\n";
|
||||
}
|
||||
|
||||
// Apply the chosen command
|
||||
engine.PostCommand(aiPlayerId, choiceResults.chosenIndex);
|
||||
|
||||
// Check if game is over
|
||||
if (engine.GameIsOver()) {
|
||||
std::cout << " Game over after " << (turn + 1) << " turns.\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Print summary
|
||||
std::cout << "\nAI Search Performance Summary:\n";
|
||||
std::cout << "==============================\n";
|
||||
std::cout << "Total turns: " << metrics.size() << "\n";
|
||||
|
||||
if (!metrics.empty()) {
|
||||
// Calculate summary statistics
|
||||
double avgDepth = 0.0;
|
||||
int totalEvaluated = 0;
|
||||
int totalAvailable = 0;
|
||||
|
||||
for (const auto& metric : metrics) {
|
||||
avgDepth += metric.depthAchieved;
|
||||
totalEvaluated += metric.commandsEvaluated;
|
||||
totalAvailable += metric.totalCommands;
|
||||
}
|
||||
|
||||
avgDepth /= metrics.size();
|
||||
|
||||
std::cout << "Average search depth: " << std::fixed << std::setprecision(1) << avgDepth
|
||||
<< "\n";
|
||||
std::cout << "Total commands evaluated: " << totalEvaluated << "/" << totalAvailable
|
||||
<< "\n";
|
||||
|
||||
// Calculate evaluation rate by depth
|
||||
// Find max depth achieved across all turns
|
||||
int maxDepth = 0;
|
||||
for (const auto& metric : metrics) {
|
||||
maxDepth = std::max(maxDepth, metric.depthAchieved);
|
||||
}
|
||||
|
||||
if (maxDepth >= 2) {
|
||||
std::cout << "\nEvaluation rate by depth:\n";
|
||||
for (int depth = 2; depth <= maxDepth; ++depth) {
|
||||
int turnsAtThisDepth = 0;
|
||||
double totalRate = 0.0;
|
||||
|
||||
for (const auto& metric : metrics) {
|
||||
if (metric.depthAchieved >= depth) {
|
||||
turnsAtThisDepth++;
|
||||
if (metric.depthAchieved > depth) {
|
||||
// If achieved higher depth, assume 100% at this depth
|
||||
totalRate += 100.0;
|
||||
} else {
|
||||
// If stopped at this depth, calculate actual rate
|
||||
double rate = metric.totalCommands > 0
|
||||
? (100.0 * metric.commandsEvaluated /
|
||||
metric.totalCommands)
|
||||
: 0.0;
|
||||
totalRate += rate;
|
||||
}
|
||||
}
|
||||
// If didn't reach this depth, contributes 0% (implicit)
|
||||
}
|
||||
|
||||
double avgRate = turnsAtThisDepth > 0 ? totalRate / metrics.size() : 0.0;
|
||||
std::cout << " Depth " << depth << ": " << std::fixed << std::setprecision(1)
|
||||
<< avgRate << "% (" << turnsAtThisDepth << "/" << metrics.size()
|
||||
<< " turns reached)\n";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\nTurn-by-turn details:\n";
|
||||
for (const auto& metric : metrics) {
|
||||
std::cout << "Turn " << metric.commandNumber << ": depth " << metric.depthAchieved
|
||||
<< ", evaluated " << metric.commandsEvaluated << "/"
|
||||
<< metric.totalCommands << ", chose " << metric.selectedCommandType
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// Created by Dan Crosby on 2025-01-15.
|
||||
//
|
||||
|
||||
#ifndef EAGLE0_AIPERFORMANCERUNNER_HPP
|
||||
#define EAGLE0_AIPERFORMANCERUNNER_HPP
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace shardok {
|
||||
|
||||
/**
|
||||
* Metrics captured for each AI command evaluation during performance testing.
|
||||
*/
|
||||
struct AIPerformanceMetrics {
|
||||
int commandNumber;
|
||||
int depthAchieved;
|
||||
int commandsEvaluated;
|
||||
int totalCommands;
|
||||
std::string selectedCommandType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Overall results from a performance test run.
|
||||
*/
|
||||
struct PerformanceTestResults {
|
||||
std::string mapName;
|
||||
int totalTurns;
|
||||
std::vector<AIPerformanceMetrics> commandMetrics;
|
||||
double averageDepth;
|
||||
double completionRate;
|
||||
std::chrono::milliseconds totalTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration options for performance testing.
|
||||
*/
|
||||
struct PerformanceTestConfig {
|
||||
std::string mapName = "Alah";
|
||||
int numTurns = 5;
|
||||
bool defenderToggle = false;
|
||||
bool verbose = false;
|
||||
int aiUnitCount = 6;
|
||||
int humanUnitCount = 6;
|
||||
};
|
||||
|
||||
} // namespace shardok
|
||||
|
||||
#endif // EAGLE0_AIPERFORMANCERUNNER_HPP
|
||||
@@ -0,0 +1,51 @@
|
||||
load("//tools:copts.bzl", "COPTS")
|
||||
|
||||
cc_binary(
|
||||
name = "ai_performance_runner",
|
||||
srcs = [
|
||||
"AIPerformanceRunner.cpp",
|
||||
"AIPerformanceRunner.hpp",
|
||||
],
|
||||
copts = COPTS,
|
||||
data = [
|
||||
"//src/main/resources/net/eagle0/shardok:battalion_types",
|
||||
"//src/main/resources/net/eagle0/shardok:settings",
|
||||
"//src/main/resources/net/eagle0/shardok/maps",
|
||||
],
|
||||
deps = [
|
||||
":performance_test_game_state_builder",
|
||||
"//src/main/cpp/net/eagle0/common:filesystem_utils",
|
||||
"//src/main/cpp/net/eagle0/common:time_utils",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_attacker_strategy_selector",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_defender_strategy_selector",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_iterative_deepening",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_score_calculator",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_time_budget",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_water_crossing_command_chooser",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:shardok_ai_client",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:engine",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:game_state_w",
|
||||
"//src/main/cpp/net/eagle0/shardok/library/settings:game_settings",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:battalion_type_registrar",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:map_loader",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "performance_test_game_state_builder",
|
||||
srcs = ["PerformanceTestGameStateBuilder.cpp"],
|
||||
hdrs = [
|
||||
"PerformanceTestGameStateBuilder.hpp",
|
||||
],
|
||||
copts = COPTS,
|
||||
deps = [
|
||||
"//src/main/cpp/net/eagle0/shardok/library:game_state_w",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:shardok_c_types",
|
||||
"//src/main/cpp/net/eagle0/shardok/library/fb_helpers:game_state_helpers",
|
||||
"//src/main/cpp/net/eagle0/shardok/library/settings:game_settings",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:battalion_type_registrar",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:map_loader",
|
||||
"//src/main/flatbuffer/net/eagle0/shardok/storage:unit_cc_fbs",
|
||||
"//src/main/protobuf/net/eagle0/shardok/common:player_info_cc_proto",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,205 @@
|
||||
# AI Performance Runner Implementation Plan
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the implementation plan for an automated AI performance testing tool for Shardok. The tool will replicate the manual performance testing currently done through the Unity client's "Custom Battle" interface, providing reproducible and automated performance measurements.
|
||||
|
||||
## Goals
|
||||
|
||||
1. **Automate Performance Testing**: Eliminate the need for manual Unity client interaction
|
||||
2. **Reproducible Results**: Ensure consistent test conditions across runs
|
||||
3. **Detailed Metrics**: Capture the same metrics currently observed manually (commands evaluated at each depth)
|
||||
4. **Clean Architecture**: Maintain proper dependency boundaries (no src/test dependencies in src/main)
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
src/main/cpp/net/eagle0/shardok/ai_performance_runner/
|
||||
├── AIPerformanceRunner.cpp # Main binary entry point
|
||||
├── AIPerformanceRunner.hpp # Performance metrics structs and helpers
|
||||
├── PerformanceTestGameStateBuilder.cpp # Game state setup utilities
|
||||
├── PerformanceTestGameStateBuilder.hpp # Game state builder interface
|
||||
├── BUILD.bazel # Build configuration
|
||||
└── README.md # Usage documentation
|
||||
```
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### 1. Performance Metrics Structure
|
||||
|
||||
```cpp
|
||||
struct AIPerformanceMetrics {
|
||||
int commandNumber;
|
||||
int depthAchieved;
|
||||
std::map<int, int> commandsEvaluatedAtDepth; // depth -> count
|
||||
std::chrono::milliseconds timeUsed;
|
||||
bool minimumDepthCompleted;
|
||||
bool searchCompleted;
|
||||
std::string selectedCommandType;
|
||||
};
|
||||
|
||||
struct PerformanceTestResults {
|
||||
std::string mapName;
|
||||
int totalTurns;
|
||||
std::vector<AIPerformanceMetrics> commandMetrics;
|
||||
double averageDepth;
|
||||
double completionRate;
|
||||
std::chrono::milliseconds totalTime;
|
||||
};
|
||||
```
|
||||
|
||||
### 2. Test Configuration
|
||||
|
||||
The default configuration replicates the Unity client's "Perf" button:
|
||||
|
||||
- **Map**: "Alah"
|
||||
- **AI Player**: 6 units with professions 1-6, all battalion type 4 (Heavy Infantry)
|
||||
- **Human Player**: 6 units (no specific configuration needed since AI will control)
|
||||
- **Defender Toggle**: Configurable (affects starting positions)
|
||||
|
||||
### 3. Key Components
|
||||
|
||||
#### AIPerformanceRunner.cpp
|
||||
- Main entry point with command-line argument parsing
|
||||
- Test execution loop
|
||||
- Results formatting and output
|
||||
- Integration with ShardokEngine and IterativeDeepeningAI
|
||||
|
||||
#### PerformanceTestGameStateBuilder.cpp
|
||||
- Game state creation utilities (migrated from test code)
|
||||
- Map loading helpers
|
||||
- Unit placement logic
|
||||
- Player setup functions
|
||||
|
||||
### 4. Build Configuration
|
||||
|
||||
```python
|
||||
load("//tools:copts.bzl", "COPTS")
|
||||
|
||||
cc_binary(
|
||||
name = "ai_performance_runner",
|
||||
srcs = ["AIPerformanceRunner.cpp"],
|
||||
copts = COPTS,
|
||||
data = [
|
||||
"//src/main/resources/net/eagle0/shardok:battalion_types",
|
||||
"//src/main/resources/net/eagle0/shardok:settings",
|
||||
"//src/main/resources/net/eagle0/shardok/maps",
|
||||
],
|
||||
deps = [
|
||||
":performance_test_game_state_builder",
|
||||
"//src/main/cpp/net/eagle0/common:time_utils",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_iterative_deepening",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_attacker_strategy_selector",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_defender_strategy_selector",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_score_calculator",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_time_budget",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:ai_water_crossing_command_chooser",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:engine",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:game_state_w",
|
||||
"//src/main/cpp/net/eagle0/shardok/library/settings:game_settings",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:battalion_type_registrar",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:map_loader",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "performance_test_game_state_builder",
|
||||
srcs = ["PerformanceTestGameStateBuilder.cpp"],
|
||||
hdrs = [
|
||||
"AIPerformanceRunner.hpp",
|
||||
"PerformanceTestGameStateBuilder.hpp",
|
||||
],
|
||||
copts = COPTS,
|
||||
deps = [
|
||||
"//src/main/cpp/net/eagle0/common:filesystem_utils",
|
||||
"//src/main/cpp/net/eagle0/common:tsv_parser",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:game_state_w",
|
||||
"//src/main/cpp/net/eagle0/shardok/library/settings:game_settings",
|
||||
"//src/main/cpp/net/eagle0/shardok/util:map_loader",
|
||||
"//src/main/flatbuffer/net/eagle0/shardok/storage:game_state_cc_fbs",
|
||||
"//src/main/flatbuffer/net/eagle0/shardok/storage:player_info_cc_fbs",
|
||||
"//src/main/flatbuffer/net/eagle0/shardok/storage:unit_cc_fbs",
|
||||
],
|
||||
)
|
||||
```
|
||||
|
||||
### 5. Command-Line Interface
|
||||
|
||||
```bash
|
||||
# Run default performance test (Alah map, 6v6 units)
|
||||
bazel run //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner
|
||||
|
||||
# Run with specific number of turns
|
||||
bazel run //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner -- --turns=10
|
||||
|
||||
# Run with defender configuration
|
||||
bazel run //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner -- --defender=true
|
||||
|
||||
# Run with verbose output
|
||||
bazel run //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner -- --verbose
|
||||
|
||||
# Run with specific map
|
||||
bazel run //src/main/cpp/net/eagle0/shardok/ai_performance_runner:ai_performance_runner -- --map=Chipingia
|
||||
```
|
||||
|
||||
### 6. Expected Output Format
|
||||
|
||||
```
|
||||
Shardok AI Performance Test
|
||||
===========================
|
||||
Map: Alah
|
||||
Configuration: 6v6 units (AI as attacker)
|
||||
Time Budget: Dynamic (proximity-based)
|
||||
|
||||
Turn 1:
|
||||
Command 1: Depth 2, evaluated 140/280 commands, time: 1250ms [MoveCommand]
|
||||
Command 2: Depth 2, evaluated ALL commands, time: 1180ms [MeleeCommand]
|
||||
Command 3: Depth 3, evaluated 21/156 commands, time: 1300ms [ArcheryCommand]
|
||||
Command 4: Depth 3, evaluated 78/312 commands, time: 1290ms [MoveCommand]
|
||||
Turn Summary: Avg depth 2.5, Total time: 5020ms
|
||||
|
||||
Overall Results:
|
||||
Total Turns: 5
|
||||
Average Depth Achieved: 2.4
|
||||
Commands Completed at Target Depth: 85%
|
||||
Total Time: 25.1s
|
||||
Average Time per Command: 1255ms
|
||||
```
|
||||
|
||||
### 7. Implementation Phases
|
||||
|
||||
#### Phase 1: Basic Infrastructure
|
||||
1. Create directory structure and BUILD.bazel
|
||||
2. Implement PerformanceTestGameStateBuilder with minimal game state creation
|
||||
3. Create basic AIPerformanceRunner that can load a map and create players
|
||||
|
||||
#### Phase 2: AI Integration
|
||||
1. Integrate IterativeDeepeningAI
|
||||
2. Implement performance metric collection
|
||||
3. Add basic output formatting
|
||||
|
||||
#### Phase 3: Full Feature Set
|
||||
1. Add command-line argument parsing
|
||||
2. Implement multiple test configurations (Perf, Rivers, Custom)
|
||||
3. Add detailed performance metrics and analysis
|
||||
|
||||
#### Phase 4: Polish and Documentation
|
||||
1. Create comprehensive README.md
|
||||
2. Add error handling and validation
|
||||
3. Implement baseline comparison features
|
||||
|
||||
## Success Criteria
|
||||
|
||||
1. **Functional**: Tool successfully runs AI turns and captures performance metrics
|
||||
2. **Accurate**: Results match manually observed performance within reasonable variance
|
||||
3. **Reproducible**: Multiple runs produce consistent results
|
||||
4. **Maintainable**: Clean code structure with no dependencies on src/test
|
||||
5. **Usable**: Clear command-line interface and helpful output
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- JSON output format for automated analysis
|
||||
- Performance regression detection
|
||||
- Integration with CI/CD pipeline
|
||||
- Configurable test scenarios beyond "Perf" and "Rivers"
|
||||
- Multi-threaded performance testing
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
//
|
||||
// Created by Dan Crosby on 2025-01-15.
|
||||
//
|
||||
|
||||
#include "PerformanceTestGameStateBuilder.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
|
||||
#include "src/main/cpp/net/eagle0/common/TsvParser.hpp"
|
||||
#include "src/main/cpp/net/eagle0/common/byte_vector.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/library/fb_helpers/GameStateHelpers.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/library/settings/GameSettings.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/util/BattalionTypeRegistrar.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/util/MapLoader.hpp"
|
||||
#include "src/main/flatbuffer/net/eagle0/shardok/storage/unit.hpp"
|
||||
#include "src/main/protobuf/net/eagle0/shardok/common/player_info.pb.h"
|
||||
|
||||
namespace shardok {
|
||||
|
||||
namespace {
|
||||
|
||||
// Profession enum values
|
||||
constexpr int NO_PROFESSION = 0;
|
||||
|
||||
// Player IDs
|
||||
constexpr PlayerId AI_PLAYER_ID = 0;
|
||||
constexpr PlayerId HUMAN_PLAYER_ID = 1;
|
||||
|
||||
} // namespace
|
||||
|
||||
auto PerformanceTestGameStateBuilder::InitializeGameSettings() -> GameSettingsSPtr {
|
||||
auto settings = std::make_shared<GameSettings>();
|
||||
auto setter = settings->GetSetter();
|
||||
|
||||
// Load battalion types
|
||||
BattalionTypeRegistrar::RegisterBattalionTypes(setter);
|
||||
|
||||
// Load complete settings from settings.tsv file
|
||||
TsvParser parser;
|
||||
const string settingsPath = FilesystemUtils::StaticShardokFilesDirectory() + "settings.tsv";
|
||||
const string settingsTsv = string(byte_vector::FromPath(settingsPath));
|
||||
const auto valuesAndTypes = parser.ParseColumnEntryTsv(settingsTsv);
|
||||
setter.SetFromTypesAndValues(valuesAndTypes[1], valuesAndTypes[0]);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
auto PerformanceTestGameStateBuilder::CreatePerfTestGameState(
|
||||
const GameSettingsSPtr& settings,
|
||||
bool defenderToggle) -> GameStateW {
|
||||
return CreateCustomTestGameState(
|
||||
settings,
|
||||
"Alah",
|
||||
6, // 6 AI units (full test configuration)
|
||||
6, // 6 human units (full test configuration)
|
||||
defenderToggle);
|
||||
}
|
||||
|
||||
auto PerformanceTestGameStateBuilder::CreateCustomTestGameState(
|
||||
const GameSettingsSPtr& settings,
|
||||
const std::string& mapName,
|
||||
int aiUnitCount,
|
||||
int humanUnitCount,
|
||||
bool defenderToggle) -> GameStateW {
|
||||
// Load the map using existing utilities
|
||||
auto hexMapProto = LoadMap(mapName);
|
||||
|
||||
// Create player info protos
|
||||
std::vector<net::eagle0::shardok::common::PlayerInfo> playerInfoProtos;
|
||||
|
||||
// AI player
|
||||
net::eagle0::shardok::common::PlayerInfo aiPlayerInfo;
|
||||
aiPlayerInfo.set_player_id(AI_PLAYER_ID);
|
||||
aiPlayerInfo.set_is_defender(defenderToggle);
|
||||
aiPlayerInfo.set_starting_food(1000);
|
||||
aiPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_LAST_PLAYER_STANDING);
|
||||
if (defenderToggle) {
|
||||
aiPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_WIN_AFTER_MAX_ROUNDS);
|
||||
} else {
|
||||
aiPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_HOLDS_CRITICAL_TILES);
|
||||
}
|
||||
playerInfoProtos.push_back(aiPlayerInfo);
|
||||
|
||||
// Human player
|
||||
net::eagle0::shardok::common::PlayerInfo humanPlayerInfo;
|
||||
humanPlayerInfo.set_player_id(HUMAN_PLAYER_ID);
|
||||
humanPlayerInfo.set_is_defender(!defenderToggle);
|
||||
humanPlayerInfo.set_starting_food(1000);
|
||||
humanPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_LAST_PLAYER_STANDING);
|
||||
if (!defenderToggle) {
|
||||
humanPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_WIN_AFTER_MAX_ROUNDS);
|
||||
} else {
|
||||
humanPlayerInfo.add_victory_conditions(
|
||||
net::eagle0::shardok::common::VICTORY_CONDITION_HOLDS_CRITICAL_TILES);
|
||||
}
|
||||
playerInfoProtos.push_back(humanPlayerInfo);
|
||||
|
||||
// Create units
|
||||
std::vector<net::eagle0::shardok::storage::fb::Unit> units;
|
||||
|
||||
// Create AI units in reserve (location -1, -1)
|
||||
for (int i = 0; i < aiUnitCount && i < 6; ++i) {
|
||||
units.push_back(AddGenericUnit(
|
||||
AI_PLAYER_ID,
|
||||
i, // Unit ID
|
||||
net::eagle0::shardok::storage::fb::Coords(-1, -1), // Reserve location
|
||||
i + 1, // Profession: 1-6 (Mage through Strategist)
|
||||
HEAVY_INFANTRY_BATTALION_TYPE,
|
||||
defenderToggle ? -1 : 0)); // Defender: -1, Attacker: 0
|
||||
}
|
||||
|
||||
// Create human units in reserve (location -1, -1)
|
||||
for (int i = 0; i < humanUnitCount && i < 6; ++i) {
|
||||
units.push_back(AddGenericUnit(
|
||||
HUMAN_PLAYER_ID,
|
||||
aiUnitCount + i, // Unit ID starting aiUnitCount
|
||||
net::eagle0::shardok::storage::fb::Coords(-1, -1), // Reserve location
|
||||
NO_PROFESSION,
|
||||
HEAVY_INFANTRY_BATTALION_TYPE,
|
||||
defenderToggle ? 0 : -1)); // Defender: -1, Attacker: 0
|
||||
}
|
||||
|
||||
// Use the proper SetupInitialGameState helper (setup phase will be handled by AI)
|
||||
return shardok::fb::SetupInitialGameState(
|
||||
"performance_test_game", // gameId
|
||||
hexMapProto,
|
||||
playerInfoProtos,
|
||||
units,
|
||||
4, // month
|
||||
false, // isWinter
|
||||
settings->GetGetter());
|
||||
}
|
||||
|
||||
auto PerformanceTestGameStateBuilder::AddPlayerInfo(
|
||||
flatbuffers::FlatBufferBuilder& fbb,
|
||||
int playerId,
|
||||
bool isDefender,
|
||||
int food) -> flatbuffers::Offset<net::eagle0::shardok::storage::fb::PlayerInfo> {
|
||||
std::vector<int8_t> victoryConditions{
|
||||
net::eagle0::shardok::storage::fb::
|
||||
VictoryCondition_VICTORY_CONDITION_LAST_PLAYER_STANDING};
|
||||
|
||||
if (isDefender) {
|
||||
victoryConditions.push_back(
|
||||
net::eagle0::shardok::storage::fb::
|
||||
VictoryCondition_VICTORY_CONDITION_WIN_AFTER_MAX_ROUNDS);
|
||||
} else {
|
||||
victoryConditions.push_back(
|
||||
net::eagle0::shardok::storage::fb::
|
||||
VictoryCondition_VICTORY_CONDITION_HOLDS_CRITICAL_TILES);
|
||||
}
|
||||
|
||||
auto victoryConditionsOffset = fbb.CreateVector(victoryConditions);
|
||||
|
||||
net::eagle0::shardok::storage::fb::PlayerInfoBuilder pib(fbb);
|
||||
pib.add_player_id(playerId);
|
||||
pib.add_starting_food(food);
|
||||
pib.add_is_defender(isDefender);
|
||||
pib.add_victory_conditions(victoryConditionsOffset);
|
||||
|
||||
return pib.Finish();
|
||||
}
|
||||
|
||||
auto PerformanceTestGameStateBuilder::AddGenericUnit(
|
||||
PlayerId playerId,
|
||||
UnitId unitId,
|
||||
const net::eagle0::shardok::storage::fb::Coords& location,
|
||||
int profession,
|
||||
int battalionType,
|
||||
int startingPositionIndex) -> net::eagle0::shardok::storage::fb::Unit {
|
||||
net::eagle0::shardok::storage::fb::Unit unit{}; // Initialize to zero
|
||||
|
||||
// Basic unit properties (following UnitConversions.cpp pattern)
|
||||
unit.mutate_player_id(playerId);
|
||||
unit.mutate_unit_id(unitId);
|
||||
unit.mutate_eagle_player_id(playerId); // Set eagle player ID
|
||||
unit.mutable_location() = location;
|
||||
unit.mutate_status(net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT);
|
||||
unit.mutate_remaining_action_points(12);
|
||||
unit.mutate_hidden(false);
|
||||
unit.mutate_fortified(false);
|
||||
unit.mutate_can_flee(true);
|
||||
unit.mutate_can_start_fire(false);
|
||||
unit.mutate_can_archery(false);
|
||||
unit.mutate_stun_rounds_remaining(0);
|
||||
unit.mutate_commanding_unit_id(-1);
|
||||
unit.mutate_targeted_unit(-1);
|
||||
unit.mutate_starting_position_index(startingPositionIndex);
|
||||
unit.mutate_has_moved_in_zoc(false);
|
||||
unit.mutate_volleys_remaining(0);
|
||||
unit.mutate_food_remaining(1000.0f); // Set food remaining
|
||||
|
||||
// Battalion
|
||||
net::eagle0::shardok::storage::fb::Battalion battalion;
|
||||
battalion.mutate_type(
|
||||
static_cast<net::eagle0::shardok::storage::fb::BattalionTypeId>(battalionType));
|
||||
battalion.mutate_size(1000.0);
|
||||
battalion.mutate_armament(100.0f);
|
||||
battalion.mutate_training(100.0f);
|
||||
battalion.mutate_morale(50.0f);
|
||||
unit.mutable_battalion() = battalion;
|
||||
|
||||
// Hero (if profession is specified)
|
||||
if (profession != NO_PROFESSION) {
|
||||
unit.mutate_has_attached_hero(true);
|
||||
|
||||
net::eagle0::shardok::storage::fb::Hero hero;
|
||||
hero.mutate_strength(50);
|
||||
hero.mutate_strength_xp(0);
|
||||
hero.mutate_agility(50);
|
||||
hero.mutate_agility_xp(0);
|
||||
hero.mutate_wisdom(50);
|
||||
hero.mutate_wisdom_xp(0);
|
||||
hero.mutate_charisma(50);
|
||||
hero.mutate_charisma_xp(0);
|
||||
hero.mutate_constitution(80);
|
||||
hero.mutate_constitution_xp(0);
|
||||
hero.mutate_vigor(50);
|
||||
hero.mutate_starting_vigor(50);
|
||||
hero.mutate_spent_vigor(0);
|
||||
hero.mutate_bravery(50);
|
||||
hero.mutate_integrity(50);
|
||||
hero.mutate_ambition(50);
|
||||
hero.mutate_eagle_hero_id(unitId + 1);
|
||||
hero.mutate_is_vip(false);
|
||||
|
||||
hero.mutable_profession_info().mutate_profession(
|
||||
static_cast<net::eagle0::shardok::storage::fb::Profession>(profession));
|
||||
hero.mutable_profession_info().mutate_meteor_cast_state(
|
||||
net::eagle0::shardok::storage::fb::MultiroundMagicState_NONE);
|
||||
|
||||
hero.mutable_control_info().mutate_controlled_unit_id(-1);
|
||||
hero.mutable_control_info().mutate_controlled_this_round(false);
|
||||
|
||||
unit.mutable_attached_hero() = hero;
|
||||
} else {
|
||||
unit.mutate_has_attached_hero(false);
|
||||
}
|
||||
|
||||
// Initialize opponent knowledge for both players (player IDs 0 and 1)
|
||||
unit.mutable_opponent_knowledge()->Mutate(0, 0); // Player 0 knowledge
|
||||
unit.mutable_opponent_knowledge()->Mutate(1, 0); // Player 1 knowledge
|
||||
|
||||
return unit;
|
||||
}
|
||||
|
||||
} // namespace shardok
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Created by Dan Crosby on 2025-01-15.
|
||||
//
|
||||
|
||||
#ifndef EAGLE0_PERFORMANCETESTGAMESTATEBUILDER_HPP
|
||||
#define EAGLE0_PERFORMANCETESTGAMESTATEBUILDER_HPP
|
||||
|
||||
#include <flatbuffers/flatbuffers.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "src/main/cpp/net/eagle0/shardok/library/GameStateW.hpp"
|
||||
#include "src/main/cpp/net/eagle0/shardok/library/ShardokCTypes.h"
|
||||
#include "src/main/flatbuffer/net/eagle0/shardok/storage/player_info.hpp"
|
||||
#include "src/main/flatbuffer/net/eagle0/shardok/storage/unit.hpp"
|
||||
|
||||
namespace shardok {
|
||||
|
||||
// Forward declarations
|
||||
class GameSettings;
|
||||
using GameSettingsSPtr = std::shared_ptr<GameSettings>;
|
||||
|
||||
/**
|
||||
* Builder class for creating game states used in performance testing.
|
||||
* Provides utilities to set up specific test scenarios matching the Unity client's
|
||||
* "Perf" button configuration.
|
||||
*/
|
||||
class PerformanceTestGameStateBuilder {
|
||||
public:
|
||||
/**
|
||||
* Initialize game settings from the default configuration files.
|
||||
* Must be called before creating game states.
|
||||
*/
|
||||
static auto InitializeGameSettings() -> GameSettingsSPtr;
|
||||
|
||||
/**
|
||||
* Create the standard "Perf" test configuration:
|
||||
* - Map: Alah
|
||||
* - 6 AI units with professions 1-6, all Heavy Infantry
|
||||
* - 6 Human units (minimal configuration)
|
||||
*
|
||||
* @param settings The game settings to use
|
||||
* @param defenderToggle If true, AI is defender; if false, AI is attacker
|
||||
* @return A GameStateW with the configured battle
|
||||
*/
|
||||
static auto CreatePerfTestGameState(
|
||||
const GameSettingsSPtr& settings,
|
||||
bool defenderToggle = false) -> GameStateW;
|
||||
|
||||
/**
|
||||
* Create a custom test configuration with specified parameters.
|
||||
*
|
||||
* @param settings The game settings to use
|
||||
* @param mapName Name of the map to load
|
||||
* @param aiUnitCount Number of AI units to create
|
||||
* @param humanUnitCount Number of human units to create
|
||||
* @param defenderToggle If true, AI is defender; if false, AI is attacker
|
||||
* @return A GameStateW with the configured battle
|
||||
*/
|
||||
static auto CreateCustomTestGameState(
|
||||
const GameSettingsSPtr& settings,
|
||||
const std::string& mapName,
|
||||
int aiUnitCount,
|
||||
int humanUnitCount,
|
||||
bool defenderToggle) -> GameStateW;
|
||||
|
||||
private:
|
||||
// Helper functions for building game state components
|
||||
static auto
|
||||
AddPlayerInfo(flatbuffers::FlatBufferBuilder& fbb, int playerId, bool isDefender, int food)
|
||||
-> flatbuffers::Offset<net::eagle0::shardok::storage::fb::PlayerInfo>;
|
||||
|
||||
static auto AddGenericUnit(
|
||||
PlayerId playerId,
|
||||
UnitId unitId,
|
||||
const net::eagle0::shardok::storage::fb::Coords& location,
|
||||
int profession,
|
||||
int battalionType,
|
||||
int startingPositionIndex = -1) -> net::eagle0::shardok::storage::fb::Unit;
|
||||
|
||||
// Battalion type constants (matching Unity client)
|
||||
static constexpr int HEAVY_INFANTRY_BATTALION_TYPE = 4;
|
||||
};
|
||||
|
||||
} // namespace shardok
|
||||
|
||||
#endif // EAGLE0_PERFORMANCETESTGAMESTATEBUILDER_HPP
|
||||
@@ -22,6 +22,7 @@ cc_library(
|
||||
copts = COPTS,
|
||||
visibility = [
|
||||
"//src/main/cpp/net/eagle0/shardok/ai:__pkg__",
|
||||
"//src/main/cpp/net/eagle0/shardok/ai_performance_runner:__pkg__",
|
||||
"//src/main/cpp/net/eagle0/shardok/library:__subpackages__",
|
||||
"//src/test/cpp/net/eagle0/shardok:__subpackages__",
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user