Player12
An open source football management simulator
Loading...
Searching...
No Matches
Lab Namespace Reference

Namespaces

namespace  ExitCode
 

Classes

struct  Band
 
struct  Estimate
 
struct  LabReport
 
struct  MatchJob
 
struct  MatchSample
 
struct  ReportRow
 
struct  SeasonOptions
 
struct  SeasonVitals
 
class  SimulationError
 
struct  Summary
 
struct  TacticPreset
 
struct  TargetSpec
 
struct  TeamSetup
 
struct  TextTable
 
struct  TierVitals
 

Enumerations

enum class  Tier : std::uint8_t { Gate , Monitor , Info }
 
enum class  Scope : std::uint8_t { Match , Engine , World , Tactics }
 
enum class  Unit : std::uint8_t { Number , Percent }
 
enum  GameStateIndex : std::uint8_t { LEAD_BY_ONE = 0 , LEVEL = 1 , TRAIL_BY_ONE = 2 }
 
enum  StrengthIndex : std::uint8_t { MAN_DOWN = 0 , EVEN = 1 , MAN_UP = 2 }
 
enum class  Verdict : std::uint8_t {
  Pass , Warn , Fail , Info ,
  NotMeasured
}
 

Functions

StatsConfig loadStatsConfig ()
 
Lineup buildLabLineup (TeamID team_id, float rating, std::vector< std::unique_ptr< Player > > &pool)
 
float lineupRating (const Lineup &lineup, const StatsConfig &config)
 
std::span< const TargetSpec > targetTable ()
 
std::vector< ReportRow > evaluateTargets (const std::map< std::string, Estimate > &metrics, std::span< const Scope > scopes)
 
std::string_view verdictName (Verdict verdict)
 
std::string_view tierName (Tier tier)
 
std::string formatValue (double value, Unit unit)
 
nlohmann::json toJson (const LabReport &report)
 
LabReport reportFromJson (const nlohmann::json &json)
 
std::string toMarkdown (const LabReport &report)
 
std::uint32_t matchSeed (std::uint64_t seed, std::uint64_t index)
 
MatchSample simulateMatch (const MatchJob &job, const StatsConfig &config)
 
std::vector< MatchSample > simulateMatches (std::span< const MatchJob > jobs, const StatsConfig &config, unsigned threads, const std::function< void(std::size_t)> &progress)
 
MatchSample sampleFromReport (const MatchReport &report)
 
std::map< std::string, Estimate > matchMetrics (std::span< const MatchSample > samples)
 
std::vector< TextTable > matchTables (std::span< const MatchSample > samples)
 
TextTable ratingGapTable (std::span< const MatchSample > samples)
 
std::vector< MatchJob > tacticJobs (std::uint64_t seed, int seeds_per_pair, float rating)
 
std::array< std::size_t, 2 > tacticPresetsOf (std::size_t job_index, int seeds_per_pair)
 
void tacticMetrics (std::span< const MatchSample > samples, int seeds_per_pair, std::map< std::string, Estimate > &metrics, std::vector< TextTable > &tables)
 
LabReport runSeasons (const SeasonOptions &options)
 
double tQuantile975 (std::size_t degrees_of_freedom)
 
Estimate meanEstimate (std::span< const double > values)
 
Estimate proportionEstimate (std::size_t successes, std::size_t trials)
 
Estimate ratioEstimate (std::span< const double > numerators, std::span< const double > denominators)
 
Estimate medianEstimate (std::span< const double > values)
 
Estimate bootstrapEstimate (std::size_t units, const std::function< double(std::span< const std::size_t >)> &statistic, std::uint64_t seed, int resamples)
 
Verdict classify (const Estimate &estimate, const std::optional< Band > &band)
 

Variables

constexpr std::array< TacticPreset, 4 > TACTIC_PRESETS
 
constexpr double MONITOR_PASS_THRESHOLD = 0.9
 
constexpr std::size_t GOAL_TIME_BINS = 6
 

Detailed Description

Synthetic squads and tactic presets for isolated lab matches.

Calibration targets, verdicts and report output (Markdown + JSON) of the balance lab. Report text is an English developer artifact, never shown in the game UI.

Batch simulation of the balance lab: isolated matches and tactics.

Whole-world season runs of the balance lab.

Statistics of the balance lab (fm_lab). Every estimate carries a 95% confidence interval so a realism verdict can tell "off target" apart from "not enough samples".

Enumeration Type Documentation

◆ GameStateIndex

enum Lab::GameStateIndex : std::uint8_t

Leading by one, level, trailing by one (team perspective).

Enumerator
LEAD_BY_ONE 
LEVEL 
TRAIL_BY_ONE 

◆ Scope

enum class Lab::Scope : std::uint8_t
strong

Where a metric can be measured.

Enumerator
Match 

Isolated matches (full engine detail) and world matches.

Engine 

Isolated matches only (needs engine-only statistics).

World 

Season runs only.

Tactics 

Tactic round-robin only.

◆ StrengthIndex

enum Lab::StrengthIndex : std::uint8_t

Fewer players, equal numbers, more players (team perspective).

Enumerator
MAN_DOWN 
EVEN 
MAN_UP 

◆ Tier

enum class Lab::Tier : std::uint8_t
strong
Enumerator
Gate 

Must pass for release; a FAIL makes fm_lab exit 1.

Monitor 

>= 90% must pass (NFR-018); below that fm_lab exits 2.

Info 

Reported only: no spec band exists.

◆ Unit

enum class Lab::Unit : std::uint8_t
strong

How a value is printed: fraction as percent, or a plain number.

Enumerator
Number 
Percent 

◆ Verdict

enum class Lab::Verdict : std::uint8_t
strong
Enumerator
Pass 

Point estimate inside the band.

Warn 

Outside, but the 95% interval still overlaps the band.

Fail 

The whole 95% interval lies outside the band.

Info 

Reported without a band.

NotMeasured 

No extractor yet, or no data in this mode.

Function Documentation

◆ bootstrapEstimate()

Estimate Lab::bootstrapEstimate ( std::size_t  units,
const std::function< double(std::span< const std::size_t >)> &  statistic,
std::uint64_t  seed,
int  resamples = 400 
)

Percentile bootstrap for statistics without a closed-form interval (e.g. variance/mean, rate multipliers). Resamples unit indices with a fixed-seed generator, so the interval is deterministic. statistic receives the indices of one resample (the identity resample for the point estimate) and returns NaN when undefined; such resamples are skipped.

◆ buildLabLineup()

Lineup Lab::buildLabLineup ( TeamID  team_id,
float  rating,
std::vector< std::unique_ptr< Player > > &  pool 
)

