Player12
An open source football management simulator
Loading...
Searching...
No Matches
league.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 <cstdint>
12#include <map>
13#include <optional>
14#include <string>
15#include <vector>
16
17#include "global/types.h"
18
23enum class TieBreakRule : uint8_t
24{
29 HEAD_TO_HEAD = 1
30};
31
40class League
41{
42 public:
51 League(LeagueID league_id, const std::string& league_name,
52 const std::vector<TeamID>& initial_team_ids = {},
53 std::optional<LeagueID> parent = std::nullopt,
55
56 // Accessors
57
62 uint8_t getId() const;
63
68 std::string getName() const;
69
74 const std::vector<TeamID>& getTeamIDs() const;
75
80 void addTeamID(TeamID team_id);
81
86 void removeTeamID(TeamID team_id);
87
93 uint16_t getPoints(TeamID team_id) const;
94
100 void addPoints(TeamID team_id, uint16_t points);
101
107 void setPoints(TeamID team_id, uint16_t points);
108
112 void resetPoints();
113
121 const std::map<TeamID, uint16_t>& getLeaderboard() const;
122
127 std::optional<LeagueID> getParentLeagueID() const;
128
131
132 private:
134 std::string name;
135 const std::optional<LeagueID> parent_league_id;
137 std::vector<TeamID> team_ids;
138 std::map<TeamID, uint16_t> leaderboard; // team_id -> points
139};
Represents a football league containing teams and a leaderboard.
Definition league.h:41
TieBreakRule getTieBreakRule() const
Ordering rule for teams level on points.
Definition league.h:130
TieBreakRule tie_break
Definition league.h:136
void removeTeamID(TeamID team_id)
Removes a team from the league.
Definition league.cpp:46
std::optional< LeagueID > getParentLeagueID() const
Gets the parent league ID, if any.
Definition league.cpp:84
void addTeamID(TeamID team_id)
Adds a team to the league.
Definition league.cpp:37
void addPoints(TeamID team_id, uint16_t points)
Adds points to a specific team.
Definition league.cpp:61
const std::vector< TeamID > & getTeamIDs() const
Gets the IDs of the teams in the league.
Definition league.cpp:35
uint8_t getId() const
Gets the league ID.
Definition league.cpp:31
uint16_t getPoints(TeamID team_id) const
Gets the points of a specific team.
Definition league.cpp:55
std::map< TeamID, uint16_t > leaderboard
Definition league.h:138
std::vector< TeamID > team_ids
Definition league.h:137
void resetPoints()
Resets the points of all teams in the league to zero.
Definition league.cpp:71
std::string name
Definition league.h:134
const std::map< TeamID, uint16_t > & getLeaderboard() const
Gets the league leaderboard.
Definition league.cpp:79
const std::optional< LeagueID > parent_league_id
Definition league.h:135
std::string getName() const
Gets the name of the league.
Definition league.cpp:33
void setPoints(TeamID team_id, uint16_t points)
Sets the points of a specific team.
Definition league.cpp:66
const LeagueID id
Definition league.h:133
TieBreakRule
How teams level on points are ordered (varies by country).
Definition league.h:24
uint8_t LeagueID
Type alias for League identifiers.
Definition types.h:15
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18