#include "Bag.h" #include "../Pieces/Piece.h" #include "PiecesList.h" #include #include #include Bag::Bag(const std::shared_ptr& piecesList) : piecesList(piecesList) { this->currentBag = this->piecesList->getSelectedPieces(); this->nextBag.clear(); this->prepareNext(); } void Bag::jumpToNextBag() { if (this->currentBag.size() < this->nextBag.size()) { std::swap(this->currentBag, this->nextBag); } for (const std::pair& pieceIndex : this->nextBag) { this->currentBag.push_back(pieceIndex); } this->nextBag.clear(); this->prepareNext(); } Piece Bag::lookNext() { return this->piecesList->getPiece(this->next); } Piece Bag::getNext() { std::pair nextIndex = this->next; this->prepareNext(); return this->piecesList->getPiece(nextIndex); } void Bag::prepareNext() { if (this->currentBag.empty()) { std::swap(this->currentBag, this->nextBag); } int indexIndex = std::rand() % this->currentBag.size(); this->next = this->currentBag.at(indexIndex); this->nextBag.push_back(this->next); this->currentBag.erase(this->currentBag.begin() + indexIndex); }