GameLogic
 All Data Structures Files Functions Variables Friends
Public Member Functions | Static Public Member Functions | Data Fields
gameModel::Environment Class Reference

#include <GameModel.h>

Public Member Functions

 Environment (communication::messages::broadcast::MatchConfig matchConfig, const communication::messages::request::TeamConfig &teamConfig1, const communication::messages::request::TeamConfig &teamConfig2, communication::messages::request::TeamFormation teamFormation1, communication::messages::request::TeamFormation teamFormation2)
 
 Environment (Config config, std::shared_ptr< Team > team1, std::shared_ptr< Team > team2)
 
 Environment (Config config, std::shared_ptr< Team > team1, std::shared_ptr< Team > team2, std::shared_ptr< Quaffle > quaffle, std::shared_ptr< Snitch > snitch, std::array< std::shared_ptr< Bludger >, 2 > bludgers, std::deque< std::shared_ptr< CubeOfShit >> pileOfShit)
 
bool operator== (const Environment &other) const
 
bool operator!= (const Environment &other) const
 
auto arePlayerInSameTeam (const std::shared_ptr< const Player > &p1, const std::shared_ptr< const Player > &p2) const -> bool
 
auto isPlayerInOwnRestrictedZone (const std::shared_ptr< const Player > &player) const -> bool
 
auto isPlayerInOpponentRestrictedZone (const std::shared_ptr< const Player > &player) const -> bool
 
auto getAllPlayers () const -> std::array< std::shared_ptr< Player >, 14 >
 
auto getTeamMates (const std::shared_ptr< const Player > &player) const -> std::array< std::shared_ptr< Player >, 6 >
 
auto getOpponents (const std::shared_ptr< const Player > &player) const -> std::array< std::shared_ptr< Player >, 7 >
 
bool cellIsFree (const Position &position) const
 
auto getAllFreeCellsAround (const Position &position) const -> std::vector< Position >
 
auto getAllLegalCellsAround (const Position &position, bool leftTeam) const -> std::vector< Position >
 
auto getAllEmptyCellsAround (const Position &position) const -> std::vector< Position >
 
auto getPlayer (const Position &position) const -> std::optional< std::shared_ptr< Player >>
 
auto getPlayerById (communication::messages::types::EntityId id) const -> std::shared_ptr< Player >
 
auto getTeam (const std::shared_ptr< const Player > &player) const -> std::shared_ptr< Team >
 
auto getTeam (TeamSide side) const -> std::shared_ptr< Team >
 
auto getAllFreeCells () const -> std::vector< Position >
 
void placePlayerOnRandomFreeCell (const std::shared_ptr< Player > &player)
 
auto getBallByID (const communication::messages::types::EntityId &id) const -> std::shared_ptr< Ball >
 
void removeDeprecatedShit ()
 
void removeShitOnCell (const Position &position)
 
auto isShitOnCell (const Position &position) const -> bool
 
auto clone () const -> std::shared_ptr< Environment >
 
auto getFreeCellsForRedeploy (const gameModel::TeamSide &teamSide) const -> const std::vector< gameModel::Position >
 

Static Public Member Functions

static Cell getCell (int x, int y)
 
static Cell getCell (const Position &position)
 
static auto getSurroundingPositions (const Position &position) -> std::vector< Position >
 
static auto getGoalsLeft () -> std::array< Position, 3 >
 
static auto getGoalsRight () -> std::array< Position, 3 >
 
static auto isGoalCell (const Position &pos) -> bool
 
static auto getAllValidCells () -> std::array< Position, 193 >
 

Data Fields

Config config
 
std::shared_ptr< Teamteam1
 
std::shared_ptr< Teamteam2
 
std::shared_ptr< Quafflequaffle
 
std::shared_ptr< Snitchsnitch
 
std::array< std::shared_ptr
< Bludger >, 2 > 
bludgers
 
std::deque< std::shared_ptr
< CubeOfShit > > 
pileOfShit
 

Detailed Description

Represents a game state

Constructor & Destructor Documentation

gameModel::Environment::Environment ( communication::messages::broadcast::MatchConfig  matchConfig,
const communication::messages::request::TeamConfig &  teamConfig1,
const communication::messages::request::TeamConfig &  teamConfig2,
communication::messages::request::TeamFormation  teamFormation1,
communication::messages::request::TeamFormation  teamFormation2 
)

Constructs an Environment from server config types

Parameters
matchConfig
teamConfig
teamFormation
gameModel::Environment::Environment ( Config  config,
std::shared_ptr< Team team1,
std::shared_ptr< Team team2 
)

Automatically places all balls at the correct location

Parameters
config
team1
team2
gameModel::Environment::Environment ( Config  config,
std::shared_ptr< Team team1,
std::shared_ptr< Team team2,
std::shared_ptr< Quaffle quaffle,
std::shared_ptr< Snitch snitch,
std::array< std::shared_ptr< Bludger >, 2 >  bludgers,
std::deque< std::shared_ptr< CubeOfShit >>  pileOfShit 
)

Ctor where all members can be specified

Parameters
config
team1
team2
quaffle
snitch
bludgers
pileOfShit

Member Function Documentation

auto gameModel::Environment::arePlayerInSameTeam ( const std::shared_ptr< const Player > &  p1,
const std::shared_ptr< const Player > &  p2 
) const -> bool

tests if two players are in the same team.

Parameters
p1player 1.
p2player 2.
Returns
if the players are in the same team true, else false.
bool gameModel::Environment::cellIsFree ( const Position position) const

