#include <iostream>
usingnamespace std;
class FManager
{
int field[3][3];
bool checkWin(int, int);
bool usedField(int, int);
public:
void move(int, int);
};
bool FManager::checkWin(int i, int j)
{
if (field[i][++j] == 1 && field[i][--j] == 1) returntrue;
elseif (field[++i][j] == 1 && field[--i][j] == 1) returntrue;
elseif (field[++i][++j] == 1 && field[--i][--j] == 1) returntrue;
elsereturnfalse;
}
bool FManager::usedField(int s, int v)
{
int counter1 = 3;
int counter2 = 3;
if (field[0][0] != 1 && field[0][0] != 0)
{
for(int i, j = 0; i < 2, j < 2; i++, j++)
{
field[i][j] = 0;
}
}
if (field[s][v] != 1)
{
field[s][v] = 1;
if (counter1 >= 3 || counter2 >=3)
{
checkWin(s, v);
}
}
field[s][v] = 1;
cout << field[2][2];
returntrue;
}
void FManager::move(int m, int n)
{
usedField(m, n);
return;
}
It was going smooth, but now everytime I run it a error is generated and Windows asks me if I want to report it. I've read all the code twice but can't find the problem... Can someone help me?
My first guess would say that you might be overshooting your field. For example, in your checkWin function, if you passed 2 or higher to it then it will check beyond the scope of the array. I would also suggest running a debugger.
*headdesk* Yeah, I was using field.move(3, 3), checking beyond the scope of the array >.< I'm an idiot. Should've checked that after reading the code twice and not noticing anything wrong. Oh well, thanks anyway, pal!