Example #1
0
int	my_8r1()
{
  char	chessboard[8][8];
  char	x;
  char	y;

  x = 0;
  y = 0;
  init(chessboard, x, y);
  add_queen(chessboard, 8);
}
Example #2
0
 void solve() {
     if (count == size) {
         vector<string> r;
         for (int i = 0; i < size; ++i) {
             string c(size, '.');
             c[queens[i]] = 'Q';
             r.push_back(c);
         }
         result.push_back(r);
     } else {
         for (int col = 0; col < size; ++col) {
             if (col_free[col] && upward_free[count+col] &&
                 downward_free[count-col+size-1]) {
                 add_queen(col);
                 solve();
                 remove_queen(col);
             }
         }
     }
 }
Example #3
0
char	add_queen(char tab[][8], int queen)
{
  int	x;
  int	y;

  x = 0;
  y = 0;
  while (x < 8)
    {
      while (y < 8)
        {
	  if (tab[x][y] == 0)
	    {
	      tab[x][y] = 1;
	    }
          y = y +1;
        }
      y = 0;
      x = x + 1;
    }
  if (queen == 1)
    return (0);
  return (add_queen(tab, queen - 1));
}