#include "PiecesList.h" #include "../Pieces/Piece.h" #include "../Pieces/PiecesFiles.h" #include #include PiecesList::PiecesList() { this->highestLoadedSize = 0; this->selectedPieces.clear(); // we need to have something at index 0 even if there is no pieces of size 0 this->loadedPieces.clear(); this->convexPieces.clear(); this->holelessPieces.clear(); this->otherPieces.clear(); this->pushBackEmptyVectors(); // we always prepare vectors of the next size to be generated this->pushBackEmptyVectors(); } bool PiecesList::loadPieces(int size) { if (size < 1) return false; PiecesFiles piecesFiles; for (int i = this->highestLoadedSize + 1; i <= size; i++) { if (!piecesFiles.loadPieces(i, this->loadedPieces.at(i), this->convexPieces.at(i), this->holelessPieces.at(i), this->otherPieces.at(i))) { return false; } else { this->highestLoadedSize++; this->pushBackEmptyVectors(); } } return true; } bool PiecesList::selectPiece(int size, int number) { if (size < 1 || size > this->highestLoadedSize || number >= this->loadedPieces.at(size).size()) return false; this->selectedPieces.push_back(std::pair(size, number)); return true; } bool PiecesList::selectAllPieces(int size) { if (size < 1 || size > this->highestLoadedSize) return false; for (int i = 0; i < this->loadedPieces.at(size).size(); i++) { this->selectedPieces.push_back(std::pair(size, i)); } return true; } bool PiecesList::selectConvexPieces(int size) { if (size < 1 || size > this->highestLoadedSize) return false; for (int index : this->convexPieces.at(size)) { this->selectedPieces.push_back(std::pair(size, index)); } return true; } bool PiecesList::selectHolelessPieces(int size) { if (size < 1 || size > this->highestLoadedSize) return false; for (int index : this->holelessPieces.at(size)) { this->selectedPieces.push_back(std::pair(size, index)); } return true; } bool PiecesList::selectOtherPieces(int size) { if (size < 1 || size > this->highestLoadedSize) return false; for (int index : this->otherPieces.at(size)) { this->selectedPieces.push_back(std::pair(size, index)); } return true; } void PiecesList::unselectAll() { this->selectedPieces.clear(); } int PiecesList::getHighestLoadedSize() const { return this->highestLoadedSize; } int PiecesList::getNumberOfPieces(int size) const { if (size < 1 || size > this->highestLoadedSize) return 0; return this->loadedPieces.at(size).size(); } std::vector> PiecesList::getSelectedPieces() const { return this->selectedPieces; } Piece PiecesList::getPiece(const std::pair& pieceIndex) const { return this->loadedPieces.at(pieceIndex.first).at(pieceIndex.second); } void PiecesList::pushBackEmptyVectors() { this->loadedPieces.push_back(std::vector()); this->convexPieces.push_back(std::vector()); this->holelessPieces.push_back(std::vector()); this->otherPieces.push_back(std::vector()); }