furthered structure.cpp with code segments. edited log class in solve.h
This commit is contained in:
parent
85da2a4def
commit
c308b6d9e8
@ -1,30 +1,81 @@
|
|||||||
|
|
||||||
|
bool next(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
|
||||||
bool next()
|
|
||||||
{
|
{
|
||||||
|
//case first log entry empty
|
||||||
//calculates next move according to log
|
if(!(log.size())
|
||||||
|
{
|
||||||
|
log.push_back(LogEntry());
|
||||||
|
solve(log, p_Box,puzzleMat);
|
||||||
|
}
|
||||||
|
|
||||||
//case puzzle solved
|
//case puzzle solved
|
||||||
//return 0;
|
else if(!(p_Box.size())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
//case last log multiple entries
|
||||||
|
else if(log.back().PieceCollector.size() > 1)
|
||||||
|
{
|
||||||
|
//advance abstraction layer of last log by one and solve()
|
||||||
|
//or pick first if highest level reached
|
||||||
|
if(log.back().abstractionLayer < MAX_ABSTRAX)
|
||||||
|
{
|
||||||
|
log.back().advance();
|
||||||
|
solve(log,p_Box,puzzleMat);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setsolution(log,p_Box,puzzleMat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//case last log exactly one solution
|
||||||
|
else if(log.back().PieceCollector.size() == 1)
|
||||||
|
{
|
||||||
|
//create new log, put next coordinates in and go into solve. then git gud
|
||||||
|
log.push_back(LogEntry());
|
||||||
|
log.back().myCoor = getNextCoor(log, p_Box, puzzleMat);
|
||||||
|
solve(log, p_Box,puzzleMat);
|
||||||
|
}
|
||||||
|
|
||||||
//case last log empty
|
//case last log empty
|
||||||
//backtrack
|
//backtrack
|
||||||
|
else if(log.back().PieceCollector.size() == 0)
|
||||||
|
{
|
||||||
|
backtrack(log,p_Box,puzzleMat);
|
||||||
|
}
|
||||||
|
|
||||||
//case last log exactly one solution
|
return 1;
|
||||||
//put all remaining puzzle pieces into new log entry
|
|
||||||
//try next piece/place with solve abstraction level 0
|
|
||||||
|
|
||||||
//case last log multiple entries
|
|
||||||
//advance abstraction layer of last log by one and solve()
|
|
||||||
//or pick first if highest level reached
|
|
||||||
|
|
||||||
//return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void solve()
|
|
||||||
|
coor calculateFirstCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
|
||||||
{
|
{
|
||||||
//case
|
//returns coor of first piece
|
||||||
|
coor firstCoor(0,0);
|
||||||
|
return firstCoor;
|
||||||
|
}
|
||||||
|
|
||||||
|
coor calculateNextCoor(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
|
||||||
|
{
|
||||||
|
//level 1:
|
||||||
|
//go left to right, then increase current row
|
||||||
|
|
||||||
|
//if
|
||||||
|
|
||||||
|
//return nextCoor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
|
||||||
|
{
|
||||||
|
switch(log.back().abstraction==0)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if()
|
||||||
//abstraction layer = 0
|
//abstraction layer = 0
|
||||||
//go to abstraction layer 0 solver
|
//go to abstraction layer 0 solver
|
||||||
|
|
||||||
@ -37,19 +88,18 @@ void solve()
|
|||||||
|
|
||||||
void abstractionlayer0solver()
|
void abstractionlayer0solver()
|
||||||
{
|
{
|
||||||
//throw all remaining puzzle pieces into log
|
//throw all remaining puzzle pieces into newest log
|
||||||
//remove all impossible
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void abstractionlayer1solver()
|
void abstractionlayer1solver()
|
||||||
{
|
{
|
||||||
//remove all impossible according to abstraction layer one
|
//remove all impossible from newest log according to abstraction layer one
|
||||||
}
|
}
|
||||||
|
|
||||||
void setsolution()
|
void setsolution()
|
||||||
{
|
{
|
||||||
//put
|
//remove first element in last logelement from box
|
||||||
//set pointer to log into matrix
|
//set pointer to this element into matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
void backtrack()
|
void backtrack()
|
||||||
|
@ -36,6 +36,7 @@ private:
|
|||||||
unsigned int shifts;
|
unsigned int shifts;
|
||||||
unsigned int boxidentifier;
|
unsigned int boxidentifier;
|
||||||
unsigned int identifier;
|
unsigned int identifier;
|
||||||
|
|
||||||
static unsigned int idcount;
|
static unsigned int idcount;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,8 +127,7 @@ class coor
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int m, n;
|
int m, n;
|
||||||
coor():m(-1),n(-1){}
|
coor(int newm=-1,int newn=-1): m(newm), n(newn)
|
||||||
coor(int newm,int newn): m(newm), n(newn)
|
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -135,14 +135,14 @@ class LogEntry
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
vector<PuzzlePiece*> PieceCollector;
|
vector<PuzzlePiece*> PieceCollector;
|
||||||
vector<coor> CoorCollector;
|
|
||||||
int abstractionLevel;
|
int abstractionLevel;
|
||||||
|
|
||||||
coor myCoor;
|
coor myCoor;
|
||||||
PuzzlePiece* myPuzzlePiece;
|
|
||||||
|
void advance(){abstractionLevel++;}
|
||||||
|
|
||||||
LogEntry()
|
LogEntry()
|
||||||
{
|
{
|
||||||
|
myCoor();
|
||||||
abstractionLevel=0;
|
abstractionLevel=0;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
|
#define MAX_ABSTRAX = 1
|
||||||
|
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
int cols=3, rows=2;
|
||||||
|
//some basic part stuff
|
||||||
vector<Part> myFirstPuzzle;
|
vector<Part> myFirstPuzzle;
|
||||||
Part myFirstPart;
|
Part myFirstPart;
|
||||||
myFirstPart.setConnections(0b00101000);
|
myFirstPart.setConnections(0b00101000);
|
||||||
myFirstPuzzle.push_back(myFirstPart);
|
myFirstPuzzle.push_back(myFirstPart);
|
||||||
cout << "Hello World" << endl;
|
|
||||||
randomBox myFirstBox(2,3);
|
//some basic random puzzle stuff
|
||||||
|
randomBox myFirstBox(cols,rows);
|
||||||
myFirstBox.createRandomPuzzle();
|
myFirstBox.createRandomPuzzle();
|
||||||
myFirstBox.shuffle();
|
myFirstBox.shuffle();
|
||||||
myFirstBox.printPuzzle();
|
myFirstBox.printPuzzle();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//some advanced solver stuff
|
||||||
|
vector<LogEntry> log;
|
||||||
|
vector<PuzzlePiece*> p_myFirstBox;
|
||||||
|
for(int i=0;i<myFirstBox.size();i++)
|
||||||
|
p_myFirstBox[i] = &myFirstBox[i];
|
||||||
|
Puzzle puzzleMat(cols, rows);
|
||||||
|
|
||||||
|
while(next(log, p_myFirstBox,puzzleMat));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user