private PlayerType IsFinished() { if (Player == PlayerType.Maximizing) { for (int i = 0; i < ChessTable.SIZE; i++) { for (int j = 0; j < ChessTable.SIZE; j++) { var value = stateTable.GetValue(i, j); if (value == 1) { if ((i + j) % 2 == 0) { if (stateTable.GetValue(i + 1, j + 1) != 0 && stateTable.GetValue(i + 1, j) != 0 && stateTable.GetValue(i, j + 1) != 0 && stateTable.GetValue(i - 1, j + 1) != 0 && stateTable.GetValue(i - 1, j - 1) != 0 && stateTable.GetValue(i, j - 1) != 0 && stateTable.GetValue(i + 1, j - 1) != 0 && stateTable.GetValue(i - 1, j) != 0) { return(PlayerType.Minimizing); } i = ChessTable.SIZE; j = ChessTable.SIZE; } else { if ( stateTable.GetValue(i + 1, j) != 0 && stateTable.GetValue(i, j + 1) != 0 && stateTable.GetValue(i, j - 1) != 0 && stateTable.GetValue(i - 1, j) != 0) { return(PlayerType.Minimizing); } i = ChessTable.SIZE; j = ChessTable.SIZE; } } /* * if (stateTable.GetValue(i + 1, j + 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i + 1, j) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i, j + 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i + 1, j - 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i - 1, j + 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i - 1, j - 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i, j - 1) == 0) * { * i = ChessTable.SIZE; * break; * } * else if (stateTable.GetValue(i - 1, j) == 0) * { * i = ChessTable.SIZE; * break; * } * else * { * return PlayerType.Minimizing; * } */ } } } else if (Player == PlayerType.Maximizing) { int count = 0; for (int i = 0; i < ChessTable.SIZE; i++) { for (int j = 0; j < ChessTable.SIZE; j++) { if (stateTable.GetValue(i, j) == 2) { count++; } } } if (count < 4) { return(PlayerType.Maximizing); } } return(PlayerType.None); }
public ChessTable UpdateTable(ChessTable newTable) { for (int i = 0; i < ChessTable.SIZE; i++) { for (int j = 0; j < ChessTable.SIZE; j++) { if (newTable.GetValue(i, j) == 1 && Player == PlayerType.Maximizing) { int LU = newTable.GetValue(i - 1, j - 1); int L = newTable.GetValue(i, j - 1); int LD = newTable.GetValue(i + 1, j - 1); int Up = newTable.GetValue(i - 1, j); int Down = newTable.GetValue(i + 1, j); int R = newTable.GetValue(i, j + 1); int RU = newTable.GetValue(i - 1, j + 1); int RD = newTable.GetValue(i + 1, j + 1); //8 direction if ((i + j) % 2 == 0) { if (L == R && L == 2) { newTable.SetValue(PlayerType.None, i, j - 1); newTable.SetValue(PlayerType.None, i, j + 1); } if (LU == RD && LU == 2) { newTable.SetValue(PlayerType.None, i - 1, j - 1); newTable.SetValue(PlayerType.None, i + 1, j + 1); } if (Up == Down && Up == 2) { newTable.SetValue(PlayerType.None, i - 1, j); newTable.SetValue(PlayerType.None, i + 1, j); } if (LD == RU && LD == 2) { newTable.SetValue(PlayerType.None, i + 1, j - 1); newTable.SetValue(PlayerType.None, i - 1, j + 1); } } else { if (L == R && L == 2) { newTable.SetValue(PlayerType.None, i, j - 1); newTable.SetValue(PlayerType.None, i, j + 1); } if (Up == Down && Up == 2) { newTable.SetValue(PlayerType.None, i - 1, j); newTable.SetValue(PlayerType.None, i + 1, j); } } i = ChessTable.SIZE; j = ChessTable.SIZE; } } } return(newTable); }