fixed game logic

This commit is contained in:
2025-03-05 19:02:51 +01:00
parent 2fbe4a6052
commit 74797e935a
15 changed files with 186 additions and 138 deletions

View File

@@ -11,19 +11,19 @@
Generator::Generator() {
}
std::vector<Polyomino> Generator::generatePolyominos(int polyominoSize) {
this->validPolyominos.clear();
std::vector<Polyomino> Generator::generatePolyominoes(int polyominoSize) {
this->validPolyominoes.clear();
this->currentTestedShape.clear();
// a polyomino has at least 1 square
if (polyominoSize < 1) return this->validPolyominos;
if (polyominoSize < 1) return this->validPolyominoes;
// always place the first cell at (0, 0)
this->currentTestedShape.insert(Position{0, 0});
std::map<Position, int> candidatePositions;
this->generate(polyominoSize, 0, 1, candidatePositions);
return this->validPolyominos;
return this->validPolyominoes;
}
void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map<Position, int> candidatePositions) {
@@ -31,7 +31,7 @@ void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nex
if (polyominoSize == this->currentTestedShape.size()) {
Polyomino candidate(this->currentTestedShape);
// we sort the rotations of the polyominos
// we sort the rotations of the polyominoes
std::vector<Polyomino> candidateRotations;
candidateRotations.reserve(4);
for (int i = 0; i < 4; i++) {
@@ -43,7 +43,7 @@ void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nex
// we keep the polyomino only if it was generated in its lowest rotation
if (candidate == candidateRotations.at(0)) {
this->validPolyominos.push_back(candidate);
this->validPolyominoes.push_back(candidate);
}
return;

View File

@@ -8,11 +8,11 @@
/**
* A generator of one-sided polyominos of any size
* A generator of one-sided polyominoes of any size
*/
class Generator {
private:
std::vector<Polyomino> validPolyominos; // the list of already generated polyominos
std::vector<Polyomino> validPolyominoes; // the list of already generated polyominoes
std::set<Position> currentTestedShape; // the polyomino being created
public:
@@ -22,14 +22,14 @@ class Generator {
Generator();
/**
* Generates the list of all one-sided polyominos of the specified size
* @return The list of polyominos
* Generates the list of all one-sided polyominoes of the specified size
* @return The list of polyominoes
*/
std::vector<Polyomino> generatePolyominos(int polyominoSize);
std::vector<Polyomino> generatePolyominoes(int polyominoSize);
private:
/**
* Generates all one-sided polyominos of the specified size using the current tested shape
* Generates all one-sided polyominoes of the specified size using the current tested shape
*/
void generate(int polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map<Position, int> candidatePositions);

View File

@@ -25,9 +25,9 @@ bool PiecesFiles::savePieces(int polyominoSize) const {
}
Generator generator;
std::vector<Polyomino> nMinos = generator.generatePolyominos(polyominoSize);
std::vector<Polyomino> nMinos = generator.generatePolyominoes(polyominoSize);
// sorting the polyominos is done after setting spawn position to ensure the order is always the same
// sorting the polyominoes is done after setting spawn position to ensure the order is always the same
for (Polyomino& nMino : nMinos) {
nMino.goToSpawnPosition();
}
@@ -64,7 +64,7 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
holelessPieces.clear();
otherPieces.clear();
// we shift the first color of each size so that the small polyominos (size 1-2-3) don't all have the same color
// we shift the first color of each size so that the small polyominoes (size 1-2-3) don't all have the same color
Block pieceBlock = firstPieceBlockType();
for (int i = 0; i < polyominoSize; i++) {
nextPieceBlockType(pieceBlock);

View File

@@ -100,7 +100,7 @@ class Polyomino {
bool operator<(const Polyomino& other) const;
/**
* Equality operator, two polyominos are equal if their positions are the same, that means two polyominos of the same shape at different places will not be equal
* Equality operator, two polyominoes are equal if their positions are the same, that means two polyominoes of the same shape at different places will not be equal
* @return If the polyomino is equal to another
*/
bool operator==(const Polyomino& other) const;