What would be the best way to see (in a 2 player) game of Tic Tac Toe who won? Right now I'm using something similar to the following:
if (btnOne.Text == "X" && btnTwo.Text == "X" && btnThree.Text == "X")
{
MessageBox.Show("X has won!", "X won!");
return;
}
else
// I'm not going to write the rest but it's really just a bunch
// if statements.
So how do I get rid of the multiple if's?
The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. It is a solved game, with a forced draw assuming best play from both players.
Something alongs:
rowSum == 3 || columnSum == 3 || diagnolSum == 3
.. ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With