initial commit

This commit is contained in:
2025-02-25 12:07:16 +01:00
commit 0657bc9b25
34 changed files with 3069 additions and 0 deletions

50
src/Core/Bag.cpp Normal file
View File

@@ -0,0 +1,50 @@
#include "Bag.h"
#include "../Pieces/Piece.h"
#include <Vector>
#include <cstdlib>
Bag::Bag(const std::vector<Piece>& pieces) : pieces(pieces) {
// initialize bags
this->currentBag.clear();
for (int i = 0; i < this->pieces.size(); i++) {
this->currentBag.push_back(i);
}
this->nextBag.clear();
// prepare first piece
this->prepareNext();
}
Piece Bag::lookNext() {
// return the next piece
return this->pieces.at(this->next);
}
Piece Bag::getNext() {
// get the piece to return
int nextIndex = this->next;
// prepare the piece even after the next
this->prepareNext();
// return the next piece
return this->pieces.at(nextIndex);
}
void Bag::prepareNext() {
// if the bag is empty switch to the next bag
if (this->currentBag.empty()) {
std::swap(this->currentBag, this->nextBag);
}
// pick a random piece from the current bag
int indexIndex = std::rand() % this->currentBag.size();
this->next = this->currentBag.at(indexIndex);
// move the piece over to the next bag
this->nextBag.push_back(this->next);
this->currentBag.erase(this->currentBag.begin() + indexIndex);
}