Hi! I'm doing a checkers program and I want to show to screen the human while the program is computing the move of the AI.
Here goes the transition between the Human and Computer move:
void FinishHumanMove(GivenMove givenMove)
{
ApplyMove(pieceOnBoard,givenMove);
UpdateBoard(); //Visual Update
ComputerTurn();
}
void ComputerTurn()
{
currentPlayer = WhoIsPlaying.Computer;
GivenMove chosenComputerMove = MinimaxDecision(pieceOnBoard,7);
ApplyMove(pieceOnBoard,chosenComputerMove);
UpdateBoard(); //Visual Update
UpdateTileComputerMove(chosenComputerMove); //Visual Update
HumanTurn();
}
However, because the computation time is quite long is the ComputerTurn() function, the UpdateBoard in the FinishHumanMove() does not finish, hence there is a feeling of lag. I checked the yield function and coroutine, but i don't know how to use them to solve my problem.
Any suggestion to how to finish the rendering of the UpdateBoard() while computing the ComputerTurn??
Thanks.
↧