This commit is contained in:
@@ -51,11 +51,11 @@ bool PiecesFiles::savePieces(int polyominoSize, std::vector<Polyomino>& polyomin
|
||||
buffer << infoByte;
|
||||
|
||||
const int bitsNeeded = polyomino.getLength() * polyomino.getLength();
|
||||
const int longsNeeded = bitsNeeded / 64 + 1;
|
||||
const int bytesNeeded = bitsNeeded / 8 + 1;
|
||||
|
||||
// write the positions of the piece
|
||||
for (int i = 0; i < longsNeeded; i++) {
|
||||
buffer << polyomino.getPositionsData()[i];
|
||||
for (int i = 0; i < bytesNeeded; i++) {
|
||||
buffer << static_cast<std::uint8_t>(polyomino.getPositionsData()[i/4] >> ((i%4) * 8));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
|
||||
constexpr char yMask = 0b0000'1111;
|
||||
|
||||
std::uint8_t infoByte;
|
||||
std::uint8_t positionByte;
|
||||
int i = 0;
|
||||
while (!buffer.IsFinished()) {
|
||||
// if (piecesFile.eof()) break;
|
||||
@@ -110,19 +111,20 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
|
||||
int length = (infoByte & lengthMask);
|
||||
|
||||
const int bitsNeeded = length * length;
|
||||
const int longsNeeded = bitsNeeded / 64 + 1;
|
||||
const int bytesNeeded = bitsNeeded / 8 + 1;
|
||||
|
||||
// read positions
|
||||
Polyomino::PolyominoData polyominoData{};
|
||||
for (int i = 0; i < longsNeeded; i++) {
|
||||
buffer >> polyominoData[i];
|
||||
|
||||
for (int j = 0; j < bytesNeeded; j++) {
|
||||
buffer >> positionByte;
|
||||
polyominoData[j/4] |= static_cast<std::uint64_t>(positionByte) << ((j%4) * 8);
|
||||
}
|
||||
|
||||
// create piece
|
||||
Piece readPiece(Polyomino(std::move(polyominoData), length), pieceBlock);
|
||||
pieces.emplace_back(Polyomino(std::move(polyominoData), length), pieceBlock);
|
||||
|
||||
nextPieceBlockType(pieceBlock);
|
||||
|
||||
pieces.push_back(readPiece);
|
||||
if (isConvex) {
|
||||
convexPieces.push_back(i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user