void Player1Turn() { currentPlayer = 1; gameState.CurrentPlayer = currentPlayer; gameUI.UpdateUI(gameState); if (!isHotseatGame) { if (currentPlayer == humanPlayerTurn) { gameBoard.UpdateBoard(gameState); return; } int bestMove = aiPlayer.GetMove(gameState, 'x');//if minimax doesn't work yet, we will place the symbol in next available spot. while (!gameState.IsValidMove(gameState.GetMoveFromIndex(bestMove), 2)) { bestMove = aiPlayer.GetMove(gameState, 'o'); } if (bestMove == -1) { Debug.LogError("ERROR: best move is null."); } Debug.Log("AI moved -> " + bestMove); StartCoroutine(MakeMoveOnState(bestMove)); } }
private void MakeCallAI(AIPlayer ai) { WaitingAI = true; Thread th = new Thread(() => { var b = game.GetBoard(); var move = ai.GetMove(b); Thread.Sleep(1000); App.Current.Dispatcher.Invoke(() => { buttonGrid[move.Row, move.Column].Click(); WaitingAI = false; }); }); th.Start(); }