74 std::vector<std::vector<std::shared_ptr<Pawn>>>
pawns;
129 void print(
char)
const;
156 virtual void addPawn(std::shared_ptr<Pawn>);
368 void movePawnFromTo(
unsigned short,
unsigned short,
unsigned short,
unsigned short);
435 Pawn*
getPawn(
unsigned short,
unsigned short)
const;
465 bool isOccupied(
unsigned short,
unsigned short)
const;
549 bool isFree(
unsigned short,
unsigned short)
const;
565 bool isFree(
short int,
short int)
const;
681 auto h1 = std::hash<sista::Coordinates>{}(k.begin);
682 auto h2 = std::hash<sista::Coordinates>{}(k.end);
683 return h1 ^ (h2 << 1);
706 std::vector<std::vector<short int>> pawnsCount;
708 std::set<Path> pawnsToSwap;
710 Coordinates firstInvalidCell(std::map<Coordinates, short int>&)
const;
719 void clearPawnsToSwap();
751 void addPawn(std::shared_ptr<Pawn>)
override;
Border class header file.
Represents a brick of the border with a symbol and ANSI settings.
Definition: border.hpp:34
Represents a 2D grid where Pawns can be placed, moved, and managed.
Definition: field.hpp:71
void movePawn(Pawn *, const Coordinates &)
Moves a Pawn to new coordinates.
Definition: field.cpp:169
Pawn * getPawn(const Coordinates &) const
Gets the Pawn at specified coordinates.
Definition: field.cpp:258
Cursor cursor
Definition: field.hpp:75
void addPrintPawn(std::shared_ptr< Pawn >)
Adds a Pawn to the field at its specified coordinates and prints it.
Definition: field.cpp:159
int height
Definition: field.hpp:77
void cleanCoordinates(const Coordinates &) const
Cleans the coordinates on screen by printing spaces.
Definition: field.cpp:149
Coordinates movingByCoordinates(Pawn *, short int, short int) const
Calculates the new coordinates of a Pawn after moving by a relative offset.
Definition: field.cpp:385
std::vector< std::vector< std::shared_ptr< Pawn > > > pawns
2D grid of shared pointers to Pawn objects.
Definition: field.hpp:74
void validateCoordinates(const Coordinates &) const
Validates that the given coordinates are within bounds and not occupied.
Definition: field.cpp:296
virtual ~Field()=default
Destructor to clean up resources.
virtual void erasePawn(Pawn *)
Removes a Pawn from the field at specified coordinates.
Definition: field.cpp:139
void movePawnBy(Pawn *, const Coordinates &)
Moves a Pawn by a relative offset.
Definition: field.cpp:195
void movePawnFromTo(const Coordinates &, const Coordinates &)
Moves a Pawn from one set of coordinates to another.
Definition: field.cpp:245
bool isFree(const Coordinates &) const
Checks if specified coordinates are free (not occupied by a Pawn).
Definition: field.cpp:285
virtual void addPawn(std::shared_ptr< Pawn >)
Adds a Pawn to the field at its specified coordinates.
Definition: field.cpp:126
int width
Definition: field.hpp:76
virtual void removePawn(Pawn *)
Removes a Pawn from the field.
Definition: field.cpp:133
void print() const
Prints the entire field to the terminal.
Definition: field.cpp:42
void clear()
Clears the field by removing all Pawns and resetting the grid.
Definition: field.cpp:26
bool isOutOfBounds(const Coordinates &) const
Checks if specified coordinates are out of bounds.
Definition: field.cpp:275
bool isOccupied(const Coordinates &) const
Checks if specified coordinates are occupied by a Pawn.
Definition: field.cpp:265
void rePrintPawn(Pawn *)
Reprints a Pawn at its current coordinates.
Definition: field.cpp:164
Represents an object on the field with a symbol, coordinates, and ANSI settings.
Definition: pawn.hpp:37
A specialized Field that handles Pawn swaps without conflicts.
Definition: field.hpp:703
void addPawn(std::shared_ptr< Pawn >) override
Adds a Pawn to the field and updates the pawnsCount grid.
Definition: field.cpp:352
void simulateSwaps()
Simulates the swaps of the pawnsToSwap and removes unfeasible paths.
Definition: field.cpp:467
void swapTwoPawns(const Coordinates &, const Coordinates &)
Swaps two Pawns at the specified coordinates.
Definition: field.cpp:533
~SwappableField()
Destructor to clean up resources.
Definition: field.cpp:345
void movePawn(Pawn *, const Coordinates &)
Moves a Pawn to new coordinates and updates the pawnsCount grid.
Definition: field.cpp:363
void applySwaps()
Applies the swaps of the pawnsToSwap to the field.
Definition: field.cpp:511
void removePawn(Pawn *) override
Removes a Pawn from the field and updates the pawnsCount grid.
Definition: field.cpp:357
void addPawnToSwap(Pawn *, const Coordinates &)
Adds a Pawn to the set of pawnsToSwap.
Definition: field.cpp:430
Cursor manipulation header file.
Sista library namespace.
Definition: ansi.cpp:26
Effect
Enumeration for handling out-of-bounds coordinates.
Definition: field.hpp:50
Definition: coordinates.hpp:115
Represents 2D coordinates with x and y values.
Definition: coordinates.hpp:31
Manages terminal cursor operations.
Definition: cursor.hpp:132
Represents a movement path for a Pawn, including priority handling.
Definition: field.hpp:613
bool operator==(const Path &) const
Overloaded operator to check if two paths are equal (same begin and end coordinates).
Definition: field.cpp:322
int priority
Definition: field.hpp:615
Coordinates end
Definition: field.hpp:617
bool operator|(const Path &) const
Overloaded operator to check if two paths are opposite (reverse of each other).
Definition: field.cpp:313
static long long int current_priority
Definition: field.hpp:614
bool operator<(const Path &) const
Overloaded operator to compare paths based on priority.
Definition: field.cpp:319
Pawn * pawn
Definition: field.hpp:618
Coordinates begin
Definition: field.hpp:616
std::size_t operator()(const sista::Path &k) const noexcept
Definition: field.hpp:680