I'm trying to write a solution to the 8 queens problem. I am trying to start with a empty board. I keep getting the following error "error C2664: 'SetQueen' : cannot convert parameter 1 from 'int' to 'int [][8]'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast" It's from the line SetQueen(chessboard[8][8], 0);
If anybody can tell me what I am doing wrong, I would greatly appreciate it. I'm just getting to arrays so I may not have declared them correctly either. Thanks for any assistance in helping me understand what I am trying to do.
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::endl;
void SetQueen (int [8][8], int);
bool CheckAttack (int [8][8], int, int);
void DisplayBoard (int [8][8]);
int main()
{
int chessboard[8][8];
SetQueen(chessboard[8][8], 0);
return 0;
}
void SetQueen (int chessboard[8][8], int column)
{
for (int row=0; row<=7; row++)
if (CheckAttack(chessboard,row,column))
{
chessboard[row][column] = true;
if (column==7)
{
DisplayBoard(chessboard);
}
else SetQueen(chessboard, column+1);
chessboard[row][column] = false;
}
}
bool CheckAttack (int chessboard[8][8], int testRow, int testColumn)
{
for (int row = testRow; row >= 0; row--)
for (int column = testColumn; column >= 0; column--)
if (chessboard[row][column])
return false;
for (int column = testColumn; column >= 0; column--)
if (chessboard[testRow][column])
return false;
for (int row = testRow; row <= 7; row++)
for (int column = testColumn; column >= 0; column--)
if (chessboard[row][column])
return false;
return true;
}
void DisplayBoard (int chessboard[8][8])
{
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
chessboard[row][column] = 0;
cout << chessboard[row][column] << ' ';
}
cout << endl;
}
}