Setup a javascript engine in a GUI

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

Moderators: hgm, Rebel, chrisw

Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Setup a javascript engine in a GUI

Post by Ferdy »

How do you setup a javascript engine in a GUI like winboard and cutechess on windows? For example this wukong javascript?

I can only setup that engine in Arena using a batch file on windows.

wukong.bat

Code: Select all

node uci.js
Then install wukong.bat as an engine.
tmokonen
Posts: 1296
Joined: Sun Mar 12, 2006 6:46 pm
Location: Kelowna
Full name: Tony Mokonen

Re: Setup a javascript engine in a GUI

Post by tmokonen »

In the CuteChess GUI, I put the program name, with full path, and command line parameters all together in the Command: section of the Configure Engine screen. You might need quotes around the program path or javascript file path if there are spaces. It's the same format as you would use from a command prompt. For example:

C:\Games\NoSpaces\NoQuotesRequired\node.exe C:\jsengines\coolengine.js

"C:\path with spaces\node.exe" C:\jsengines\wukong.js

C:\Games\NoSpaces\NoQuotesRequired\node.exe "C:\jsengines\This time I have spaces.js"
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Setup a javascript engine in a GUI

Post by hgm »

What works from the command line should work in the GUI. It is just that, as far as the GUI is concerned, node.exe is the engine, and the .js file and possibly other arguments that would be needed to make nodejs run the engine, have to be given as parameters to the engine command.

Spaces in filenames are a problem, as they lead to ambiguity to what is the executable and what are commands; the Windows command-prompt interpreter solves this by trying all possibilities. But WinBoard doesn't, and needs quotes to indicate which space-containing groups of characters have to be considered as a single word. The Load Engine dialog should automatically apply quotes when the executable pathname needs them, but it cannot know whether quotes are needed in the engine parameters. WinBoard support 3 levels of quoting, (with single or double quotes, or surrounding {braces}). so that you can have quotes within quotes. Which is good, because the entire engine command has to be passed as a string to the -fcp / -scp options. And these options are stored in the engine list, which is itself a parameter to a string option, surrounded by braces. So if these contain spaces (because they consist of executable + parameters) that needs one extra outer level of quoting. Nota that quotes within a quoted string can be 'escaped' by preceding them with a backslash, when WinBoard interprets such a string.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Setup a javascript engine in a GUI

Post by Ferdy »

tmokonen wrote: Thu Dec 24, 2020 8:56 am In the CuteChess GUI, I put the program name, with full path, and command line parameters all together in the Command: section of the Configure Engine screen. You might need quotes around the program path or javascript file path if there are spaces. It's the same format as you would use from a command prompt. For example:

C:\Games\NoSpaces\NoQuotesRequired\node.exe C:\jsengines\coolengine.js

"C:\path with spaces\node.exe" C:\jsengines\wukong.js

C:\Games\NoSpaces\NoQuotesRequired\node.exe "C:\jsengines\This time I have spaces.js"
Tried the following in cutechess GUI but does not work.

(1)

Image


(2)

Image
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Setup a javascript engine in a GUI

Post by Ferdy »

hgm wrote: Thu Dec 24, 2020 9:11 am What works from the command line should work in the GUI. It is just that, as far as the GUI is concerned, node.exe is the engine, and the .js file and possibly other arguments that would be needed to make nodejs run the engine, have to be given as parameters to the engine command.

Spaces in filenames are a problem, as they lead to ambiguity to what is the executable and what are commands; the Windows command-prompt interpreter solves this by trying all possibilities. But WinBoard doesn't, and needs quotes to indicate which space-containing groups of characters have to be considered as a single word. The Load Engine dialog should automatically apply quotes when the executable pathname needs them, but it cannot know whether quotes are needed in the engine parameters. WinBoard support 3 levels of quoting, (with single or double quotes, or surrounding {braces}). so that you can have quotes within quotes. Which is good, because the entire engine command has to be passed as a string to the -fcp / -scp options. And these options are stored in the engine list, which is itself a parameter to a string option, surrounded by braces. So if these contain spaces (because they consist of executable + parameters) that needs one extra outer level of quoting. Nota that quotes within a quoted string can be 'escaped' by preceding them with a backslash, when WinBoard interprets such a string.
This is what I tried so far without success.

wukong.js and uci.js are in F:\Tmp folder.

(1)
Image


(2)
Double quotes are inside the single quotes.
Image


(3)
Image
User avatar
Guenther
Posts: 4607
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Setup a javascript engine in a GUI

Post by Guenther »

Ferdy wrote: Thu Dec 24, 2020 10:54 am
hgm wrote: Thu Dec 24, 2020 9:11 am What works from the command line should work in the GUI. It is just that, as far as the GUI is concerned, node.exe is the engine, and the .js file and possibly other arguments that would be needed to make nodejs run the engine, have to be given as parameters to the engine command.

Spaces in filenames are a problem, as they lead to ambiguity to what is the executable and what are commands; the Windows command-prompt interpreter solves this by trying all possibilities. But WinBoard doesn't, and needs quotes to indicate which space-containing groups of characters have to be considered as a single word. The Load Engine dialog should automatically apply quotes when the executable pathname needs them, but it cannot know whether quotes are needed in the engine parameters. WinBoard support 3 levels of quoting, (with single or double quotes, or surrounding {braces}). so that you can have quotes within quotes. Which is good, because the entire engine command has to be passed as a string to the -fcp / -scp options. And these options are stored in the engine list, which is itself a parameter to a string option, surrounded by braces. So if these contain spaces (because they consist of executable + parameters) that needs one extra outer level of quoting. Nota that quotes within a quoted string can be 'escaped' by preceding them with a backslash, when WinBoard interprets such a string.
...
I never tried this directly, because setting up via Polyglot/Inbetween is more comfortable for me and allows some automatic
batch processes done in renaming and creating of hundreds of folders and entries at once for my engines.json.

I noticed though that it won't work here too, but the reason is a node.js incompatibility.
If I try my old one (Node 5.0.0) I get this:

Code: Select all

