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()
|
||||
bool next(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat)
|
||||
{
|
||||
|
||||
//calculates next move according to log
|
||||
//case first log entry empty
|
||||
if(!(log.size())
|
||||
{
|
||||
log.push_back(LogEntry());
|
||||
solve(log, p_Box,puzzleMat);
|
||||
}
|
||||
|
||||
//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
|
||||
//backtrack
|
||||
else if(log.back().PieceCollector.size() == 0)
|
||||
{
|
||||
backtrack(log,p_Box,puzzleMat);
|
||||
}
|
||||
|
||||
//case last log exactly one solution
|
||||
//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;
|
||||
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
|
||||
//go to abstraction layer 0 solver
|
||||
|
||||
@ -37,19 +88,18 @@ void solve()
|
||||
|
||||
void abstractionlayer0solver()
|
||||
{
|
||||
//throw all remaining puzzle pieces into log
|
||||
//remove all impossible
|
||||
//throw all remaining puzzle pieces into newest log
|
||||
}
|
||||
|
||||
void abstractionlayer1solver()
|
||||
{
|
||||
//remove all impossible according to abstraction layer one
|
||||
//remove all impossible from newest log according to abstraction layer one
|
||||
}
|
||||
|
||||
void setsolution()
|
||||
{
|
||||
//put
|
||||
//set pointer to log into matrix
|
||||
//remove first element in last logelement from box
|
||||
//set pointer to this element into matrix
|
||||
}
|
||||
|
||||
void backtrack()
|
||||
|
@ -36,6 +36,7 @@ private:
|
||||
unsigned int shifts;
|
||||
unsigned int boxidentifier;
|
||||
unsigned int identifier;
|
||||
|
||||
static unsigned int idcount;
|
||||
};
|
||||
|
||||
@ -126,8 +127,7 @@ class coor
|
||||
{
|
||||
public:
|
||||
int m, n;
|
||||
coor():m(-1),n(-1){}
|
||||
coor(int newm,int newn): m(newm), n(newn)
|
||||
coor(int newm=-1,int newn=-1): m(newm), n(newn)
|
||||
{}
|
||||
};
|
||||
|
||||
@ -135,14 +135,14 @@ class LogEntry
|
||||
{
|
||||
public:
|
||||
vector<PuzzlePiece*> PieceCollector;
|
||||
vector<coor> CoorCollector;
|
||||
int abstractionLevel;
|
||||
|
||||
coor myCoor;
|
||||
PuzzlePiece* myPuzzlePiece;
|
||||
|
||||
void advance(){abstractionLevel++;}
|
||||
|
||||
LogEntry()
|
||||
{
|
||||
myCoor();
|
||||
abstractionLevel=0;
|
||||
}
|
||||
private:
|
||||
|
@ -1,15 +1,34 @@
|
||||
#define MAX_ABSTRAX = 1
|
||||
|
||||
#include "header.h"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int cols=3, rows=2;
|
||||
//some basic part stuff
|
||||
vector<Part> myFirstPuzzle;
|
||||
Part myFirstPart;
|
||||
myFirstPart.setConnections(0b00101000);
|
||||
myFirstPuzzle.push_back(myFirstPart);
|
||||
cout << "Hello World" << endl;
|
||||
randomBox myFirstBox(2,3);
|
||||
|
||||
//some basic random puzzle stuff
|
||||
randomBox myFirstBox(cols,rows);
|
||||
myFirstBox.createRandomPuzzle();
|
||||
myFirstBox.shuffle();
|
||||
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