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

108
src/Pieces/Polyomino.h Normal file
View File

@@ -0,0 +1,108 @@
#pragma once
#include "Cell.h"
#include <Vector>
#include <Set>
#include <iostream>
/**
* A mathematical object consisting of touching squares on a 2D grid
*/
class Polyomino {
private:
std::set<Cell> cells; // the squares composing the polyomino, (0,0) is downleft
int length; // the size of the smallest square in which the polyomino can fit on any rotation
public:
/**
* Creates a polyomino with the specified cells and normalizes it, wheter it is actually a polyonimo is not checked
*/
Polyomino(const std::set<Cell>& cells);
/**
* Creates a polyomino with the specified cells and length, wheter it is actually a polyonimo of this length is not checked
*/
Polyomino(const std::set<Cell>& cells, int length);
/**
* Translates the polyomino to the lowest unsigned values (lower row on y = 0, and left-most column on x = 0)
*/
void normalize();
/**
* Rotates the polyomino 90° clockwise, the center of rotation being the middle of the square going from (0,0) to (length-1, length-1)
*/
void rotateCW();
/**
* Rotates the polyomino 180°, the center of rotation being the middle of the square going from (0,0) to (length-1, length-1)
*/
void rotate180();
/**
* Rotates the polyomino 90° counter-clockwise, the center of rotation being the middle of the square going from (0,0) to (length-1, length-1)
*/
void rotateCCW();
/**
* Set the polyomino to a normalized default spawn position
*/
void goToSpawnPosition();
private:
/**
* Auxiliary method of goToSpawnPosition()
*/
void checkForFlattestSide(const std::vector<std::vector<int>>& linesCompleteness, bool currentFlattestSides[4], int& sideToBeOn, bool checkLeftSide) const;
public:
/**
* Returns wheter the polyomino is convex, that is if every line and column has at most one continuous line of cells
*/
bool isConvex() const;
/**
* Returns wheter the polyomino has at least one hole
*/
bool hasHole() const;
private :
/**
* Auxiliary method of hasHole()
*/
void tryToInsertCell(std::set<Cell>& emptyCells, const Cell& candidate) const;
public:
/**
* Returns a copy of the cells of the polyomino
*/
std::set<Cell> getCells() const;
/**
* Returns the length of the polyomino
*/
int getLength() const;
/**
* Returns the number of squares in the polyomino
*/
int getPolyominoOrder() const;
/**
* Strict inferiority operator, a polyomino is inferior than another if it has a smaller length, or if they are the same length,
* while checking from left to right and top to bottom, is the first which has a cell while the other doesn't
*/
bool operator<(const Polyomino& other) const;
/**
* Equality operator, two polyominos are equal if they overlap, that means two polyominos of the same shape but different positions will not be equal
*/
bool operator ==(const Polyomino& other) const;
/**
* Stream output operator, adds a 2D grid representing the polyomino
*/
friend std::ostream& operator<<(std::ostream& os, const Polyomino& polyomino);
};