Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created July 27, 2019 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/206706f946852e9fc6ad1f3f0854d036 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/206706f946852e9fc6ad1f3f0854d036 to your computer and use it in GitHub Desktop.
private bool CheckForWinner()
{
// Check rows
foreach (List row in fields)
{
if (row[0] != Player.None && row[0] == row[1] && row[1] == row[2])
{
return true;
}
}
// Check columns
for (var column_index = 0; column_index < FIELD_SIZE; column_index++)
{
if (fields[0][column_index] != Player.None
&& fields[0][column_index] == fields[1][column_index]
&& fields[1][column_index] == fields[2][column_index])
{
return true;
}
}
// Check left-right diagonal
if (fields[0][0] != Player.None && fields[0][0] == fields[1][1]
&& fields[1][1] == fields[2][2])
{
return true;
}
// Check right-left diagonal
if (fields[0][2] != Player.None && fields[1][1] == fields[2][0]
&& fields[1][1] == fields[0][2])
{
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment