您可以拥有一个包含所有获胜案例的矩阵,并检查当前状态是否为获胜状态:
// Example
var matrix = new[,] { { "O", "+", "+" }, { "O", "+", "+" }, { "O", "+", "+" } };
var wins = new List<string> {
"100100100", // 1st column vertical
"010010010", // 2nd column vertical
"001001001", // 3rd column vertical
"111000000", // 1st row horizontal
"000111000", // 2nd row horizontal
"000000111", // 3rd row horizontal
"100010001", // top-left bottom-right diagonal
"001010100" // top-right bottom-left diagonal
};
// Crosses (X)
var check = new List<string> {"0", "0", "0", "0", "0", "0", "0", "0", "0"};
for (var i = 0; i < 3; i++)
for (var j = 0; j < 3; j++)
if (matrix[i, j] == "X") check[i*3 + j] = "1";
if (wins.Contains(string.Join("", check))) { /* crosses win */ }
// Circles (O)
check = new List<string> { "0", "0", "0", "0", "0", "0", "0", "0", "0" };
for (var i = 0; i < 3; i++)
for (var j = 0; j < 3; j++)
if (matrix[i, j] == "O") check[i * 3 + j] = "1";
if (wins.Contains(string.Join("", check))) { /* circles win */ }