const everywhere + légèrement changer format fichiers

This commit is contained in:
2025-03-01 22:21:43 +01:00
parent 8088894073
commit f525c00662
15 changed files with 151 additions and 113 deletions

View File

@@ -32,20 +32,10 @@ bool PiecesFiles::savePieces(int polyominoSize) const {
nMino.goToSpawnPosition();
}
std::sort(nMinos.begin(), nMinos.end());
Block pieceblock = firstPieceBlockType();
for (int i = 0; i < polyominoSize; i++) {
nextPieceBlockType(pieceblock);
}
for (const Polyomino& nMino : nMinos) {
// write polyomino length
char lengthByte = nMino.getLength();
piecesFile.write(&lengthByte, 1);
// write the type and block of the piece
char infoByte = (nMino.isConvex() << 7) + (nMino.hasHole() << 6) + pieceblock;
nextPieceBlockType(pieceblock);
// write the characteristics of the piece
char infoByte = (nMino.isConvex() << 7) + (nMino.hasHole() << 6) + nMino.getLength();
piecesFile.write(&infoByte, 1);
// write the positions of the piece
@@ -74,37 +64,41 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
holelessPieces.clear();
otherPieces.clear();
Block pieceBlock = firstPieceBlockType();
for (int i = 0; i < polyominoSize; i++) {
nextPieceBlockType(pieceBlock);
}
char convexMask = 0b1000'0000;
char holeMask = 0b0100'0000;
char blockMask = 0b0011'1111;
char lengthMask = 0b0011'1111;
char xMask = 0b1111'0000;
char yMask = 0b0000'1111;
char lengthByte;
char infoByte;
int i = 0;
// read piece length
while (piecesFile.get(lengthByte)) {
while (piecesFile.get(infoByte)) {
if (piecesFile.eof()) break;
// read piece infos
char infoByte;
piecesFile.get(infoByte);
bool isConvex = (infoByte & convexMask) >> 7;
bool hasHole = (infoByte & holeMask) >> 6;
Block block = Block(infoByte & blockMask);
int length = (infoByte & lengthMask);
// read positions
std::set<Position> piecepositions;
std::set<Position> piecePositions;
char positionByte;
for (int i = 0; i < polyominoSize; i++) {
piecesFile.get(positionByte);
int x = (positionByte & xMask) >> 4;
int y = positionByte & yMask;
piecepositions.insert(Position{x, y});
piecePositions.insert(Position{x, y});
}
// create piece
Piece readPiece(Polyomino(piecepositions, lengthByte), block);
Piece readPiece(Polyomino(piecePositions, length), pieceBlock);
nextPieceBlockType(pieceBlock);
pieces.push_back(readPiece);
if (isConvex) {
convexPieces.push_back(i);