i need some help with figuring out how to check diagonals in my 3D Tic-Tac-Toe board. i have the horizontal, vertical and depth done fine but i cant figure out how to get diagonals. i only put in the check part since the full code is really long. the peoblem is that im making it to that you choose wha cubic dimensions you want and i dont know how to go through the board and only check diagonal.
template <class TYPE>
class Grid : public Darray<TYPE> {
private:
int currentRow,
currentDepth,
currentCol;
public:
Grid();
Grid(TYPE depth, TYPE row, TYPE col);
void arrow_keys(Player *player);
bool win();
void clear_screen(void);
void draw ();
void draw (TYPE d);
void topBorder();
void bottomBorder();
bool winHorizontal(Player* player);
bool winVertical(Player* player);
bool winDiagonal(Player* player);
bool winCubic(Player* player);
};
template <class TYPE>
bool Grid<TYPE>::winHorizontal(Player* player)
{
int count;
for(int d = 0; d <DEPTH; d++){
for(int r = 0; r<ROW; r++){
for(int c = 0; c< COL; c++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == COL)
return true;
count = 0;
}
}
cout << "Player " << symbol << " Wins!!" << endl;
return false;
}
template <class TYPE>
bool Grid<TYPE>::winVertical(Player* player)
{
int count;
for(int d = 0; d <DEPTH; d++){
for(int r = 0; r<ROW; r++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == ROW)
return true;
count = 0;
}
cout << "Player " << symbol << " Wins!!" << endl;
return false;
}
template <class TYPE>
bool Grid<TYPE>::winDiagonal(Player* player)
{
int count;
for(int d = 0; d <DEPTH; d++){
for(int r = 0; r<ROW; r++){
for(int c = 0; c< COL; c++)
{
if(*player == *array[d][r][c].getPlayer() || *player == *array[d][r][c].getPlayer() )
count++;
}
if()
return true;
count = 0;
currentDepth--;
}
}
cout << "Player " << symbol << " Wins!!" << endl;
return false;
}
template <class TYPE>
bool Grid<TYPE>::winCubic(Player* player)
{
int count;
for(int d = 0; d < DEPTH; d++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == DEPTH)
return true;
count = 0;
cout << "Player " << symbol << " Wins!!" << endl;
return false;
}
template <class TYPE>
bool Grid<TYPE>::win()
{
if(winHorizontal())
return true;
if(winVertical())
return true;
if(winDiagonal())
return true;
if(winCubic())
return true;
else
return false;
}