Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for winner in TicTacToe?

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?

like image 757
Kredns Avatar asked Apr 11 '09 17:04

Kredns


People also ask

Is there a winner in tic tac toe?

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.


1 Answers

Something alongs:

rowSum == 3 || columnSum == 3 || diagnolSum == 3

.. ?

like image 187
chakrit Avatar answered Sep 30 '22 09:09

chakrit