--- queensgui/src/queens.cpp 2007/07/19 23:36:33 3 +++ queensgui/src/queens.cpp 2007/07/19 23:44:01 4 @@ -23,13 +23,14 @@ #include "solutioncontainer.h" -Queens::Queens(GUIUpdate *par, SolutionContainer *sol, int set_size, bool set_debug) : QThread(), solution(set_size) +Queens::Queens(GUIUpdate *par, Solution* sol, SolutionContainer *container, int set_size, bool set_debug) : QThread() { - parent = par; - size = set_size; - solution.setSize(size); - debug = set_debug; - solutions = sol; + m_parent = par; + m_size = set_size; + m_solution = sol; + m_solution->setSize(m_size); + m_debug = set_debug; + m_solutions = container; } bool Queens::solve() @@ -44,28 +45,29 @@ bool Queens::solve(int row, bool findAll) { - if (blocked == true) + if (m_blocked == true) return false; - for (int col=0; colsetMatrix(row,col,true); + + if (row == (m_size-1) ) { if (!findAll) return true; else { - solutions->addSolution( solution.copy() ); - parent->foundSolution(); + m_solutions->addSolution( m_solution->copy() ); + m_parent->foundSolution(); } } if ( solve(row+1,findAll) ) return true; - solution.matrix[row][col] = false; + m_solution->setMatrix(row,col, false); } } return false; @@ -74,8 +76,8 @@ bool Queens::checkRows(int row, int col) { - for (int c=0; cgetMatrix(row,c) == true) return false; } @@ -84,8 +86,8 @@ bool Queens::checkCols(int row, int col) { - for (int r=0; rgetMatrix(r,col) == true) return false; } return true; @@ -95,18 +97,18 @@ { int r=row; int c=col; - for (int i=0; igetMatrix(r,c) == true) return false; r++; c++; - if ( r>(size-1) || c>(size-1) ) + if ( r>(m_size-1) || c>(m_size-1) ) break; } r=row; c=col; - for (int i=0; igetMatrix(r,c) == true) return false; r--; c--; @@ -120,22 +122,22 @@ { int r=row; int c=col; - for (int i=0; igetMatrix(r,c) == true) return false; r++; c--; - if ( r>(size-1) || c<0 ) + if ( r>(m_size-1) || c<0 ) break; } r=row; c=col; - for (int i=0; igetMatrix(r,c) == true) return false; r--; c++; - if (r<0 || c>(size-1)) + if (r<0 || c>(m_size-1)) break; } return true; @@ -143,15 +145,15 @@ void Queens::run() { - blocked = false; + m_blocked = false; findAll(); - if (blocked == false) - parent->finishedSearch(); + if (m_blocked == false) + m_parent->finishedSearch(); } void Queens::stop() { - blocked = true; + m_blocked = true; }