Determines whether the given Position is occupied by a Player or Ball

Parameters
positionthe position to be checked
Returns
true if not occupied by any ball or player, false otherwise
auto gameModel::Environment::clone ( ) const -> std::shared_ptr<Environment>

returns a deep copy of the current Environment

Returns
auto gameModel::Environment::getAllEmptyCellsAround ( const Position position) const -> std::vector<Position>

Gets all Positions around a given Position where no Object is located. If all surrounding Positions are occupied, an empty list is returned

Parameters
positionthe Position to be checked
Returns
auto gameModel::Environment::getAllFreeCells ( ) const -> std::vector<Position>

Gets all valid cells not occupied by players or balls

Returns
auto gameModel::Environment::getAllFreeCellsAround ( const Position position) const -> std::vector<Position>

get all Positions around a given position where no other player or ball is on. If all surrounding cells are blocked the search window is enlarged until a free cell is found

Parameters
positionthe position to be checked
Returns
auto gameModel::Environment::getAllLegalCellsAround ( const Position position,
bool  leftTeam 
) const -> std::vector<Position>

Gets all Positions around the given Position where a player is allowed to move without risking a foul

Parameters
positionthe Position to check
leftTeamwhether to calculate Position for the left Team
Returns
a list with all found Positions, may be empty
auto gameModel::Environment::getAllPlayers ( ) const -> std::array<std::shared_ptr<Player>, 14>

Gets all players in the game

Returns
auto gameModel::Environment::getAllValidCells ( ) -> std::array<Position, 193>
static

Gets all Positions which are not out of bounds

Returns
auto gameModel::Environment::getBallByID ( const communication::messages::types::EntityId &  id) const -> std::shared_ptr<Ball>

Get the corresponding ball object to an given id.

Parameters
idthe id of the ball.
Returns
the corresponding ball object.
Cell gameModel::Environment::getCell ( int  x,
int  y 
)
static

Gets the type of the cell at position (x,y)

Parameters
xxPosition from left, 0 based
yyPosition from bottom, 0 based
Returns
The corresponding Cell
Cell gameModel::Environment::getCell ( const Position position)
static

See overloaded function above

Parameters
position
Returns
auto gameModel::Environment::getFreeCellsForRedeploy ( const gameModel::TeamSide &  teamSide) const -> const std::vector<gameModel::Position>
Parameters
teamSideTeamside of the Player being redeployed
envthe current Enivironment
Returns
list of possible Positions for redeploy
auto gameModel::Environment::getGoalsLeft ( ) -> std::array<Position, 3>
static

Gets all goal cells in left half of the game field.

Returns
auto gameModel::Environment::getGoalsRight ( ) -> std::array<Position, 3>
static

Gets all goal cells in right half of the game field.

Returns
auto gameModel::Environment::getOpponents ( const std::shared_ptr< const Player > &  player) const -> std::array<std::shared_ptr<Player>, 7>

Gets all players from the opponent team of the given player

Parameters
player
Returns
auto gameModel::Environment::getPlayer ( const Position position) const -> std::optional<std::shared_ptr<Player>>

Returns player object (if not banned) at the specified position if one exists

Returns
player on the specified position, or nothing of no player is located on the specified position
auto gameModel::Environment::getPlayerById ( communication::messages::types::EntityId  id) const -> std::shared_ptr<Player>

gets player by server entity id

Parameters
id
Exceptions
runtime_errorwhen player cannot be found
Returns
auto gameModel::Environment::getSurroundingPositions ( const Position position) -> std::vector<Position>
static

Gets all valid Position surrounding the given position

Parameters
position
Returns
auto gameModel::Environment::getTeam ( const std::shared_ptr< const Player > &  player) const -> std::shared_ptr<Team>

get the corresponding team of a player.

Parameters
playerthe selected player.
Returns
the team of a player.
auto gameModel::Environment::getTeam ( TeamSide  side) const -> std::shared_ptr<Team>

Gets the team on the specified side

Parameters
sidethe side of the team
Returns
auto gameModel::Environment::getTeamMates ( const std::shared_ptr< const Player > &  player) const -> std::array<std::shared_ptr<Player>, 6>

Gets all players in the same team as the given player, themselves excluded

Parameters
player
Returns
auto gameModel::Environment::isGoalCell ( const Position pos) -> bool
static

Checks if a given cell is a goal cell.

Parameters
pos
Returns
auto gameModel::Environment::isPlayerInOpponentRestrictedZone ( const std::shared_ptr< const Player > &  player) const -> bool

checks if a player is in the opponent restricted zone.

Parameters
playerthe player.
Returns
true if player is in opponent restricted zone, else false;
auto gameModel::Environment::isPlayerInOwnRestrictedZone ( const std::shared_ptr< const Player > &  player) const -> bool

checks if a player is in the own restricted zone.

Parameters
playerthe player.
Returns
true if player is in own restricted zone, else false;
auto gameModel::Environment::isShitOnCell ( const Position position) const -> bool
Parameters
positionis the Position to test
Returns
returns true, if Shit is on the Position, false otherwise
void gameModel::Environment::placePlayerOnRandomFreeCell ( const std::shared_ptr< Player > &  player)

place a player on random free cell in their half of the game field.

Parameters
player
void gameModel::Environment::removeDeprecatedShit ( )

Removes all the cubes of shit spawned during the last round

void gameModel::Environment::removeShitOnCell ( const Position position)

removes Shit on a given Position

Parameters
positionis the Position of the CubeOfShit which should be removed

The documentation for this class was generated from the following files: