Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_scheduler.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <array>
12#include <atomic>
13#include <cstdint>
14#include <memory>
15#include <optional>
16#include <utility>
17#include <vector>
18
19#include "global/stats_config.h"
20#include "global/thread_pool.h"
21#include "global/types.h"
22#include "model/competition.h"
23#include "model/lineup.h"
24#include "model/match_context.h"
25#include "model/match_report.h"
26#include "model/match_rules.h"
27#include "model/strategy.h"
29
37{
40 uint32_t seed = 0;
55 std::array<float, 2> home_talk{};
56 std::array<float, 2> away_talk{};
59 std::vector<std::pair<PlayerID, std::uint8_t>> medical_flags;
67 std::optional<MatchContext> context_override;
68};
69
72{
73 uint8_t home_goals = 0;
74 uint8_t away_goals = 0;
75 bool extra_time = false;
76 std::optional<std::pair<uint8_t, uint8_t>> penalties;
79 std::optional<bool> tie_winner_home;
81 std::vector<PlayerMatchConsequence> consequences;
82};
83
85{
94
97 const StatsConfig& config);
98} // namespace MatchSimulation
99
102{
103 uint32_t completed = 0;
104 uint32_t total = 0;
105};
106
115{
116 public:
117 explicit MatchScheduler(
118 unsigned thread_count = ThreadPool::defaultThreadCount());
119
121 void setThreadCount(unsigned thread_count);
122 unsigned getThreadCount() const { return threads; }
123
125 std::vector<MatchSimulationResult> run(
126 const std::vector<MatchSimulationInput>& inputs,
127 const StatsConfig& config);
128
131 {
132 completed.store(0, std::memory_order_relaxed);
133 total.store(0, std::memory_order_relaxed);
134 }
137 {
138 return {completed.load(std::memory_order_relaxed),
139 total.load(std::memory_order_relaxed)};
140 }
141
142 private:
143 unsigned threads = 1;
144 std::unique_ptr<ThreadPool> pool;
145 std::atomic<uint32_t> completed{0};
146 std::atomic<uint32_t> total{0};
147};
Manages the starting XI and reserves of a team.
Definition lineup.h:85
Simulates a batch of independent matches in parallel.
Definition match_scheduler.h:115
void setThreadCount(unsigned thread_count)
Definition match_scheduler.cpp:119
std::unique_ptr< ThreadPool > pool
Definition match_scheduler.h:144
std::atomic< uint32_t > total
Definition match_scheduler.h:146
std::atomic< uint32_t > completed
Definition match_scheduler.h:145
void resetProgress()
Definition match_scheduler.h:130
SimulationProgress getProgress() const
Definition match_scheduler.h:136
unsigned threads
Definition match_scheduler.h:143
unsigned getThreadCount() const
Definition match_scheduler.h:122
Represents the tactical setup of a team for a match.
Definition strategy.h:61
static unsigned defaultThreadCount()
Definition thread_pool.cpp:148
float run
Definition match_stadium_3d.cpp:388
Definition match_scheduler.h:85
MatchContext leagueContext(LeagueID league_id)
Definition match_scheduler.cpp:28
Contains structures to simplify JSON parsing and loading of player statistics.
Definition match_context.h:26
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
Definition match_rules.h:48
Definition match_scheduler.h:37
uint32_t seed
Definition match_scheduler.h:40
std::optional< MatchContext > context_override
Definition match_scheduler.h:67
Lineup home_lineup
Definition match_scheduler.h:41
std::array< float, 2 > away_talk
Definition match_scheduler.h:56
std::array< float, 2 > home_talk
Definition match_scheduler.h:55
TeamID home_id
Definition match_scheduler.h:38
MatchRules::Knockout knockout
Definition match_scheduler.h:50
Strategy away_strategy
Definition match_scheduler.h:44
TeamID away_id
Definition match_scheduler.h:39
std::vector< std::pair< PlayerID, std::uint8_t > > medical_flags
Definition match_scheduler.h:59
LeagueID league_id
Definition match_scheduler.h:53
Lineup away_lineup
Definition match_scheduler.h:42
Strategy home_strategy
Definition match_scheduler.h:43
Definition match_scheduler.h:72
uint8_t away_goals
Definition match_scheduler.h:74
MatchReport report
Definition match_scheduler.h:80
uint8_t home_goals
Definition match_scheduler.h:73
std::optional< bool > tie_winner_home
Definition match_scheduler.h:79
std::vector< PlayerMatchConsequence > consequences
Definition match_scheduler.h:81
bool extra_time
Definition match_scheduler.h:75
std::optional< std::pair< uint8_t, uint8_t > > penalties
Definition match_scheduler.h:76
Definition match_scheduler.h:102
uint32_t completed
Definition match_scheduler.h:103
uint32_t total
Definition match_scheduler.h:104
Configuration mapping roles to their focus areas and listing all possible stats.
Definition stats_config.h:42
uint8_t LeagueID
Type alias for League identifiers.
Definition types.h:15
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18