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

Formation presets and XI selection built on the Lineup API. More...

Classes

struct  Preset
 A named arrangement of ten outfield slots. More...
 
struct  Slot
 One outfield slot of a formation. More...
 

Functions

float roleFit (PlayerRole actual, PlayerRole expected)
 How well a player's natural role suits a slot role, in [0, 1]. 1 means natural; adjacent roles score partially; goalkeepers and outfield players never swap.
 
void applyPreset (Lineup &lineup, const Preset &preset, const StatsConfig &config)
 Moves the current outfield players into the preset's slots, keeping the same eleven and matching players to the slots that suit them best.
 
void autoPick (Lineup &lineup, const Preset &preset, std::span< const Player *const > squad, const StatsConfig &config)
 Chooses the best goalkeeper and ten outfield players from the squad for the preset, places them, and puts everyone else on the bench.
 
void autoPickAvailable (Lineup &lineup, const Preset &preset, std::span< const Player *const > squad, const std::unordered_set< PlayerID > &unavailable, const StatsConfig &config)
 autoPick() that leaves unavailable players (injured, suspended) out of the matchday squad (the lineup screen lists them with the rest).
 
size_t unavailableStarters (const Lineup &lineup, const std::unordered_set< PlayerID > &unavailable)
 Selected starters (goalkeeper and outfield) found in the set.
 
int detectPreset (const Lineup &lineup)
 Index of the preset matching the current positions, or -1 when the shape has been customised.
 

Variables

const std::array< Preset, 5 > PRESETS
 4-4-2, 4-3-3, 4-2-3-1, 3-5-2 and 5-3-2.
 

Detailed Description

Formation presets and XI selection built on the Lineup API.

Pitch coordinates follow Lineup: x runs from the own goal (0) to the opponent's goal (1), y from the left touchline (0) to the right (1).

Function Documentation

◆ applyPreset()

void Formation::applyPreset ( Lineup &  lineup,
const Preset &  preset,
const StatsConfig &  config 
)

Moves the current outfield players into the preset's slots, keeping the same eleven and matching players to the slots that suit them best.

◆ autoPick()

void Formation::autoPick ( Lineup &  lineup,
const Preset &  preset,
std::span< const Player *const >  squad,
const StatsConfig &  config 
)

Chooses the best goalkeeper and ten outfield players from the squad for the preset, places them, and puts everyone else on the bench.

◆ autoPickAvailable()

void Formation::autoPickAvailable ( Lineup &  lineup,
const Preset &  preset,
std::span< const Player *const >  squad,
const std::unordered_set< PlayerID > &  unavailable,
const StatsConfig &  config 
)

autoPick() that leaves unavailable players (injured, suspended) out of the matchday squad (the lineup screen lists them with the rest).

◆ detectPreset()

int Formation::detectPreset ( const Lineup &  lineup)

Index of the preset matching the current positions, or -1 when the shape has been customised.

◆ roleFit()

float Formation::roleFit ( PlayerRole  actual,
PlayerRole  expected 
)

How well a player's natural role suits a slot role, in [0, 1]. 1 means natural; adjacent roles score partially; goalkeepers and outfield players never swap.

◆ unavailableStarters()

size_t Formation::unavailableStarters ( const Lineup &  lineup,
const std::unordered_set< PlayerID > &  unavailable 
)

Selected starters (goalkeeper and outfield) found in the set.

Variable Documentation

◆ PRESETS

const std::array< Preset, 5 > Formation::PRESETS
Initial value:
= {{
{"4-4-2", {{{LB, {0.20f, 0.12f}}, {CB, {0.20f, 0.38f}}, {CB, {0.20f, 0.62f}},
{RB, {0.20f, 0.88f}}, {LM, {0.43f, 0.12f}}, {CM, {0.43f, 0.38f}},
{CM, {0.43f, 0.62f}}, {RM, {0.43f, 0.88f}}, {ST, {0.78f, 0.38f}},
{ST, {0.78f, 0.62f}}}}},
{"4-3-3", {{{LB, {0.20f, 0.12f}}, {CB, {0.20f, 0.38f}}, {CB, {0.20f, 0.62f}},
{RB, {0.20f, 0.88f}}, {CM, {0.44f, 0.28f}}, {CDM, {0.38f, 0.50f}},
{CM, {0.44f, 0.72f}}, {LW, {0.72f, 0.14f}}, {ST, {0.80f, 0.50f}},
{RW, {0.72f, 0.86f}}}}},
{"4-2-3-1", {{{LB, {0.20f, 0.12f}}, {CB, {0.20f, 0.38f}}, {CB, {0.20f, 0.62f}},
{RB, {0.20f, 0.88f}}, {CDM, {0.37f, 0.38f}}, {CDM, {0.37f, 0.62f}},
{LW, {0.60f, 0.15f}}, {CAM, {0.58f, 0.50f}}, {RW, {0.60f, 0.85f}},
{ST, {0.80f, 0.50f}}}}},
{"3-5-2", {{{CB, {0.20f, 0.26f}}, {CB, {0.18f, 0.50f}}, {CB, {0.20f, 0.74f}},
{LM, {0.46f, 0.09f}}, {CM, {0.45f, 0.32f}}, {CDM, {0.38f, 0.50f}},
{CM, {0.45f, 0.68f}}, {RM, {0.46f, 0.91f}}, {ST, {0.78f, 0.38f}},
{ST, {0.78f, 0.62f}}}}},
{"5-3-2", {{{LB, {0.27f, 0.08f}}, {CB, {0.20f, 0.30f}}, {CB, {0.18f, 0.50f}},
{CB, {0.20f, 0.70f}}, {RB, {0.27f, 0.92f}}, {CM, {0.44f, 0.28f}},
{CM, {0.42f, 0.50f}}, {CM, {0.44f, 0.72f}}, {ST, {0.76f, 0.38f}},
{ST, {0.76f, 0.62f}}}}},
}}

4-4-2, 4-3-3, 4-2-3-1, 3-5-2 and 5-3-2.