diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index 828f287..05a62d5 100644 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -1,30 +1,81 @@ - -bool next() +bool next(vector& log, vector& p_Box, Puzzle& puzzleMat) { + //case first log entry empty + if(!(log.size()) + { + log.push_back(LogEntry()); + solve(log, p_Box,puzzleMat); + } - //calculates next move according to log + //case puzzle solved + else if(!(p_Box.size()) + return 0; - //case puzzle solved - //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 empty - //backtrack + //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 exactly one solution - //put all remaining puzzle pieces into new log entry - //try next piece/place with solve abstraction level 0 + //case last log empty + //backtrack + else if(log.back().PieceCollector.size() == 0) + { + backtrack(log,p_Box,puzzleMat); + } - //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& log, vector& p_Box, Puzzle& puzzleMat) { - //case + //returns coor of first piece + coor firstCoor(0,0); + return firstCoor; +} + +coor calculateNextCoor(vector& log, vector& p_Box, Puzzle& puzzleMat) +{ + //level 1: + //go left to right, then increase current row + + //if + + //return nextCoor; +} + +void solve(vector& log, vector& 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() diff --git a/Source/header/solve.h b/Source/header/solve.h index fcbd14b..27b7618 100644 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -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 PieceCollector; - vector CoorCollector; int abstractionLevel; - coor myCoor; - PuzzlePiece* myPuzzlePiece; + + void advance(){abstractionLevel++;} LogEntry() { + myCoor(); abstractionLevel=0; } private: diff --git a/Source/main.cpp b/Source/main.cpp index 59f9f66..a2a86ec 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -1,15 +1,34 @@ +#define MAX_ABSTRAX = 1 + #include "header.h" + + int main() { + + int cols=3, rows=2; + //some basic part stuff vector 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 log; + vector p_myFirstBox; + for(int i=0;i