màj diagrammes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
Bag::Bag(std::shared_ptr<PiecesList> piecesList) :
|
||||
Bag::Bag(const std::shared_ptr<PiecesList>& piecesList) :
|
||||
piecesList(piecesList) {
|
||||
|
||||
// initialize bags
|
||||
|
||||
@@ -23,7 +23,7 @@ class Bag {
|
||||
/**
|
||||
* Creates a new bag with the pieces currently selected in the piece list
|
||||
*/
|
||||
Bag(std::shared_ptr<PiecesList> piecesList);
|
||||
Bag(const std::shared_ptr<PiecesList>& piecesList);
|
||||
|
||||
/**
|
||||
* Ignores the remaining pieces in the current bag and startd fresh from a new bag
|
||||
|
||||
@@ -38,7 +38,7 @@ void GameBoard::initialize() {
|
||||
}
|
||||
|
||||
bool GameBoard::moveLeft() {
|
||||
if (this->isActivePieceInWall(Position{-1, 0})) {
|
||||
if (this->activePieceInWall(Position{-1, 0})) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@@ -49,7 +49,7 @@ bool GameBoard::moveLeft() {
|
||||
}
|
||||
|
||||
bool GameBoard::moveRight() {
|
||||
if (this->isActivePieceInWall(Position{1, 0})) {
|
||||
if (this->activePieceInWall(Position{1, 0})) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@@ -60,7 +60,7 @@ bool GameBoard::moveRight() {
|
||||
}
|
||||
|
||||
bool GameBoard::moveDown() {
|
||||
if (this->isActivePieceInWall(Position{0, -1})) {
|
||||
if (this->activePieceInWall(Position{0, -1})) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@@ -75,7 +75,7 @@ bool GameBoard::rotate(Rotation rotation) {
|
||||
this->rotate(rotation);
|
||||
|
||||
// before trying to kick, check if the piece can rotate without kicking
|
||||
if (!this->isActivePieceInWall()) {
|
||||
if (!this->activePieceInWall()) {
|
||||
this->isLastMoveKick = false;
|
||||
return true;
|
||||
}
|
||||
@@ -123,11 +123,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set<Position>& safePos
|
||||
// check right before right arbitrarly, we don't decide this with rotations since it would still be arbitrary with 180° rotations
|
||||
if (overlapsRight) {
|
||||
Position shift{+i, j};
|
||||
if (!this->activePieceOverlapsOnePosition(safePositions, shift)) {
|
||||
if (!this->activePieceOverlaps(safePositions, shift)) {
|
||||
overlapsLeft = false;
|
||||
}
|
||||
else {
|
||||
if (!this->isActivePieceInWall(shift)) {
|
||||
if (!this->activePieceInWall(shift)) {
|
||||
this->activePiecePosition += shift;
|
||||
return true;
|
||||
}
|
||||
@@ -137,11 +137,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set<Position>& safePos
|
||||
// do the same on the left side
|
||||
if (overlapsLeft) {
|
||||
Position shift{-i, j};
|
||||
if (!this->activePieceOverlapsOnePosition(safePositions, shift)) {
|
||||
if (!this->activePieceOverlaps(safePositions, shift)) {
|
||||
overlapsLeft = false;
|
||||
}
|
||||
else {
|
||||
if (!this->isActivePieceInWall(shift)) {
|
||||
if (!this->activePieceInWall(shift)) {
|
||||
this->activePiecePosition += shift;
|
||||
return true;
|
||||
}
|
||||
@@ -181,11 +181,11 @@ bool GameBoard::hold(Rotation initialRotation) {
|
||||
this->rotate(initialRotation);
|
||||
|
||||
// if the piece can't spawn, abort initial rotation
|
||||
if (this->isActivePieceInWall()) {
|
||||
if (this->activePieceInWall()) {
|
||||
this->activePiece = std::make_shared<Piece>(stored);
|
||||
|
||||
// if the piece still can't spawn, abort holding
|
||||
if (this->isActivePieceInWall()) {
|
||||
if (this->activePieceInWall()) {
|
||||
if (isFirstTimeHolding) {
|
||||
this->activePiece = nullptr;
|
||||
}
|
||||
@@ -219,16 +219,16 @@ bool GameBoard::spawnNextPiece() {
|
||||
// this piece has done nothing yet
|
||||
this->isLastMoveKick = false;
|
||||
|
||||
return !this->isActivePieceInWall();
|
||||
return !this->activePieceInWall();
|
||||
}
|
||||
|
||||
bool GameBoard::touchesGround() {
|
||||
return this->isActivePieceInWall(Position{0, -1});
|
||||
return this->activePieceInWall(Position{0, -1});
|
||||
}
|
||||
|
||||
LineClear GameBoard::lockPiece() {
|
||||
bool isLockedInPlace = (this->isActivePieceInWall(Position{0, 1}) && this->isActivePieceInWall(Position{1, 0})
|
||||
&& this->isActivePieceInWall(Position{-1, 0}) && this->isActivePieceInWall(Position{0, -1}));
|
||||
bool isLockedInPlace = (this->activePieceInWall(Position{0, 1}) && this->activePieceInWall(Position{1, 0})
|
||||
&& this->activePieceInWall(Position{-1, 0}) && this->activePieceInWall(Position{0, -1}));
|
||||
|
||||
for (Position position : this->activePiece->getPositions()) {
|
||||
this->board.changeBlock(position + this->activePiecePosition, this->activePiece->getBlockType());
|
||||
@@ -268,14 +268,14 @@ std::vector<Piece> GameBoard::getNextPieces() const {
|
||||
return this->nextQueue;
|
||||
}
|
||||
|
||||
bool GameBoard::isActivePieceInWall(const Position& shift) const {
|
||||
bool GameBoard::activePieceInWall(const Position& shift) const {
|
||||
for (Position position : this->activePiece->getPositions()) {
|
||||
if (this->board.getBlock(position + this->activePiecePosition + shift) != NOTHING) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GameBoard::activePieceOverlapsOnePosition(const std::set<Position>& safePositions, const Position& shift) const {
|
||||
bool GameBoard::activePieceOverlaps(const std::set<Position>& safePositions, const Position& shift) const {
|
||||
for (Position position : this->activePiece->getPositions()) {
|
||||
if (safePositions.contains(position + this->activePiecePosition + shift)) return true;
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ class GameBoard {
|
||||
* Checks if one of the active piece's positions touches a wall in the board
|
||||
* @return If the active piece is in a wall
|
||||
*/
|
||||
bool isActivePieceInWall(const Position& shift = Position{0, 0}) const;
|
||||
bool activePieceInWall(const Position& shift = Position{0, 0}) const;
|
||||
|
||||
/**
|
||||
* Check if one of the active piece's positions shifted by a specified position would overlap with a set of positions
|
||||
* @return If the shifted active piece overlaps with one of the position
|
||||
*/
|
||||
bool activePieceOverlapsOnePosition(const std::set<Position>& safePositions, const Position& shift = Position{0, 0}) const;
|
||||
bool activePieceOverlaps(const std::set<Position>& safePositions, const Position& shift = Position{0, 0}) const;
|
||||
|
||||
/**
|
||||
* Sets the active piece to its spawn position
|
||||
|
||||
@@ -14,8 +14,8 @@ class Menu {
|
||||
private:
|
||||
PiecesList piecesList; // the list of pieces in the game
|
||||
Player playerControls; // the controls of the player
|
||||
int boardHeight; // the height of the board for the next game
|
||||
int boardWidth; // the width of the board for the next game
|
||||
int boardHeight; // the height of the board for the next game
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -101,7 +101,7 @@ std::vector<std::pair<int, int>> PiecesList::getSelectedPieces() const {
|
||||
return this->selectedPieces;
|
||||
}
|
||||
|
||||
Piece PiecesList::getPiece(std::pair<int, int> pieceIndex) const {
|
||||
Piece PiecesList::getPiece(const std::pair<int, int>& pieceIndex) const {
|
||||
return this->loadedPieces.at(pieceIndex.first).at(pieceIndex.second);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class PiecesList {
|
||||
/**
|
||||
* @return The piece corresponding to the specified index
|
||||
*/
|
||||
Piece getPiece(std::pair<int, int> pieceIndex) const;
|
||||
Piece getPiece(const std::pair<int, int>& pieceIndex) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
#include "Menu.h"
|
||||
#include "../Pieces/Generator.h"
|
||||
#include "../Pieces/PiecesFiles.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
void testGeneratorForAllSizes(int amount);
|
||||
void testGeneratorForOneSize(int size);
|
||||
void testGeneratorByprintingAllNminos(int n);
|
||||
void testStoringAndRetrievingPieces(int size);
|
||||
void generateFilesForAllSizes(int amount);
|
||||
void generateFilesForOneSize(int size);
|
||||
void loadFromFilesForOneSize(int size);
|
||||
void readStatsFromFilesForAllSizes(int amount);
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::srand(std::time(NULL));
|
||||
|
||||
Menu menu;
|
||||
menu.getPiecesList().loadPieces(4);
|
||||
menu.getPiecesList().selectAllPieces(4);
|
||||
Game game = menu.startGame(SPRINT);
|
||||
game.start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void testGeneratorForAllSizes(int amount) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
Generator generator;
|
||||
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
std::vector<Polyomino> n_minos = generator.generatePolyominos(i);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << "generated " << n_minos.size() << " polyominos of size " << i << " in " << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testGeneratorForOneSize(int size) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
Generator generator;
|
||||
|
||||
std::cout << "Generating " << size << "-minos" << std::endl;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
std::vector<Polyomino> n_minos = generator.generatePolyominos(size);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testGeneratorByprintingAllNminos(int n) {
|
||||
Generator generator;
|
||||
std::vector<Polyomino> n_minos = generator.generatePolyominos(n);
|
||||
|
||||
for (Polyomino& n_mino : n_minos) {
|
||||
n_mino.goToSpawnPosition();
|
||||
}
|
||||
std::sort(n_minos.begin(), n_minos.end());
|
||||
|
||||
for (Polyomino& n_mino : n_minos) {
|
||||
|
||||
std::cout << n_mino << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testStoringAndRetrievingPieces(int size) {
|
||||
PiecesFiles piecesFiles;
|
||||
piecesFiles.savePieces(size);
|
||||
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
piecesFiles.loadPieces(size, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
|
||||
std::cout << "Convex " << size << "-minos:" << std::endl;
|
||||
for (int index : convexPieces) {
|
||||
std::cout << pieces.at(index);
|
||||
}
|
||||
|
||||
std::cout << "Holeless " << size << "-minos:" << std::endl;
|
||||
for (int index : holelessPieces) {
|
||||
std::cout << pieces.at(index);
|
||||
}
|
||||
|
||||
std::cout << "Others " << size << "-minos:" << std::endl;
|
||||
for (int index : otherPieces) {
|
||||
std::cout << pieces.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
void generateFilesForAllSizes(int amount) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.savePieces(i);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << "Generated pieces files for size " << i << " in " << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << "Read pieces from files for size " << i << " in " << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void generateFilesForOneSize(int size) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
std::cout << "Generating " << size << "-minos files" << std::endl;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.savePieces(size);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void loadFromFilesForOneSize(int size) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
std::cout << "Loading " << size << "-minos from files" << std::endl;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.loadPieces(size, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void readStatsFromFilesForAllSizes(int amount) {
|
||||
PiecesFiles piecesFiles;
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
piecesFiles.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
|
||||
std::cout << i << "-minos : " << pieces.size() << std::endl;
|
||||
std::cout << "Convex " << i << "-minos : " << convexPieces.size() << std::endl;
|
||||
std::cout << "Holeless " << i << "-minos : " << holelessPieces.size() << std::endl;
|
||||
std::cout << "Others " << i << "-minos : " << otherPieces.size() << std::endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user