1608805123.071 Engine->Adapter: C:\Engines\UCIJS\WukongJS_10-64\uci.js:10
1608805123.072 Engine->Adapter: const { Engine } = require('./wukong.js');  
1608805123.072 Engine->Adapter:       ^
1608805123.072 Engine->Adapter: 
1608805123.072 Engine->Adapter: SyntaxError: Unexpected token {
1608805123.072 Engine->Adapter:     at exports.runInThisContext (vm.js:53:16)
1608805123.072 Engine->Adapter:     at Module._compile (module.js:404:25)
1608805123.072 Engine->Adapter:     at Object.Module._extensions..js (module.js:432:10)
1608805123.072 Engine->Adapter:     at Module.load (module.js:356:32)
1608805123.072 Engine->Adapter:     at Function.Module._load (module.js:311:12)
1608805123.072 Engine->Adapter:     at Function.Module.runMain (module.js:457:10)
1608805123.072 Engine->Adapter:     at startup (node.js:136:18)
1608805123.072 Engine->Adapter:     at node.js:972:3
1608805123.076 Engine->Adapter: EOF
If I use the current node (15.x.x) it says my Win version is incompatible and at least Win 8.1 is needed.

Code: Select all

1608805368.682 Adapter->Engine: uci
1608805368.874 Engine->Adapter: Node.js is only supported on Windows 8.1, Windows Server 2012 R2, or higher.
1608805368.875 Engine->Adapter: Setting the NODE_SKIP_PLATFORM_CHECK environment variable to 1 skips this
1608805368.876 Engine->Adapter: check, but Node.js might not execute correctly. Any issues encountered on
1608805368.880 Engine->Adapter: EOF
and I have not yet tried the suggested solution above with setting an environment variable...
https://rwbc-chess.de

trollwatch:
Talkchess nowadays is a joke - it is full of trolls/idiots/people stuck in the pleistocene > 80% of the posts fall into this category...
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Setup a javascript engine in a GUI

Post by hgm »

Ferdy wrote: Thu Dec 24, 2020 10:54 amThis is what I tried so far without success.

wukong.js and uci.js are in F:\Tmp folder.
You should let WinBoard worry about the quoting, and you should not put any command-line arguments in the text entry meant for the executable. The latter should go into the 'command-line parameters' entry. The .exe entry is only for the executable; if there are any spaces in there, WinBoard will assume it is an executable name with spaces in it. Writing quotes in there yourself will just confuse WinBoard; when you use the 'browse' button to point out the .exe it wouldn't provide any quotes either.

So the .exe field should just contain

C:/Program Files/blabla/nodes.exe

and the command-line parameter should be

uci.js

This should result in a line in the engine list

"nodes.exe uci.js" -fd "C:/Program Files/blabla"

If you don't want the engine to run in the nodes.exe folder (e.g. because it cannot find its book files from there), you should explicitly provide the directory (there also is a browse button for that), and WinBoard will use that as -fd argument, and refrain from spliiting off the path from the engine command. In that case it should produce a line in the engine list like

'"C:/Program Files/blabla/nodes.exe" uci.js' -fd "whatever"
User avatar
Guenther
Posts: 4607
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Setup a javascript engine in a GUI

Post by Guenther »

Guenther wrote: Thu Dec 24, 2020 11:22 am ...
I never tried this directly, because setting up via Polyglot/Inbetween is more comfortable for me and allows some automatic
batch processes done in renaming and creating of hundreds of folders and entries at once for my engines.json.

I noticed though that it won't work here too, but the reason is a node.js incompatibility.
If I try my old one (Node 5.0.0) I get this:

Code: Select all

1608805123.071 Engine->Adapter: C:\Engines\UCIJS\WukongJS_10-64\uci.js:10
1608805123.072 Engine->Adapter: const { Engine } = require('./wukong.js');  
1608805123.072 Engine->Adapter:       ^
1608805123.072 Engine->Adapter: 
1608805123.072 Engine->Adapter: SyntaxError: Unexpected token {
1608805123.072 Engine->Adapter:     at exports.runInThisContext (vm.js:53:16)
1608805123.072 Engine->Adapter:     at Module._compile (module.js:404:25)
1608805123.072 Engine->Adapter:     at Object.Module._extensions..js (module.js:432:10)
1608805123.072 Engine->Adapter:     at Module.load (module.js:356:32)
1608805123.072 Engine->Adapter:     at Function.Module._load (module.js:311:12)
1608805123.072 Engine->Adapter:     at Function.Module.runMain (module.js:457:10)
1608805123.072 Engine->Adapter:     at startup (node.js:136:18)
1608805123.072 Engine->Adapter:     at node.js:972:3
1608805123.076 Engine->Adapter: EOF
If I use the current node (15.x.x) it says my Win version is incompatible and at least Win 8.1 is needed.

Code: Select all

1608805368.682 Adapter->Engine: uci
1608805368.874 Engine->Adapter: Node.js is only supported on Windows 8.1, Windows Server 2012 R2, or higher.
1608805368.875 Engine->Adapter: Setting the NODE_SKIP_PLATFORM_CHECK environment variable to 1 skips this
1608805368.876 Engine->Adapter: check, but Node.js might not execute correctly. Any issues encountered on
1608805368.880 Engine->Adapter: EOF
and I have not yet tried the suggested solution above with setting an environment variable...
I tried now with Node 9.0.0 and Node 11.0.0
Finally there is some reaction, but nothing happens after this - no commands are sent and no commands are received anymore
after the engine told its name.

Code: Select all

1608810214.537 Adapter->Engine: uci
1608810214.727 Engine->Adapter: 
1608810214.727 Engine->Adapter:   Wukong JS - UCI mode - v1.0
1608810214.727 Engine->Adapter: 
1608810214.727 Engine->Adapter: 
1608810214.737 Engine->Adapter: id name WukongJS 1.0
1608810214.737 Engine->Adapter: id author Code Monkey King
I guess this is because of the further indirection 'node => uci.js => wukong.js'
I would be surprised, if anyone got it working in a GUI except the author(?) for now

Note that I have been running all other JS engines since the beginning w/o problems
https://rwbc-chess.de

trollwatch:
Talkchess nowadays is a joke - it is full of trolls/idiots/people stuck in the pleistocene > 80% of the posts fall into this category...
User avatar
Guenther
Posts: 4607
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Setup a javascript engine in a GUI

Post by Guenther »

hgm wrote: Thu Dec 24, 2020 12:41 pm
Ferdy wrote: Thu Dec 24, 2020 10:54 amThis is what I tried so far without success.

wukong.js and uci.js are in F:\Tmp folder.
You should let WinBoard worry about the quoting, and you should not put any command-line arguments in the text entry meant for the executable. The latter should go into the 'command-line parameters' entry. The .exe entry is only for the executable; if there are any spaces in there, WinBoard will assume it is an executable name with spaces in it. Writing quotes in there yourself will just confuse WinBoard; when you use the 'browse' button to point out the .exe it wouldn't provide any quotes either.

So the .exe field should just contain

C:/Program Files/blabla/nodes.exe

and the command-line parameter should be

uci.js

This should result in a line in the engine list

"nodes.exe uci.js" -fd "C:/Program Files/blabla"

If you don't want the engine to run in the nodes.exe folder (e.g. because it cannot find its book files from there), you should explicitly provide the directory (there also is a browse button for that), and WinBoard will use that as -fd argument, and refrain from spliiting off the path from the engine command. In that case it should produce a line in the engine list like

'"C:/Program Files/blabla/nodes.exe" uci.js' -fd "whatever"
In WB now w/o Polyglot - Wukong10JS-64 is just a renamed node
The debug is not very helpful - it doesn't work, neither in CuteChess nor from cmd with Polyglot (for logging) nor with WB so far
(seems a problem with node - crashing/not responsive)

Code: Select all

recognized 'normal' (-1) as variant normal
recognized 'normal' (-1) as variant normal
shuffleOpenings = 0
Version: WinBoard 4.9.1 + Wukong10JS-64
Reset(1, 0) from gameMode 0
recognized 'normal' (-1) as variant normal
GameEnds(0, (null), 2)
shuffleOpenings = 0
StartChildProcess (dir="") UCI2WB Wukong10JS-64 uci.js C:\Engines\UCIJS\Wukong_10JS-64
nice engine proc to 10
1200 >first : xboard
protover 2
1230 <first : Wukong10JS-64: No error
Terminating process 4176, result=0
GameEnds(29, xboard exit, 2)
EDIT:
BTW can we change the title of the original header to Wukong JS instead of general JS engines ?
Other JS engines never had these problems and the current title will confuse other users
https://rwbc-chess.de

trollwatch:
Talkchess nowadays is a joke - it is full of trolls/idiots/people stuck in the pleistocene > 80% of the posts fall into this category...
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Setup a javascript engine in a GUI

Post by Ferdy »

tmokonen wrote: Thu Dec 24, 2020 8:56 am In the CuteChess GUI, I put the program name, with full path, and command line parameters all together in the Command: section of the Configure Engine screen. You might need quotes around the program path or javascript file path if there are spaces. It's the same format as you would use from a command prompt. For example:

C:\Games\NoSpaces\NoQuotesRequired\node.exe C:\jsengines\coolengine.js

"C:\path with spaces\node.exe" C:\jsengines\wukong.js

C:\Games\NoSpaces\NoQuotesRequired\node.exe "C:\jsengines\This time I have spaces.js"
There is a bug in uci.js, the engine does not send uciok as last message after receiving uci command.

Fixing it and the following would work.

Image