Player12
An open source football management simulator
Loading...
Searching...
No Matches
strategy.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 <algorithm>
12#include <vector>
13
14#include "model/tactics.h"
15
27{
28 float pressing = 0.5f;
29 float riskTaking =
30 0.5f;
32 0.5f;
33 float widthUsage = 0.5f;
34 float compactness = 0.5f;
35};
36
46{
47 float attackWeight = 0.5f;
48 float defenseWeight = 0.5f;
50};
51
61{
62 public:
66 Strategy();
67
79 float getAttackWeight(int roleIndex, int gridPosition) const;
80
88 float getDefenseWeight(int roleIndex, int gridPosition) const;
89
91 void setPressing(float value)
92 {
93 sliders.pressing = std::clamp(value, 0.0f, 1.0f);
94 }
95
97 void setRiskTaking(float value)
98 {
99 sliders.riskTaking = std::clamp(value, 0.0f, 1.0f);
100 }
101
103 void setOffensiveBias(float value)
104 {
105 sliders.offensiveBias = std::clamp(value, 0.0f, 1.0f);
106 }
107
109 void setWidthUsage(float value)
110 {
111 sliders.widthUsage = std::clamp(value, 0.0f, 1.0f);
112 }
113
115 void setCompactness(float value)
116 {
117 sliders.compactness = std::clamp(value, 0.0f, 1.0f);
118 }
119
120 // --- Setters for player role weights ---
128 void setOutfieldWeights(int playerIndex, float attack, float defense,
129 int radius);
130
136 RoleWeights& getRole(int roleIndex);
137
143 const RoleWeights& getRole(int roleIndex) const;
144
149 void setAllSliders(const StrategySliders& newSliders);
150
156
163 void setAllOutfieldWeights(float attack, float defense, int radius);
164
165 // --- Roles, duties and the in-possession shape ---
167 const std::vector<SlotInstruction>& getSlotInstructions() const
168 {
169 return slots;
170 }
172 void setSlotInstructions(std::vector<SlotInstruction> instructions);
177 const SlotInstruction* findSlot(Vector2F anchor) const;
179 void setSlot(const SlotInstruction& instruction);
181 void setKeeperRole(TacticalRole role);
182
187 const std::vector<PlayerInstruction>& getOppositionOrders() const
188 {
189 return opposition_orders;
190 }
191 void setOppositionOrders(std::vector<PlayerInstruction> orders);
192
193 private:
194 // Global sliders affecting all players
196
197 // Per-role weight definitions
198 RoleWeights goalkeeper = {0.0f, 1.0f, 1}; // single goalkeeper
199 RoleWeights outfield[10]; // 10 outfield players
200
201 std::vector<SlotInstruction> slots;
203 std::vector<PlayerInstruction> opposition_orders;
204};
Represents the tactical setup of a team for a match.
Definition strategy.h:61
Strategy()
Default constructor, initializes global sliders and default weights.
Definition strategy.cpp:18
TacticalRole keeper_role
Definition strategy.h:202
void setPressing(float value)
Sets the pressing slider value.
Definition strategy.h:91
RoleWeights goalkeeper
Definition strategy.h:198
void setOppositionOrders(std::vector< PlayerInstruction > orders)
Definition strategy.cpp:171
void setAllOutfieldWeights(float attack, float defense, int radius)
Applies the same weights to all outfield players.
Definition strategy.cpp:72
void setSlotInstructions(std::vector< SlotInstruction > instructions)
Definition strategy.cpp:125
const SlotInstruction * findSlot(Vector2F anchor) const
Definition strategy.cpp:131
StrategySliders getSliders() const
Retrieves the current slider state.
Definition strategy.cpp:60
void setOutfieldWeights(int playerIndex, float attack, float defense, int radius)
Sets the role weights for a specific outfield player.
Definition strategy.cpp:63
float getAttackWeight(int roleIndex, int gridPosition) const
Get weights of a player at a specific grid cell.
Definition strategy.cpp:26
RoleWeights & getRole(int roleIndex)
Gets the role weights for a specific player (non-const).
Definition strategy.cpp:78
std::vector< PlayerInstruction > opposition_orders
Definition strategy.h:203
TacticalRole getKeeperRole() const
Definition strategy.h:180
void setAllSliders(const StrategySliders &newSliders)
Sets all sliders at once.
Definition strategy.cpp:51
std::vector< SlotInstruction > slots
Definition strategy.h:201
const std::vector< SlotInstruction > & getSlotInstructions() const
Definition strategy.h:167
RoleWeights outfield[10]
Definition strategy.h:199
void setOffensiveBias(float value)
Sets the offensive bias slider value.
Definition strategy.h:103
void setCompactness(float value)
Sets the compactness slider value.
Definition strategy.h:115
void setKeeperRole(TacticalRole role)
Definition strategy.cpp:164
float getDefenseWeight(int roleIndex, int gridPosition) const
Get defense weight of a player at a specific grid cell.
Definition strategy.cpp:38
void setRiskTaking(float value)
Sets the risk taking slider value.
Definition strategy.h:97
StrategySliders sliders
Definition strategy.h:195
void setWidthUsage(float value)
Sets the width usage slider value.
Definition strategy.h:109
const std::vector< PlayerInstruction > & getOppositionOrders() const
Definition strategy.h:187
void setSlot(const SlotInstruction &instruction)
Definition strategy.cpp:147
Legacy grid-based strategy weights, retained by the Strategy API.
Definition strategy.h:46
float attackWeight
Definition strategy.h:47
float defenseWeight
Definition strategy.h:48
int movementRadius
Definition strategy.h:49
Role, duty and in-possession spot of one outfield slot. Slots are matched by their out-of-possession ...
Definition tactics.h:126
Team-wide tactical preferences in [0, 1].
Definition strategy.h:27
float pressing
Definition strategy.h:28
float widthUsage
Definition strategy.h:33
float compactness
Definition strategy.h:34
float riskTaking
Definition strategy.h:29
float offensiveBias
Definition strategy.h:31
A simple 2D float vector for pitch coordinates.
Definition types.h:84
TacticalRole
How a player interprets his slot (values are persisted in the tactic). Standard plays the position as...
Definition tactics.h:43