generating "Random" Pieces from picture source now

rgb values stored as double in the piece base class. this is bound to change once other group has expanded piece base class.
This commit is contained in:
Raphael Maenle 2017-12-06 16:25:13 +01:00
parent cd7bc1c42a
commit 9b282e83ca
8 changed files with 100 additions and 73 deletions

BIN
Codicil/Images/Balloons.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 KiB

BIN
Codicil/Images/tiger.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 KiB

View File

@ -1,3 +1,4 @@
#include "../../header.h"
//shifts puzzle piece one to the right //shifts puzzle piece one to the right
void PuzzlePiece::shift(unsigned int moves) void PuzzlePiece::shift(unsigned int moves)
@ -189,7 +190,8 @@ void Puzzle::printPuzzle()
} }
//creates a legal puzzle out of random pieces //creates a legal puzzle out of random pieces
void randomBox::createRandomPuzzle()
void randomBox::createRandomAbstraction1()
{ {
PuzzlePiece temporaryRandomPiece(0); PuzzlePiece temporaryRandomPiece(0);
for(int i=0;i<getRows();i++) for(int i=0;i<getRows();i++)
@ -213,12 +215,59 @@ void randomBox::createRandomPuzzle()
temporaryRandomPiece.assignIdentifier(); temporaryRandomPiece.assignIdentifier();
setPiece(j,i,temporaryRandomPiece); setPiece(j,i,temporaryRandomPiece);
j++; j++;
Box.push_back(temporaryRandomPiece);
} }
} }
} }
} }
void randomBox::createRandomAbstraction2()
{
//get a picture
cv::Mat PuzzlePicture = cv::imread("../../Codicil/Images/Balloons.jpg");
if(! PuzzlePicture.data )
{
cout << "Could not open or find the image" << std::endl ;
return;
}
//split a picture into mxn pieces
cv::Size smallSize ((int)(PuzzlePicture.cols/getCols()) ,(int)(PuzzlePicture.rows/getRows()));
// get the image data
vector<cv::Mat> smallChannels;
unsigned int i=0,j=0;
for ( int y=0; y<=PuzzlePicture.rows-smallSize.height; y += smallSize.height )
{
for ( int x=0 ; x<=PuzzlePicture.cols-smallSize.width; x += smallSize.width )
{
//split into different ROIs
cv::Rect rect = cv::Rect (x ,y , smallSize.width, smallSize.height );
cv::Mat tmpSmallPicture = cv::Mat(PuzzlePicture,rect);
cv::split(tmpSmallPicture, smallChannels);
//save color into individual PuzzlePieces in Matrix
PuzzlePiece tmpPiece = getPiece(j,i);
tmpPiece.r = cv::mean(smallChannels[0]).operator[](0);
tmpPiece.g = cv::mean(smallChannels[1]).operator[](0);
tmpPiece.b = cv::mean(smallChannels[2]).operator[](0);
setPiece(j,i,tmpPiece);
j++;
}
i++;
j=0;
}
}
void randomBox::putAllIntoBox() {
for (int i = 0; i < getRows(); i++)
{
for (int j = 0; j < getCols(); j++)
{
Box.push_back(getPiece(j,i));
}
}
}
//prints a box contents on console //prints a box contents on console
void randomBox::printBox() void randomBox::printBox()
{ {
@ -236,16 +285,24 @@ vector<PuzzlePiece> randomBox::shuffle()
{ {
random_shuffle(Box.begin(),Box.end()); random_shuffle(Box.begin(),Box.end());
for (vector<PuzzlePiece>::iterator i = Box.begin(); i != Box.end(); i++) for (vector<PuzzlePiece>::iterator i = Box.begin(); i != Box.end(); i++)
(*i).shift(rand()%4); {
i->shift(rand()%4);
i->resetShift();
}
numerateBox(Box); numerateBox(Box);
return Box; return Box;
} }
//creates a random box size m, n, shuffles it, and then retuns it //creates a random box size m, n, shuffles it, and then retuns it
vector<PuzzlePiece> createBox(unsigned int m, unsigned int n) vector<PuzzlePiece> createBox(coor myCoor)
{ {
randomBox myFirstPuzzleBox(m,n); randomBox myFirstPuzzleBox(myCoor.m,myCoor.n);
myFirstPuzzleBox.createRandomPuzzle(); myFirstPuzzleBox.createRandomAbstraction1();
myFirstPuzzleBox.createRandomAbstraction2();
myFirstPuzzleBox.putAllIntoBox();
myFirstPuzzleBox.printPuzzle();
return myFirstPuzzleBox.shuffle(); return myFirstPuzzleBox.shuffle();
} }

View File

@ -1,3 +1,5 @@
#include "../../header.h"
void status(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat); void status(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);
@ -66,15 +68,6 @@ bool next(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
return 1; return 1;
} }
/*
coor calculateFirstCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
{
//returns coor of first piece
coor firstCoor(0,0);
return firstCoor;
}
*/
coor calculateNextCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat) coor calculateNextCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
{ {
//level 1: //level 1:
@ -135,10 +128,10 @@ void abstractionlayer1solver(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box,
log.back().PieceCollector.erase(log.back().PieceCollector.begin()+i); log.back().PieceCollector.erase(log.back().PieceCollector.begin()+i);
else else
{ {
i++; //otherwise loop stops before end!
//set shift to 0 so that we have a defined starting position for all pieces //set shift to 0 so that we have a defined starting position for all pieces
while(log.back().PieceCollector[i]->getShift()) while(log.back().PieceCollector[i]->getShift())
log.back().PieceCollector[i]->shift(1); log.back().PieceCollector[i]->shift(1);
i++; //otherwise loop stops before end!
} }
} }
} }

