Event driven search

Discussion about development of draughts in the time of computer and Internet.
Post Reply
Maurits Meijer
Posts: 221
Joined: Thu Nov 27, 2008 19:22
Contact:

Event driven search

Post by Maurits Meijer »

Hello,

I'm currently working on a JavaScript based engine but I am having trouble figuring out how to do the search. Since JavaScript is run in a single thread (without interupts available) I would like to do the search in chuncks of about 50 to 100 ms. That way the browser would still be able to respond to user input. The speed of the algorithm isn't that important, but just unraffeling the recursive calls of Negamax creates too much overhead. Has anybody done something like this before or know how to do this?
http://slagzet.com
MichelG
Posts: 244
Joined: Sun Dec 28, 2003 20:24
Contact:

Re: Event driven search

Post by MichelG »

Maurits Meijer wrote:Hello,

I'm currently working on a JavaScript based engine but I am having trouble figuring out how to do the search. Since JavaScript is run in a single thread (without interupts available) I would like to do the search in chuncks of about 50 to 100 ms. That way the browser would still be able to respond to user input. The speed of the algorithm isn't that important, but just unraffeling the recursive calls of Negamax creates too much overhead. Has anybody done something like this before or know how to do this?
You can do this by using a non-recursive implementation of alpha-beta. It's a bit more complicated to write, but than you can call it maybe 10000 times, and release the process for user input. It actually might be a tiny bit faster as well.
Ed Gilbert
Posts: 860
Joined: Sat Apr 28, 2007 14:53
Real name: Ed Gilbert
Location: Morristown, NJ USA
Contact:

Re: Event driven search

Post by Ed Gilbert »

I'm currently working on a JavaScript based engine but I am having trouble figuring out how to do the search. Since JavaScript is run in a single thread (without interupts available) I would like to do the search in chuncks of about 50 to 100 ms. That way the browser would still be able to respond to user input. The speed of the algorithm isn't that important, but just unraffeling the recursive calls of Negamax creates too much overhead. Has anybody done something like this before or know how to do this?
One way to do this is using a test of the search node counter. Every N nodes (entries to negamax), call your function that handles user input. Pick N so that it is often enough for the UI to be responsive, but not so often as to slow down your search. If N is one less than a power of 2, you can simply AND your node counter with it and test for 0.

-- Ed
Maurits Meijer
Posts: 221
Joined: Thu Nov 27, 2008 19:22
Contact:

Re: Event driven search

Post by Maurits Meijer »

Ed Gilbert wrote: One way to do this is using a test of the search node counter. Every N nodes (entries to negamax), call your function that handles user input. Pick N so that it is often enough for the UI to be responsive, but not so often as to slow down your search. If N is one less than a power of 2, you can simply AND your node counter with it and test for 0.

-- Ed

Thanks for the replys.
The browser itself needs to handle the events that are queued. When a function is executing the browser can't do that and will throw 'this page is not responding' popups at you. So I would need to be able to leave the search and have a timed-event call a function that would continue the search.

I'm gonna try the non-recursive way Michel suggested.

I also found that modern browser have webworkers that would really help out this case, but they are not supported by internet explorer:(
http://slagzet.com
Maurits Meijer
Posts: 221
Joined: Thu Nov 27, 2008 19:22
Contact:

Re: Event driven search

Post by Maurits Meijer »

Got the non-recursive version negamax working :)
It doesn't look as bad as I thought it might.
http://slagzet.com
Post Reply