This commit is contained in:
@@ -55,7 +55,12 @@ bool PiecesFiles::savePieces(int polyominoSize, std::vector<Polyomino>& polyomin
|
||||
|
||||
// write the positions of the piece
|
||||
for (int i = 0; i < bytesNeeded; i++) {
|
||||
buffer << static_cast<std::uint8_t>(polyomino.getPositionsData()[i/4] >> ((i%4) * 8));
|
||||
buffer << static_cast<std::uint8_t>(
|
||||
(
|
||||
polyomino.getPositionsData()[i / sizeof(std::uint64_t)] >>
|
||||
(56 - ((i % sizeof(std::uint64_t)) * 8))
|
||||
)
|
||||
& 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +123,8 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
|
||||
|
||||
for (int j = 0; j < bytesNeeded; j++) {
|
||||
buffer >> positionByte;
|
||||
polyominoData[j/4] |= static_cast<std::uint64_t>(positionByte) << ((j%4) * 8);
|
||||
polyominoData[j / sizeof(std::uint64_t)] |=
|
||||
(static_cast<std::uint64_t>(positionByte) << (56 - ((j % sizeof(std::uint64_t)) * 8)));
|
||||
}
|
||||
|
||||
pieces.emplace_back(Polyomino(std::move(polyominoData), length), pieceBlock);
|
||||
|
||||
@@ -277,7 +277,7 @@ std::vector<Position> Polyomino::getPositions() const {
|
||||
int posIndex = y * this->length + x;
|
||||
int longIndex = posIndex / (sizeof(std::uint64_t) * 8);
|
||||
int bitIndex = posIndex % (sizeof(std::uint64_t) * 8);
|
||||
if (this->positions[longIndex] & static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex)) {
|
||||
if (this->positions[longIndex] & static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex - 1)) {
|
||||
result.push_back(Position(x, y));
|
||||
}
|
||||
}
|
||||
@@ -328,19 +328,19 @@ bool Polyomino::contains(const Position& position) const {
|
||||
int posIndex = position.y * this->length + position.x;
|
||||
int longIndex = posIndex / (sizeof(std::uint64_t) * 8);
|
||||
int bitIndex = posIndex % (sizeof(std::uint64_t) * 8);
|
||||
return this->positions[longIndex] & static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex);
|
||||
return this->positions[longIndex] & static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex - 1);
|
||||
}
|
||||
|
||||
void Polyomino::insert(const Position& position) {
|
||||
int posIndex = position.y * this->length + position.x;
|
||||
int longIndex = posIndex / (sizeof(std::uint64_t) * 8);
|
||||
int bitIndex = posIndex % (sizeof(std::uint64_t) * 8);
|
||||
this->positions[longIndex] |= static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex);
|
||||
this->positions[longIndex] |= static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex - 1);
|
||||
}
|
||||
|
||||
void Polyomino::erase(const Position& position) {
|
||||
int posIndex = position.y * this->length + position.x;
|
||||
int longIndex = posIndex / (sizeof(std::uint64_t) * 8);
|
||||
int bitIndex = posIndex % (sizeof(std::uint64_t) * 8);
|
||||
this->positions[longIndex] &= ~(static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex));
|
||||
this->positions[longIndex] &= ~(static_cast<std::uint64_t>(1) << (sizeof(std::uint64_t) * 8 - bitIndex - 1));
|
||||
}
|
||||
Reference in New Issue
Block a user