2017-12-21 12:20:57 +01:00
|
|
|
//
|
|
|
|
// Created by Raphael Maenle on 21/12/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "../../header/solve.h"
|
|
|
|
|
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
void Puzzle::printPuzzle()
|
|
|
|
{
|
2017-12-23 10:11:07 +01:00
|
|
|
cout << "a1: " << endl;
|
|
|
|
a1.printConstraintMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Puzzle::printBox()
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
for(auto it:myBox)
|
|
|
|
{
|
|
|
|
cout << "Part " << i++ << ":" << endl;
|
|
|
|
it.print(); cout << endl;
|
|
|
|
|
|
|
|
}
|
2017-12-21 13:07:01 +01:00
|
|
|
}
|
2017-12-21 12:43:31 +01:00
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
//puts a puzzlepiece back into its box
|
|
|
|
void Puzzle::putIntoBox()
|
2017-12-21 12:43:31 +01:00
|
|
|
{
|
2017-12-21 13:07:01 +01:00
|
|
|
Part tmpPart;
|
2017-12-23 10:11:07 +01:00
|
|
|
int id = 0;
|
2017-12-21 13:07:01 +01:00
|
|
|
for(int i=0;i<this->getSizeAsCoor().col;i++)
|
2017-12-21 12:43:31 +01:00
|
|
|
{
|
2017-12-21 13:07:01 +01:00
|
|
|
for(int j=0;j<this->getSizeAsCoor().row;j++)
|
|
|
|
{
|
2017-12-23 10:11:07 +01:00
|
|
|
|
|
|
|
tmpPart.m_a1=this->a1.m_constraintMatrix[i][j];
|
|
|
|
//sets part id
|
|
|
|
tmpPart.SetPartID(id++);
|
|
|
|
// adds all 4 rotations to Box
|
|
|
|
for(int rotations=0;rotations<4;rotations++)
|
|
|
|
{
|
|
|
|
tmpPart.m_a1.shift(1);
|
|
|
|
//TODO! add all other layers and rotationvariance here
|
|
|
|
myBox.emplace_back(tmpPart);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
}
|
2017-12-21 12:43:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
//shuffles the existing box in Puzzle
|
|
|
|
void Puzzle::shuffle()
|
|
|
|
{
|
|
|
|
random_shuffle(myBox.begin(),myBox.end());
|
|
|
|
}
|
2017-12-21 12:43:31 +01:00
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
//deletes all constraints from all abstractionlayers
|
|
|
|
void Puzzle::removeConstrains(coor removeCoordinates)
|
|
|
|
{
|
2017-12-22 22:47:14 +01:00
|
|
|
this->a1.RemoveConstraintOnPosition(removeCoordinates);
|
2017-12-21 13:07:01 +01:00
|
|
|
}
|
2018-01-07 20:08:50 +01:00
|
|
|
void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece)
|
|
|
|
{
|
|
|
|
this->a1.SetConstraintOnPosition(setConstraints,constraintPiece->m_a1);
|
|
|
|
}
|
2017-12-21 12:43:31 +01:00
|
|
|
|
|
|
|
void Puzzle::createRandomPuzzle()
|
|
|
|
{
|
2017-12-22 22:47:14 +01:00
|
|
|
a1.CreateRandomPuzzle();
|
2017-12-21 13:07:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Puzzle::createp_box()
|
|
|
|
{
|
2018-01-07 20:08:50 +01:00
|
|
|
for(int i=0;i<cols*rows*4;i++)
|
2018-01-06 23:23:42 +01:00
|
|
|
p_myBox.push_back(&myBox[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//creates a box of puzzlepieces with nothing other than puzzle piece id and correct nr of pieces
|
|
|
|
void Puzzle::createBox(){
|
2018-01-07 20:08:50 +01:00
|
|
|
for(int i=0;i<cols*rows;i++)
|
2018-01-06 23:23:42 +01:00
|
|
|
{
|
|
|
|
Part temp;
|
|
|
|
temp.SetPartID(i);
|
|
|
|
for(uint8_t j=0;j<4;j++)
|
|
|
|
{
|
|
|
|
temp.SetNumOfRotations(j);
|
|
|
|
myBox.push_back(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-12-22 22:47:14 +01:00
|
|
|
|
2017-12-21 13:07:01 +01:00
|
|
|
}
|
2018-01-07 14:16:57 +01:00
|
|
|
|
|
|
|
bool Puzzle::allSet() {
|
2018-01-07 20:08:50 +01:00
|
|
|
for(auto it:myBox)
|
|
|
|
if(!it.set)
|
|
|
|
return false;
|
|
|
|
return true;
|
2018-01-07 14:16:57 +01:00
|
|
|
}
|