Hi all,
I'm undertaking a pretty ambitious task in porting Stockfish over to JavaScript. Some may ask, why? Well, it's just an excercise to see how well I can get it to work. I've recently seen how Garbo chess works, and it does play pretty good, I think porting the C++ code to JavaScript can be done with some time consuming work. Also, I will probably find that no direct conversions are available so I'll find a way to get it done. For starters, the rkiss.h does this rand64() function as something like this:
return (x << k) | (x >> (64 - k));
Now, from what I know JavaScript operates only on 32bit when doing bitwise shift operations. If I change it to:
return (x << k) | (x >> (32 - k));
will this work? I mean, nothing blows up but I havent't really gone to far with this yet. I'm giong through the code and trying to fnd areas where I know will be a concern and gettings the mechanics down first.
Thanks,
David
Javascript port of Stockfish
Moderators: hgm, Rebel, chrisw
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
-
- Posts: 568
- Joined: Tue Dec 12, 2006 10:10 am
- Full name: Gary Linscott
Re: Javascript port of Stockfish
I'm the author of Garbochess. I actually did consider doing a relatively straight "port" of an existing engine to Javascript. The big problem is that there is no 64 bit integer type in Javascript. So bitboards end up being implemented as two 32 bit integers. It's certainly doable, but it would be a lot of work.
Anyhow, I'd love to see more strong javascript engines around. So good luck .
Edit: Btw, changing the rotation function like that is not a good idea. RNG's are tested heavily, and small changes to the algorithm can greatly weaken them.
Anyhow, I'd love to see more strong javascript engines around. So good luck .
Edit: Btw, changing the rotation function like that is not a good idea. RNG's are tested heavily, and small changes to the algorithm can greatly weaken them.
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Javascript port of Stockfish
Hi Gary,
Thanks for the reply. Yeah, it's going to be alot of work. I'm going through the C++ code and identifying areas where I know things will be rough and trying to iron those out first before I proceed with anything else. The 64 bit thing will be the hardest part. I didn't take too deep of a look at your code but how did you handle the 64 bit restriction? Did you implement to two 32 bit approach?
Anyways, I'll keep you posted on my progress.
Thanks again,
David
Thanks for the reply. Yeah, it's going to be alot of work. I'm going through the C++ code and identifying areas where I know things will be rough and trying to iron those out first before I proceed with anything else. The 64 bit thing will be the hardest part. I didn't take too deep of a look at your code but how did you handle the 64 bit restriction? Did you implement to two 32 bit approach?
Anyways, I'll keep you posted on my progress.
Thanks again,
David
-
- Posts: 568
- Joined: Tue Dec 12, 2006 10:10 am
- Full name: Gary Linscott
Re: Javascript port of Stockfish
I avoided bit boards entirely actually. It's a real pain to do all the operations manually. You could have wrapper functions, but it will be slow.
-
- Posts: 2554
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
re: PRNG
Hi David,whittenizer wrote:Hi all,
I'm undertaking a pretty ambitious task in porting Stockfish over to JavaScript. Some may ask, why? Well, it's just an excercise to see how well I can get it to work. I've recently seen how Garbo chess works, and it does play pretty good, I think porting the C++ code to JavaScript can be done with some time consuming work. Also, I will probably find that no direct conversions are available so I'll find a way to get it done. For starters, the rkiss.h does this rand64() function as something like this:
return (x << k) | (x >> (64 - k));
Now, from what I know JavaScript operates only on 32bit when doing bitwise shift operations. If I change it to:
return (x << k) | (x >> (32 - k));
will this work? I mean, nothing blows up but I havent't really gone to far with this yet. I'm giong through the code and trying to fnd areas where I know will be a concern and gettings the mechanics down first.
Thanks,
David
I think that PRNG used in StockFish (Bob Jenkins' public domain code) will work well with 32-bit integers (will test tomorrow). The fun part is that the claim that it passes all dieharder tests is false, it's weak in one/more of rgb_lagged_sums. But "p's happen" and I don't think this will have an impact on anything.
I tried to write a small fast PRNG myself (for example Microsoft CRT's default PRNG fails badly even old diehard tests!, too bad i use static tables generated using this flawed rng in my engine), but without success to pass all the tests without any weak p's.
Good luck
Martin
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: re: PRNG
Hi Martin,
Thanks for the reply. Yeah, I'm getting mixed results when changing the 64-k to 32-k. The C++ is pretty intense and needs to be studied a bit more first I think.
Anyways, I'm stubbing out all of the classes to js files, doing all the prototype fun stuff, then I'll come back to this 64/32 bit thing at some point.
Let me know what you find out with your tests.
THanks much
Thanks for the reply. Yeah, I'm getting mixed results when changing the 64-k to 32-k. The C++ is pretty intense and needs to be studied a bit more first I think.
Anyways, I'm stubbing out all of the classes to js files, doing all the prototype fun stuff, then I'll come back to this 64/32 bit thing at some point.
Let me know what you find out with your tests.
THanks much
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: re: PRNG
Hi Martin,
I found a nice link for PRNG's. Alea seems pretty nice with the Mash.js. Have you used this? I may try this and see how it behaves.
http://baagoe.com/en/RandomMusings/java ... x.xml#Alea
Anyways, I'm off to the races.
David
I found a nice link for PRNG's. Alea seems pretty nice with the Mash.js. Have you used this? I may try this and see how it behaves.
http://baagoe.com/en/RandomMusings/java ... x.xml#Alea
Anyways, I'm off to the races.
David
-
- Posts: 2554
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: re: PRNG
Hi David,whittenizer wrote:Hi Martin,
I found a nice link for PRNG's. Alea seems pretty nice with the Mash.js. Have you used this? I may try this and see how it behaves.
http://baagoe.com/en/RandomMusings/java ... x.xml#Alea
Anyways, I'm off to the races.
David
yes I have seen that site. I can test Alea as well though I'm not familiar with JS. I think x | 0 is a trick for fast conversion to integer in javascript?
Basically anything (Alea looks like MWC with state cycling) is better than LCGs.
Martin
-
- Posts: 2554
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: re: PRNG
Hi David,whittenizer wrote:Hi Martin,
Thanks for the reply. Yeah, I'm getting mixed results when changing the 64-k to 32-k. The C++ is pretty intense and needs to be studied a bit more first I think.
Anyways, I'm stubbing out all of the classes to js files, doing all the prototype fun stuff, then I'll come back to this 64/32 bit thing at some point.
Let me know what you find out with your tests.
THanks much
Tests finished and I have to say it performs the same as the 64-bit version in the tests (passes all but two where it's weak, just like its 64-bit counterpart). Replacing 64-k with 32-k won't do however, you have to change the last rotation from 37 to 5 (unless you already have done so).
Martin
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: re: PRNG
Hey,
Yes, x | 0 works in javascript. Anyways, Alea seems to be working for me at the moment as the "init_zobrist" port seems to work just fine. So much more to go.
I'll keep you posted. Thanks for the replys.
Yes, x | 0 works in javascript. Anyways, Alea seems to be working for me at the moment as the "init_zobrist" port seems to work just fine. So much more to go.
I'll keep you posted. Thanks for the replys.