How to allow screen to update while thinking

I am writing a board game. For the computer’s move, I use a minmax algorithm to think through many possible moves.

The problem is that the tween I start to animate the player’s move before the computer begins thinking about its own doesn’t update while the computer is thinking. I would like it to update. If I could just do this, then by the time the animation finishes the computer should finish its thinking, or be close to it. But I can’t seem to get the tween to run while the computer is in the recursive minmax function.

Is there any way to fix this? I don’t think a core routine would work because it needs to return a value.

I amusing itween. I really only need to update the tweens when it is thinking, so if there is just some way to force itween to do that.

I am very new to unity, so sorry if this is a newb question, but I have been banging my head against the wall trying to solve it.

Thanks,

Moving the thinking process to a seperate thread should probably work

A coroutine doesn’t really have to return a value, you can simply return null and if you started the coroutine using Unity’s StartCoroutine then it will simply be resumed in the next frame. So if you can divide your work into small steps, you can do something like this:

IEnumerator Think() {
     for (int i = 0; i < stepCount; i++) {
          // perform one step
          yield return null;
     }
}

void SomewhereElse() {
     StartCoroutine(Think());
}

Note however that this means that it will always take stepCount frames for the coroutine to complete. It won’t just complete as fast as possible.

Alternatively you can use a separate thread as has already been suggested but unfortunately lots of Unity stuff only works on the main thread.