change Position and Polynomio structs (less memory usage)
Some checks failed
Linux arm64 / Build (push) Failing after 2m9s

This commit is contained in:
2025-07-19 20:50:36 +02:00
parent 161c9425ae
commit d5b51213c8
10 changed files with 64 additions and 64 deletions

View File

@@ -44,7 +44,7 @@ void GameBoard::initialize() {
bool GameBoard::moveLeft() {
this->movedLeftLast = true;
if (this->activePieceInWall(Position{-1, 0})) {
if (this->activePieceInWall(Position(-1, 0))) {
return false;
}
else {
@@ -57,7 +57,7 @@ bool GameBoard::moveLeft() {
bool GameBoard::moveRight() {
this->movedLeftLast = false;
if (this->activePieceInWall(Position{1, 0})) {
if (this->activePieceInWall(Position(1, 0))) {
return false;
}
else {
@@ -68,7 +68,7 @@ bool GameBoard::moveRight() {
}
bool GameBoard::moveDown() {
if (this->activePieceInWall(Position{0, -1})) {
if (this->activePieceInWall(Position(0, -1))) {
return false;
}
else {
@@ -100,10 +100,10 @@ bool GameBoard::rotate(Rotation rotation) {
for (Position position : stored.getPositions()) {
Position positionInGrid(position + this->activePiecePosition);
safePositions.insert(positionInGrid);
safePositions.insert(positionInGrid + Position{0, 1});
safePositions.insert(positionInGrid + Position{1, 0});
safePositions.insert(positionInGrid + Position{0, -1});
safePositions.insert(positionInGrid + Position{-1, 0});
safePositions.insert(positionInGrid + Position(0, 1));
safePositions.insert(positionInGrid + Position(1, 0));
safePositions.insert(positionInGrid + Position(0, -1));
safePositions.insert(positionInGrid + Position(-1, 0));
}
// first try kicking the piece down
@@ -147,18 +147,18 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set<Position>& safePos
// we first check the side to which the player moved last
if (movedLeftLast) {
if (overlapsLeft) {
if (this->tryFittingKickedPiece(safePositions, Position({-i, j}), overlapsLeft)) return true;
if (this->tryFittingKickedPiece(safePositions, Position(-i, j), overlapsLeft)) return true;
}
if (overlapsRight) {
if (this->tryFittingKickedPiece(safePositions, Position({+i, j}), overlapsRight)) return true;
if (this->tryFittingKickedPiece(safePositions, Position(+i, j), overlapsRight)) return true;
}
}
else {
if (overlapsRight) {
if (this->tryFittingKickedPiece(safePositions, Position({+i, j}), overlapsRight)) return true;
if (this->tryFittingKickedPiece(safePositions, Position(+i, j), overlapsRight)) return true;
}
if (overlapsLeft) {
if (this->tryFittingKickedPiece(safePositions, Position({-i, j}), overlapsLeft)) return true;
if (this->tryFittingKickedPiece(safePositions, Position(-i, j), overlapsLeft)) return true;
}
}
@@ -265,11 +265,11 @@ bool GameBoard::activePieceInWall(const Position& shift) const {
}
bool GameBoard::touchesGround() const {
return this->activePieceInWall(Position{0, -1});
return this->activePieceInWall(Position(0, -1));
}
Position GameBoard::lowestPosition() const {
Position shift = Position{0, -1};
Position shift = Position(0, -1);
while (!activePieceInWall(shift)) {
shift.y -= 1;
}
@@ -278,8 +278,8 @@ Position GameBoard::lowestPosition() const {
}
LineClear GameBoard::lockPiece() {
bool isLockedInPlace = (this->activePieceInWall(Position{0, 1}) && this->activePieceInWall(Position{1, 0})
&& this->activePieceInWall(Position{-1, 0}) && this->activePieceInWall(Position{0, -1}));
bool isLockedInPlace = (this->activePieceInWall(Position(0, 1)) && this->activePieceInWall(Position(1, 0))
&& this->activePieceInWall(Position(-1, 0)) && this->activePieceInWall(Position(0, -1)));
for (Position position : this->activePiece->getPositions()) {
this->board.changeBlock(position + this->activePiecePosition, this->activePiece->getBlockType());
@@ -345,7 +345,7 @@ std::ostream& operator<<(std::ostream& os, const GameBoard& gameboard) {
// print only the position were the active piece is
for (int y = gameboard.activePiecePosition.y + gameboard.activePiece->getLength() - 1; y >= gameboard.board.getBaseHeight(); y--) {
for (int x = 0; x < gameboard.board.getWidth(); x++) {
bool hasActivePiece = gameboard.activePiece->getPositions().contains(Position{x, y} - gameboard.activePiecePosition);
bool hasActivePiece = gameboard.activePiece->getPositions().contains(Position(x, y) - gameboard.activePiecePosition);
if (hasActivePiece) {
os << "*";
}
@@ -361,7 +361,7 @@ std::ostream& operator<<(std::ostream& os, const GameBoard& gameboard) {
Block pieceBlockType = (gameboard.activePiece == nullptr) ? NOTHING : gameboard.activePiece->getBlockType();
for (int y = gameboard.board.getBaseHeight() - 1; y >= 0; y--) {
for (int x = 0; x < gameboard.board.getWidth(); x++) {
bool hasActivePiece = (gameboard.activePiece == nullptr) ? false : gameboard.activePiece->getPositions().contains(Position{x, y} - gameboard.activePiecePosition);
bool hasActivePiece = (gameboard.activePiece == nullptr) ? false : gameboard.activePiece->getPositions().contains(Position(x, y) - gameboard.activePiecePosition);
// the active piece takes visual priority over the board
if (hasActivePiece) {
@@ -369,7 +369,7 @@ std::ostream& operator<<(std::ostream& os, const GameBoard& gameboard) {
os << "*";
}
else {
Block block = gameboard.board.getBlock(Position{x, y});
Block block = gameboard.board.getBlock(Position(x, y));
os << getConsoleColorCode(block);
if (block != NOTHING) {
os << "*";