I'm trying to make chess in the c++ console and I have a function that searches for the piece you want to move. The first parameter is the 2d array that stores the board's state. But when I call the function in the move function it gives me this error:
cannot convert argument 1 from 'int' to 'int [][8]
It also tells me that
argument of type "int" is incompatible of type "int (*)[8]
I don't understand why that is since the argument is the same 2d array
pair<int, int> search_piece(int v[8][8], int col, int piece, bool colour) {
for (int row = 0; row < 8; row++)
if (!colour) {
if (v[row][col] == piece && v[row][col] < 7)
return make_pair(row, col);
}
else
if (v[row][col] == piece && v[row][col] > 6)
return make_pair(row, col);
return make_pair(-1, -1);
}
void move(int v[8][8], int row, int col, int piece, bool colour) {
pair<int, int> pos = search_piece(v[8][8], col, piece, colour);
int irow = pos.first;
int icol = pos.second;
if (irow >= 0 && icol >= 0)
swap(v[irow][icol], v[row][col]);
else
cout << "Invalid move!\n";
}