kevin-shannon / connect4

The original vertical four in a line game.
12 stars 3 forks source link

Prevent AI from locking up the UI #16

Closed tannerkrewson closed 5 years ago

tannerkrewson commented 6 years ago

So I just added a fade animation to the main menu modal, and now when you click on AI vs AI, it gets locked into the grey screen for a second. This is because the AI code process syncronosly and the whole page has to wait for the AI code to execute before being able to process any other JS. The way to fix this would be to do the minimax calculations with callbacks, promises, or async/await.

I actually might be able to that outside of the AI itself, as a change to the XPlayer.js interface between the code of the player and the code of the game.

tannerkrewson commented 5 years ago

Also disallow "queueing" your next move by clicking the board while the AI is thinking

tannerkrewson commented 5 years ago

A loading spinner that represents the AI thinking would be cool; we could reuse the spinning chip

tannerkrewson commented 5 years ago

https://stackoverflow.com/questions/10344498/best-way-to-iterate-over-an-array-without-blocking-the-ui

The code we're running doesn't have to mess with the UI, so we could try web workers! https://caniuse.com/#feat=webworkers

tannerkrewson commented 5 years ago

done with web workers ✔️✔️✔️

ef3d3ed097005a13c3bb135811ed90d599bfe0a1