/[projects]/queensgui/src/solution.cpp
ViewVC logotype

Diff of /queensgui/src/solution.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by torben, Thu Jul 19 21:34:15 2007 UTC revision 5 by torben, Fri Jul 20 01:22:53 2007 UTC
# Line 19  Line 19 
19   ***************************************************************************/   ***************************************************************************/
20  #include "solution.h"  #include "solution.h"
21    
22    #include <iostream>
23    
24  Solution::Solution(int size)  using namespace std;
 {  
         m_size = size;  
         for (int i=0; i<m_size; i++)  
                 for (int j=0; j<m_size; j++)  
                         matrix[i][j] = false;  
 }  
   
25    
26  Solution::~Solution()  void Solution::print()
27  {  {
28            print(false, -1, -1);
29  }  }
30    
31    void Solution::print(bool debug, int row, int col)
 Solution::Solution(const Solution &input)  
32  {  {
33          m_size = input.m_size;          for (int i=0; i<m_size; i++) {
         for (int i=0; i<m_size; i++)  
34                  for (int j=0; j<m_size; j++)                  for (int j=0; j<m_size; j++)
35                          matrix[i][j] = input.matrix[i][j];                          cout << "+--";
36  }                  cout << "+" << endl;
   
   
 void Solution::set(bool input[MAX_SIZE][MAX_SIZE])  
 {  
         for (int i=0; i<m_size; i++)  
                 for (int j=0; j<m_size; j++)  
                         matrix[i][j] = input[i][j];  
 }  
   
   
 void Solution::rotate90()  
 {  
         bool temp[MAX_SIZE][MAX_SIZE];  
   
         for (int i=0; i<m_size; i++)  
37                  for (int j=0; j<m_size; j++) {                  for (int j=0; j<m_size; j++) {
38                          temp[j][(m_size-1)-i] = matrix[i][j];                          cout << "|";
39                            if (debug==true && row!=-1 && i==row && j==col)
40                                    cout << "??";
41                            else
42                                    cout << ( getMatrix(i,j)==true ? "QQ" : "  ");
43                  }                  }
44          set(temp);                  cout << "|" << endl;
45            }
46            for (int j=0; j<m_size; j++)
47                    cout << "+--";
48            cout << "+" << endl;
49  }  }
   
 void Solution::mirror()  
 {  
         bool temp[MAX_SIZE][MAX_SIZE];  
   
         for (int i=0; i<m_size; i++)  
                 for (int j=0; j<m_size;j++)  
                         temp[i][(m_size-1)-j] = matrix[i][j];  
         set(temp);  
 }  
   
   
 bool Solution::operator==(const Solution& sol)  
 {  
         for (int i=0; i<m_size; i++)  
                 for (int j=0; j<m_size; j++)  
                         if (matrix[i][j] != sol.matrix[i][j])  
                                 return false;  
         return true;  
 }  
   
 bool Solution::operator!=(const Solution& sol)  
 {  
         int matchcount = 0;  
         for (int i=0; i<m_size; i++)  
                 for (int j=0; j<m_size; j++)  
                         if (matrix[i][j] == sol.matrix[i][j])  
                                 matchcount++;  
         if (matchcount == (m_size*2) )  
                 return false;  
         else  
                 return true;  
 }  
   

Legend:
Removed from v.1  
changed lines
  Added in v.5

  ViewVC Help
Powered by ViewVC 1.1.20