bobtheuberfish / chiriboga

Implements Netrunner in Javascript against an AI opponent
https://chiriboga.sifnt.net.au/
GNU General Public License v3.0
86 stars 11 forks source link

"Thinking" of AI takes a long time #145

Closed R41B closed 1 year ago

R41B commented 1 year ago

Hi there! I was wondering what the "thinking" option of the AI means. Is it really deciding what the next turn would be, or is it just a gimmick to make the AI look more natural? Sometimes I have to wait for a long time (almost 20 seconds) before the "thinking" is over, and it takes a lot of the speed of the game away.

Is there by any chance a way to speed this up or remove it?

Thanks!

bobtheuberfish commented 1 year ago

Hi,

During 'thinking' the AI is determining the potential cost of running each server. This can take a long time, especially if there are servers with lots of ice and there are lots of abilities in play that could be used during the run as the number of possibilities grows enormously large. I have tried to optimise the AI to only consider possibilities that are likely to be useful but it does need to be quite thorough so that it doesn't miss anything crucial. I have even added a time limit to how long it is allowed to think about each server - if it runs out of time then it just has to accept the best estimate it has come up with so far.

In an ideal world I would do this computation across multiple cores (e.g. two threads would take half the time) but unfortunately I have not found a way to do multithreading in JavaScript. In the previous version of the game it would completely freeze during these run calculations so I implemented a kind of pretend multithreading where the browser swaps back and forth between doing the calculation and animating the screen many times a second. This makes it much nicer to play but it has also made the total calculation time longer...

So in short I think the answer to your question is no.

R41B commented 1 year ago

Okay! I understand it better now. It all makes sense. Thanks!