Print solution
| 128 | |
| 129 | /// Print solution |
| 130 | virtual void |
| 131 | print(std::ostream& os) const { |
| 132 | os << "\tNumber of Queens: " << q << std::endl; |
| 133 | os << "\tBoard: " << b << std::endl; |
| 134 | if (b.assigned()) { |
| 135 | // Print a nice board |
| 136 | bool* placed = new bool[n*n]; |
| 137 | for (int i=0; i<n*n; i++) |
| 138 | placed[i] = false; |
| 139 | for (int i=0; i<n*n; i++) |
| 140 | placed[b[i].val()] = true; |
| 141 | for (int j=0; j<n; j++) { |
| 142 | std::cout << "\t\t"; |
| 143 | for (int i=0; i<n; i++) |
| 144 | std::cout << (placed[xy(i,j)] ? 'Q' : '.') << ' '; |
| 145 | std::cout << std::endl; |
| 146 | } |
| 147 | delete [] placed; |
| 148 | } |
| 149 | os << std::endl; |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | /** \brief Main-function |