JSUCI 1.0 - connect javascript chess engines to UCI

Discussion of anything and everything relating to chess playing software and machines.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Edmund
Posts: 668
Joined: Mon Dec 03, 2007 2:01 pm
Location: Barcelona, Spain
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by Edmund » Sun Apr 06, 2014 10:19 pm

op12no2 wrote:Thanks for the update. If only V8 workers could fire up sub-workers, there would be no problem.

I was wondering if the engine could listen on an event handler (like it would with browsers) without a worker, allowing the engine to fire off a worker, but jsUCI would have to poll for comms(?) and it's all a but ugly perhaps.
The worker commands onmessage and postmessage I personally emulated through programming the corresponding event handlers in C++. How I get it, workers don't exist in V8 and would have to be implemented through 3rd party plugins. Here is the response I got on my question on whether web workers were feasable: http://stackoverflow.com/questions/2277 ... ipt-engine

The same way how I programmed the event handlers one could also add a command for spawning workers, but this is obviously more complex than the commands obove.

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Mon Apr 07, 2014 6:37 am

Ah I see - I think. I had assumed workers were part of the javascript EMCA spec. But googling, they seem to be a web thing not a JS thing - as you say; which makes everything more complicated...

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Sat May 17, 2014 9:34 am

Hi Edmund,

node.js boasts non-blocking I/O so I'm going to have a fiddle with that as well. There are also third-party utils to convert into a single exe.

I am still currently using jsuci to test Lozza; it has been essential to allow me to test against other engines; thank you so much.

Edmund
Posts: 668
Joined: Mon Dec 03, 2007 2:01 pm
Location: Barcelona, Spain
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by Edmund » Mon May 19, 2014 7:58 am

op12no2 wrote:Hi Edmund,

node.js boasts non-blocking I/O so I'm going to have a fiddle with that as well. There are also third-party utils to convert into a single exe.

I am still currently using jsuci to test Lozza; it has been essential to allow me to test against other engines; thank you so much.
Hello Colin

Indeed, node.js might provide a solution. I didn't manage to set it up though. Do you think it can be used to create a similar interface such as JSUCI, with the difference of allowing for web workers?

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Mon May 19, 2014 9:57 am

Hi Edmund,
Edmund wrote:Do you think it can be used to create a similar interface such as JSUCI, with the difference of allowing for web workers?
I think so. AIUI node.js can spawn child processes (the equiv of HTML5 web workers I guess), so while I have not tried it, it should be possible to have a root comms loop like this:-

process.stdin.setEncoding('utf8');

process.stdin.on('readable', function() {
var uciMessage = process.stdin.read();
if (uciMessage !== null) {
... handle UCI message
}
});

Which forks the engine from it, allowing other messages to arrive to control the forked processes. I guess SMP is ultimately possible too. The engine writes back to the UI with process.stdout.write().

I'll get it going single threaded - then add the fork...

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Mon May 19, 2014 12:42 pm

I've got the single threaded version going with one anomaly. From the command line ("node lozza.js"), doing a "go depth 14" say, shows the increasing PVs etc in real time. When using a UI like Arena, that same output is not displayed until the javascript gets back to the message loop. Not really sure why it should be different between the two contexts. That doesn't happen using jsUCI...

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Mon May 19, 2014 4:58 pm

I've given up with node.js :) - not the panacea I thought it was.

What if lastMessage was an exposed function rather than an exposed variable - would that maybe work? or are we back to the same problem?

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Sat Oct 18, 2014 8:11 am

Hi Edmund,

jsUCI often crashes at around move 104. Possible buffer overflow?; at that point the UCI position is "position startpos" + 208*5 ish, which is > 1k. Having said that I looked at the code and could not see anything obvious (to me).

PS: I'm thinking a turning Lozza into a .exe by using the V8 C harness as a starting point but processing std in the C and forking a process with V8 and Lozza. That way the stop and ponder can be handled I think...

Edmund
Posts: 668
Joined: Mon Dec 03, 2007 2:01 pm
Location: Barcelona, Spain
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by Edmund » Sat Oct 18, 2014 2:17 pm

op12no2 wrote:Hi Edmund,

jsUCI often crashes at around move 104. Possible buffer overflow?; at that point the UCI position is "position startpos" + 208*5 ish, which is > 1k. Having said that I looked at the code and could not see anything obvious (to me).

PS: I'm thinking a turning Lozza into a .exe by using the V8 C harness as a starting point but processing std in the C and forking a process with V8 and Lozza. That way the stop and ponder can be handled I think...
Sorry for that bug. I just uploaded a new version with new executable (jsuci 1.2.rar) to the project website.

It was indeed a 1k string variable that I now changed to a 64k string.

Please let me know whether this solves the issue. I wish you all the best with your engine.

op12no2
Posts: 349
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Full name: Colin Jenkins
Contact:

Re: JSUCI 1.0 - connect javascript chess engines to UCI

Post by op12no2 » Sat Oct 18, 2014 2:35 pm

Edmund, you are a super-hero; thank you so much. I can't tell you useful it's been to be able to use jsUCI to evaluate Lozza against other engines in 200 game matches as she slowly develops; thanks again.

PS: There is a little web UI now:-

http://op12no2.me/toys/lozza/play.htm

Post Reply