I am currently working in a implementing a quoridor game in java , using AI game-playing algorithms. After the "human" clicks to make his move , the gui needs to be updated and the AI start thinking. I have something like this inside the panel:
public void mouseClicked(MouseEvent e)
{
gameBoard.executeMove( movePawn );
repaint();
gameboard.callAi();
}
After I call the funtcion callAi() , I get into a loop that is consuming too much time to finish. The gui on the other hand freezes , it doesnt update , even thought the repaint method is called before the AI "start thinking". I tried to put a delay before I call the AI , but it was not working. I wrote this one:
try
{ TimeUnit.MILLISECONDS.sleep(5);}
catch{}
What can I do to solve this one ? Maybe it has something to do with threads , but I am not too friendly with threads in Java.