4-4-2 matchday squad (eleven starters, seven reserves) whose attributes are role-shaped offsets around rating with a small deterministic per-player spread. Same construction as test/test_match_calibration.cpp (createCalibrationTeam), duplicated so the lab does not depend on tests, except that the spread depends on the squad slot only: two squads of the same rating are identical (the test's ID-based spread makes team 1 about 2.3 attribute points stronger than team 2). Players are owned by pool and get IDs team_id * 100 + index.

◆ classify()

Verdict Lab::classify ( const Estimate &  estimate,
const std::optional< Band > &  band 
)

PASS when the point estimate lies in the band, WARN when it does not but the interval overlaps the band, FAIL when the whole interval is outside. No band gives Info, an invalid estimate NotMeasured.

◆ evaluateTargets()

std::vector< ReportRow > Lab::evaluateTargets ( const std::map< std::string, Estimate > &  metrics,
std::span< const Scope >  scopes 
)

Evaluates every target of scope_filter against the measured metrics. Targets whose metric is missing are kept as NOT MEASURED rows with a note, so the report always lists the full spec table.

◆ formatValue()

std::string Lab::formatValue ( double  value,
Unit  unit 
)

"12.3%" or "2.83" (digits chosen from the magnitude).

◆ lineupRating()

float Lab::lineupRating ( const Lineup &  lineup,
const StatsConfig &  config 
)

Mean overall of the eleven starters (the contract's team rating).

◆ loadStatsConfig()

StatsConfig Lab::loadStatsConfig ( )

The game's stats configuration (assets/config/stats_config.json), so lab players rate exactly like generated ones; the calibration-test constants when the file cannot be read.

◆ matchMetrics()

std::map< std::string, Estimate > Lab::matchMetrics ( std::span< const MatchSample >  samples)

Every match metric computable from the samples (abandoned matches are excluded and counted in abandoned_share). Keys are TargetSpec::metric names; definitions sit next to each metric in lab_runner.cpp.

◆ matchSeed()

std::uint32_t Lab::matchSeed ( std::uint64_t  seed,
std::uint64_t  index 
)

Deterministic 32-bit match seed number index of a run seeded seed.

◆ matchTables()

std::vector< TextTable > Lab::matchTables ( std::span< const MatchSample >  samples)

Total-goals histogram, top scorelines and goal timing.

◆ meanEstimate()

Estimate Lab::meanEstimate ( std::span< const double >  values)

Mean of per-unit values; t interval mean +- t * sd / sqrt(n), lower bound clamped at 0 when every value is non-negative.

◆ medianEstimate()

Estimate Lab::medianEstimate ( std::span< const double >  values)

Median with a distribution-free (binomial order-statistic) interval.

◆ proportionEstimate()

Estimate Lab::proportionEstimate ( std::size_t  successes,
std::size_t  trials 
)

Share of successes; Wilson score interval (z = 1.96).

◆ ratingGapTable()

TextTable Lab::ratingGapTable ( std::span< const MatchSample >  samples)

Stronger-side results by rating-gap band (NFR-019).

◆ ratioEstimate()

Estimate Lab::ratioEstimate ( std::span< const double >  numerators,
std::span< const double >  denominators 
)

Ratio of sums sum(num) / sum(den) over sampling units (e.g. goals per shot with matches as units). Delta-method interval: var(R) = sum((num_i - R den_i)^2) / (n (n - 1) mean(den)^2). Units with den = 0 still count (their numerator must then be 0). The lower bound is clamped at 0 when all inputs are non-negative.

◆ reportFromJson()

LabReport Lab::reportFromJson ( const nlohmann::json &  json)

Inverse of toJson(); throws nlohmann::json::exception on bad input.

◆ runSeasons()

LabReport Lab::runSeasons ( const SeasonOptions &  options)

Creates a new AI-only career (no managed club) in the current runtime root, which the caller must point at a scratch directory (FM_RUNTIME_ROOT), and simulates seasons full seasons through GameController::advanceDay(). Throws std::invalid_argument for a bad league filter or season count and std::runtime_error when a season does not complete.

◆ sampleFromReport()

MatchSample Lab::sampleFromReport ( const MatchReport &  report)

Summary of a structured world match report (not detailed).

◆ simulateMatch()

MatchSample Lab::simulateMatch ( const MatchJob &  job,
const StatsConfig &  config 
)

Simulates one isolated match on the calling thread with fresh squads (no state is shared between jobs). Throws SimulationError.

◆ simulateMatches()

std::vector< MatchSample > Lab::simulateMatches ( std::span< const MatchJob >  jobs,
const StatsConfig &  config,
unsigned  threads,
const std::function< void(std::size_t)> &  progress = nullptr 
)

Simulates every job on threads threads (caller included) through the shared ThreadPool; sample i belongs to job i, so the output does not depend on the thread count. progress (optional) is called from the calling thread with the number of finished jobs.

◆ tacticJobs()

std::vector< MatchJob > Lab::tacticJobs ( std::uint64_t  seed,
int  seeds_per_pair,
float  rating 
)

Round robin of TACTIC_PRESETS between equal teams: for each pair and each of seeds_per_pair seeds, both home/away orders with the same seed.

◆ tacticMetrics()

void Lab::tacticMetrics ( std::span< const MatchSample >  samples,
int  seeds_per_pair,
std::map< std::string, Estimate > &  metrics,
std::vector< TextTable > &  tables 
)

SC-004 metric plus the per-preset results table.

◆ tacticPresetsOf()

std::array< std::size_t, 2 > Lab::tacticPresetsOf ( std::size_t  job_index,
int  seeds_per_pair 
)

Preset of each side of tacticJobs() job i.

◆ targetTable()

std::span< const TargetSpec > Lab::targetTable ( )

Every CT-M/CT-W row of the spec plus the lab's INFO metrics.

◆ tierName()

std::string_view Lab::tierName ( Tier  tier)

◆ toJson()

nlohmann::json Lab::toJson ( const LabReport &  report)

◆ toMarkdown()

std::string Lab::toMarkdown ( const LabReport &  report)

◆ tQuantile975()

double Lab::tQuantile975 ( std::size_t  degrees_of_freedom)

Two-sided 97.5% quantile of Student's t (1.96 for large samples).

◆ verdictName()

std::string_view Lab::verdictName ( Verdict  verdict)

Variable Documentation

◆ GOAL_TIME_BINS

constexpr std::size_t Lab::GOAL_TIME_BINS = 6
inlineconstexpr

Goal timing bins: 0-15, 16-30, 31-45+, 46-60, 61-75, 76-90+.

◆ MONITOR_PASS_THRESHOLD

constexpr double Lab::MONITOR_PASS_THRESHOLD = 0.9
inlineconstexpr

Minimum Monitor pass rate (NFR-018).

◆ TACTIC_PRESETS

constexpr std::array<TacticPreset, 4> Lab::TACTIC_PRESETS
inlineconstexpr
Initial value:
{{
{"Balanced", {0.50f, 0.50f, 0.50f, 0.50f, 0.50f}},
{"Front foot", {0.82f, 0.72f, 0.76f, 0.68f, 0.64f}},
{"Counter", {0.38f, 0.68f, 0.62f, 0.58f, 0.42f}},
{"Control", {0.62f, 0.34f, 0.44f, 0.72f, 0.72f}},
}}

The four presets of the tactics screen (gui/scenes/strategy_scene.cpp, PRESETS). Duplicated because the GUI table lives in an anonymous namespace of fm_ui; keep both in sync.