so i am in a beginners c++ class, and we have an assignment where we make a tic tac toe game with arrays, but our next step is to find illegal moves and cout illegal move. We also have to determine how to find a winner. any help would be appreciated!!
How would you do this if playing using paper/pen? How would you tell some else how to check for a winner etc? Write down exactly how this would be done so that someone else who knows nothing about TicTacToe can follow it and undertake the process correctly.
The first part of programming is to design the program - not coding! Only when you have a program design do you then start to code the program from the design. The design includes the processes needed to do what is required - such as determining if/who is the winner. If you can't specify how something is to be done, then you can't code it - the program just does what it's told!
Once you have the design then if you have issues converting to code, then we'll be able to advise on this.
// for a two-dimensional array,
// gameboard[3][3],
//
// 1 2 3
// 4 5 6
// 7 8 9
//
// then...
// This is to check for a top-row win.
if (gameboard[0][0] == gameboard[0][1] && gameboard[0][0] == gameboard[0][2] && gameboard[0][0] != '1')
{
if (gameboard[0][0] == 'X')
{
xWin = true;
}
elseif (gameboard[0][0] == 'O')
{
oWin = true;
}
}
// Add more if statements to check for each row, column, and diagonal wins.
// You will need 7 more if statements to check all of them.
// xWin and oWin are booleans that cause another function to output "X wins!" or "O wins!" respectively.