I went the other way, from computations on the server to computations
on the client. Here's why: if you have a large number of players, your
server costs will become a real problem. But the number of clients
available to do calculations expands with the number of players, and
client CPU time costs you nothing.

What you need to do is break the task down into maybe 100 iterations
and call it 100 times, something like the code here, which shows a
prime number routine coded conventionally and then coded in
setTimeout() pieces.

http://dreaminginjavascript.wordpress.com/2008/08/02/functions_are_weird/

Add a progress bar and you're good.

On Sep 5, 5:14 pm, jbhat <[EMAIL PROTECTED]> wrote:
> So I am porting a variation of the board game Hex from java to
> javascript, as I am putting it on the web.  One of the functions I
> need to write for the computer AI to get his next move is to fill in
> the rest of the board (a filled hex is red or blue, an unfilled is
> white) 300,000 times, randomly, and check the winner of the game, and
> then make some quick calculations, and returns the position of the
> best move.
>
> This worked fine in Java, but it seems to be hanging up in JS.  I have
> decreased the number of repetitions to 100,000, and then down to 1000,
> and i still have to stop the script when I test it in firefox.  I was
> wondering if I could pass the data to an AJAX call, do the
> computations in PHP, and then return the correct move.  I am having 2
> problems however:
>
> 1) I don't think you can pass an array to AJAX, and I have an array of
> hex colors for the board that must be passed in.
>
> 2) The function making the AJAX call must return the move (and the
> correct bid, as this is a bidding game), but the function ends before
> the AJAX call completes.
>
> Any suggestions about how to best do this would be appreciated.  You
> can see the code break by going tohttp://apps.facebook.com/biddinghex
> Then going to play computer, and entering a bid, hit bid - the script
> will crash.
>
> Thank you,
> Jay

Reply via email to