benchmarking 1/2
All checks were successful
Linux arm64 / Build (push) Successful in 1m54s

This commit is contained in:
2025-05-26 19:32:31 +02:00
parent 69c07abcec
commit 0bb25d4628
4 changed files with 92 additions and 11 deletions

View File

@@ -25,22 +25,35 @@ bool PiecesFiles::savePieces(int polyominoSize) const {
}
Generator generator;
std::vector<Polyomino> nMinos = generator.generatePolyominoes(polyominoSize);
std::vector<Polyomino> polyominoes = generator.generatePolyominoes(polyominoSize);
return this->savePieces(polyominoSize, polyominoes);
}
bool PiecesFiles::savePieces(int polyominoSize, std::vector<Polyomino>& polyominoes) const {
std::string filePath;
if (!this->getFilePath(polyominoSize, filePath)) {
return false;
}
std::ofstream piecesFile(filePath, std::ios::trunc | std::ios::binary);
if (!piecesFile.good()) {
return false;
}
// sorting the polyominoes is done after setting spawn position to ensure the order is always the same
for (Polyomino& nMino : nMinos) {
for (Polyomino& nMino : polyominoes) {
nMino.goToSpawnPosition();
}
std::sort(nMinos.begin(), nMinos.end());
std::sort(polyominoes.begin(), polyominoes.end());
for (const Polyomino& nMino : nMinos) {
for (const Polyomino& polyomino : polyominoes) {
// write the characteristics of the piece
char infoByte = (nMino.isConvex() << 7) + (nMino.hasHole() << 6) + nMino.getLength();
char infoByte = (polyomino.isConvex() << 7) + (polyomino.hasHole() << 6) + polyomino.getLength();
piecesFile.write(&infoByte, 1);
// write the positions of the piece
char positionByte;
for (Position position : nMino.getPositions()) {
for (const Position position : polyomino.getPositions()) {
positionByte = (position.x << 4) + position.y;
piecesFile.write(&positionByte, 1);
}

View File

@@ -22,13 +22,18 @@ class PiecesFiles {
*/
bool savePieces(int polyominoSize) const;
/**
* Generate a file containing all the pieces of the specified size, assuming they have been correctly generated
* @return If the file could be created
*/
bool savePieces(int polyominoSize, std::vector<Polyomino>& polyominoes) const;
/**
* Replace the content of the vectors by the pieces of the specified size, if the file wasn't found the vectors stays untouched
* @return If the file was found
*/
bool loadPieces(int polyominoSize, std::vector<Piece>& pieces, std::vector<int>& convexPieces, std::vector<int>& holelessPieces, std::vector<int>& otherPieces) const;
private:
/**
* Puts the path to the piece file of the specified size in order, if the data folder wasn't found the string stays untouched
* @return If the data folder was found