début de la classe PiecesFile

This commit is contained in:
2025-02-28 22:32:51 +01:00
parent 26f501f7e8
commit 13ee43167e
11 changed files with 143 additions and 45 deletions

View File

@@ -1,19 +1,18 @@
#include "Bag.h"
#include "../Pieces/Piece.h"
#include "PiecesList.h"
#include <vector>
#include <utility>
#include <cstdlib>
Bag::Bag(const std::vector<Piece>& pieces) :
pieces(pieces) {
Bag::Bag(std::shared_ptr<PiecesList> piecesList) :
piecesList(piecesList) {
// initialize bags
this->currentBag.clear();
for (int i = 0; i < this->pieces.size(); i++) {
this->currentBag.push_back(i);
}
this->currentBag = this->piecesList->getSelectedPieces();
this->nextBag.clear();
// prepare first piece
@@ -21,18 +20,18 @@ Bag::Bag(const std::vector<Piece>& pieces) :
}
Piece Bag::lookNext() {
return this->pieces.at(this->next);
return *this->piecesList->getPiece(this->next.first, this->next.second);
}
Piece Bag::getNext() {
// get the piece to return
int nextIndex = this->next;
std::pair<int, int> nextIndex = this->next;
// prepare the piece even after the next
this->prepareNext();
// return the next piece
return this->pieces.at(nextIndex);
return *this->piecesList->getPiece(nextIndex.first, nextIndex.second);
}
void Bag::prepareNext() {