void HandleAIMove() { Player player = Player.GetPlayerFromTurn(turn, player1, player2); if (player.Mode != Player.Modes.Human) { List <Tuple <int, int> > validMoves = Game.GetValidMoves(board, player.Tile); Tuple <int, int> move = null; if (validMoves.Count > 0) { if (player.Mode == Player.Modes.AILegendary) { move = Game.GetAIMove(board, 4, player.Tile); } else if (player.Mode == Player.Modes.AIHard) { move = Game.GetAIMove(board, 3, player.Tile); } else if (player.Mode == Player.Modes.AINormal) { move = Game.GetAIMove(board, 2, player.Tile); } else if (player.Mode == Player.Modes.AIEasy) { move = Game.GetMaxScoreMove(board, player.Tile); } } HandleNextMove(move); } }
void HandleNextMove(Tuple <int, int> move) { if (Game.GetWinner(board) == Game.Empty) { Player currentPlayer = Player.GetPlayerFromTurn(turn, player1, player2); List <Tuple <int, int> > validMoves = Game.GetValidMoves(board, currentPlayer.Tile); if (validMoves.Count > 0 && move != null) { if (validMoves.Contains(move)) { Game.MakeMove(board, move, currentPlayer.Tile); boardHistories.Add(board.Clone() as byte[, ]); turn++; RenderBoard(board); } else { return; } } else { turn++; } if (Game.GetWinner(board) != Game.Empty) { HandleWinner(); } Player nextPlayer = Player.GetPlayerFromTurn(turn, player1, player2); if (nextPlayer.Mode != Player.Modes.Human) { HandleAIMove(); } } }