Log In  


When the AI plays itself in my game, it is too much for the _update() so PICO-8 drops _draw() frames. The moves are correct, but its awkward because both pieces move at once.

How do I remedy this? Is it a coroutine I need? I've been playing with them and have gotten some crazy results, not really knowing what I am trying to accomplish. But is that even the right approach?

Or can I make some kind of delay between moves to give the cpu time to catch up? I tested by making it only run the engine after a button press and it works fine.

I also tried calling flip() explicitly after the resource-heavy function but no dice.

any pointers are appreciated.



1

It is possible to use co-routines, monitor cpu usage, and give back the control mid computations to not have _draw calls skipped.
There's a much simpler way : do your computations that take more than one frame to compute, but each time you reach a significant state, say you've finished moving an ennemy piece but still have to compute more moves, call flip() to force a call to _draw() .
You'll get more skipped frames but won't miss significant visual steps this way.


@RealShadowCaster
Thank you for the reply and I used your suggestion. The problem is that it's computing so many positions in one recursive loop. So there's no clear break point. But I put the flip inside the main loop of alphabeta and it is working properly. I added a stat(1) condition:

if stat(1)>0.6 then
 flip()
end


[Please log in to post a comment]