View File

@ -5,15 +5,10 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#define MAX_ABSTRAX 1
#define structdebug
using namespace std; using namespace std;
#include "header/input.h" #include "header/input.h"
#include "header/solve.h" #include "header/solve.h"
#include "header/output.h"
#include "functions/input/input.cpp"
#include "functions/solve/classExtension.cpp"
#include "functions/solve/structure.cpp"
#include "functions/output/output.cpp"

View File

@ -3,6 +3,10 @@
class Part class Part
{ {
public: public:
double r;
double g;
double b;
Part(): connections(0){} Part(): connections(0){}
~Part() {} ~Part() {}
uint8_t getConnections() const uint8_t getConnections() const
@ -13,4 +17,6 @@ public:
private: private:
uint8_t connections; uint8_t connections;
}; };

View File

@ -1,6 +1,10 @@
#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std; using namespace std;
class PuzzlePiece: public Part class PuzzlePiece: public Part
{ {
public: public:
@ -115,7 +119,9 @@ public:
randomBox(unsigned int m, unsigned int n) : Puzzle(m,n) {srand(time(0));} //passed m n to puzzle constructor randomBox(unsigned int m, unsigned int n) : Puzzle(m,n) {srand(time(0));} //passed m n to puzzle constructor
void createRandomPuzzle(); void createRandomAbstraction1();
void createRandomAbstraction2();
void putAllIntoBox();
vector<PuzzlePiece> shuffle(); vector<PuzzlePiece> shuffle();
void printBox(); void printBox();
@ -157,24 +163,11 @@ private:
static int randomed; static int randomed;
}; };
class BoxClassify
{
vector<PuzzlePiece*> p_Box;
vector<vector<PuzzlePiece*>> ab1class;
};
int LogEntry::randomed(0);
unsigned int PuzzlePiece::idcount(0);
void printBox(vector<PuzzlePiece> myBox); void printBox(vector<PuzzlePiece> myBox);
vector<PuzzlePiece> createBox(unsigned int m, unsigned int n); vector<PuzzlePiece> createBox(coor myCoor);
void numerateBox(vector<PuzzlePiece>& myBox); void numerateBox(vector<PuzzlePiece>& myBox);
bool next(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat); bool next(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);
coor calculateFirstCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);
coor calculateNextCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat); coor calculateNextCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);
void solve(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat); void solve(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);
void abstractionlayer0solver(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat); void abstractionlayer0solver(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat);

View File

@ -1,39 +1,22 @@
#define MAX_ABSTRAX 1
#define structdebug
#include "header.h" #include "header.h"
//#include "../Codicil/test_puzzle_long40x40.h"
int LogEntry::randomed(0);
unsigned int PuzzlePiece::idcount(0);
int main() int main()
{ {
int cols=10, rows=20; int cols=2, rows=3;
//some basic part stuff
vector<Part> myFirstPuzzle;
Part myFirstPart;
myFirstPart.setConnections(0b00101000);
myFirstPuzzle.push_back(myFirstPart);
//some basic random puzzle stuff //some basic random puzzle stuff
randomBox myRandomBox(cols,rows); vector<PuzzlePiece> myFirstBox = createBox(coor(cols,rows));
myRandomBox.createRandomPuzzle();
vector<PuzzlePiece> myFirstBox = myRandomBox.shuffle();
//undo everything and make this puzzle fucking imba hard!!!
//need 40x40 for this, so check your status
//makehard4040puzzle(myFirstBox);
//some advanced solver stuff //some advanced solver stuff
vector<LogEntry> log; vector<LogEntry> log;
vector<PuzzlePiece*> p_myFirstBox; vector<PuzzlePiece*> p_myFirstBox;
//BoxClassify myFirstBox(); //BoxClassify myFirstBox();
cout << "original puzzle: " << endl;
myRandomBox.printPuzzle();
cout << endl; cout << endl;
for(int i=0;i<myFirstBox.size();i++) for(int i=0;i<myFirstBox.size();i++)
p_myFirstBox.push_back(&myFirstBox[i]); p_myFirstBox.push_back(&myFirstBox[i]);