New engine release - Wukong JS

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

Moderators: hgm, Rebel, chrisw

User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New engine release - Wukong JS

Post by mvanthoor »

Dann Corbit wrote: Mon Jan 18, 2021 9:43 pm I looked over the JS language (I have done some Java programming) and I am astonished to learn that it is not even typed.
Writing a chess engine in javascript is like writing one in perl or python.
You're a braver man than I am Gunga Dinn.
If you're writing a chess engine in Javascript AND completing it without a huge amount of bugs, you're either a genius, or incredibly lucky. In my personal opinion, untyped languages shouldn't even have been invented. (It could also be that I'm just too stupid to use them, as I depend on the compiler to weed out things I shouldn't be doing.)

(And yes, I know I just called myself 'stupid' in one of Maksim's threads, the guy whom I told to stop calling himself stupid. Oh, the irony...)
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: New engine release - Wukong JS

Post by maksimKorzh »

mvanthoor wrote: Tue Jan 19, 2021 11:51 am
Dann Corbit wrote: Mon Jan 18, 2021 9:43 pm I looked over the JS language (I have done some Java programming) and I am astonished to learn that it is not even typed.
Writing a chess engine in javascript is like writing one in perl or python.
You're a braver man than I am Gunga Dinn.
If you're writing a chess engine in Javascript AND completing it without a huge amount of bugs, you're either a genius, or incredibly lucky. In my personal opinion, untyped languages shouldn't even have been invented. (It could also be that I'm just too stupid to use them, as I depend on the compiler to weed out things I shouldn't be doing.)

(And yes, I know I just called myself 'stupid' in one of Maksim's threads, the guy whom I told to stop calling himself stupid. Oh, the irony...)
Marcel, you've made my day)))

But what is so genuine in working JS chess engine?
Did you have a look at WukongJS's source?
It's very simple and straightforward.

What's the difference in say array manipulation typed vs untyped?
You just add offset to source square and get target square, no matter how many bits each element takes.
The greatest value for piece code is 12 (black king) and even 8bit integer can hold that but we know that
in JS we have "Number" type which is a double precision 64bit integer - more than enough.

And things like movestack are even simpler to implement compared to C because you can simply .push(move) and .pop() it back
and don't need to care about cleaning memory. Definitely it has some downsides in the performance but one of my subscribers
implemented almost 10x faster movegen just because he's good at optimizing JS code (he didn't use different algorithms).
This helped me to improve my version at least 6x times (his didn't have all the functionality yet, like piece lists, hashes, etc.)
And JS is extremely beneficial if you want to deliver your engine to people willing to play with it!

P.S. Making a product with "bells & whistles" exactly for users to play chess at different levels is my new prior goal now.
I've realized that the vast majority of chess players are 1700-2100 Elo and my engine would be a perfect sparring partner for them.
I still really doubt that I would be able to monetize it one day but at least the youtube community is growing and at very least it opens
some potential opportunities for me as a chess programmer.
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New engine release - Wukong JS

Post by mvanthoor »

maksimKorzh wrote: Tue Jan 19, 2021 4:20 pm Marcel, you've made my day)))

But what is so genuine in working JS chess engine?
Did you have a look at WukongJS's source?
It's very simple and straightforward.
The problem is Javascript. (Or PHP, or Python, or any weak, untyped language). In some of those languages, it's possible for a variable to start out as an array, and end up as an int, being a float and a bool in between. Stuff like that creates subtle and hard to find bugs. If something breaks in Javascript, you often don't get any errors; stuff just stops working and nobody knows why.

My problem is not with Javascript per se; I like Typescript, which is Javascript with types (duh...), and I don't care if a language compiles to Javascript or whatever. (Rust compiles to LLVM's intermediate language, and is then optimized as if the original code was written in C.) I just dislike weakly typed languages, and I utterly hate weakly typed, dynamic languages.
What's the difference in say array manipulation typed vs untyped?
In a weakly typed language, a variable can change type. Lets say, in pseudo-code (non-existing functions, but you get the idea):

Code: Select all

let x = array(); <= x is now an an empty array, obviously.
x = create_some_stuff(); <= here, X is filled up.
x = delete_from_array(x, "bye") <= remove "bye" from X

// Assume "bye" is not in X, thus delete_from_array() returns false (instead of the original array), which doesn't give an error.
// Now... x is false, and it's a bool, not an array.

if (x !== undefined) {
	// X  isn't undefined... it's "false". But it's not what we expected it to be.
	let item = first_item_from_array(x) <= this should be "undefined" if the array is empty, or be x[0], but it crashes because x is no longer an array
	...
}
This makes code very error prone and hard to read.

PHP does similar things. I know... I've ported a massive (older) application recently, to a new platform. I've fixed hundreds of these bugs in the last 10 months.
And things like movestack are even simpler to implement compared to C because you can simply .push(move) and .pop() it back
and don't need to care about cleaning memory. Definitely it has some downsides in the performance but one of my subscribers
implemented almost 10x faster movegen just because he's good at optimizing JS code (he didn't use different algorithms).
This helped me to improve my version at least 6x times (his didn't have all the functionality yet, like piece lists, hashes, etc.)
And JS is extremely beneficial if you want to deliver your engine to people willing to play with it!
Javascript is easy to write, but hard to debug. I prefer the other way around: hard to write, but easy to debug :)

You know why I prefer Rust: because it's strictly and strongly typed, and certainly NOT dynamically typed, so the compiler is able to point out ANY mistake you made, before even compiling. Javascript (and Python, and PHP, etc...) are the complete opposites of Rust.
P.S. Making a product with "bells & whistles" exactly for users to play chess at different levels is my new prior goal now.
I've realized that the vast majority of chess players are 1700-2100 Elo and my engine would be a perfect sparring partner for them.
I still really doubt that I would be able to monetize it one day but at least the youtube community is growing and at very least it opens
some potential opportunities for me as a chess programmer.
At some point, Rustic will also get levels.

Instead of a user interface though, I'll probably lift the DGT-board code from Picochess first, and create a library out of it, so anyone can create a chess program / GUI to talk to a DGT-board. Now it's written in Python, and *IT DOESN'T RUN ON WINDOWS*. Not that I love Windows like nothing else, but if I write software, I don't want to instantly alienate like 80% of the potential users.

Rustic cleanly compiles on Windows, Linux (x64 and the Raspberry), and probably on the Mac too. I'd love to have a DGT-library that can do the same, and then write a Rust version of Picochess on top of it. Better yet, I can use my own chess engine/move generator as a backend for that project.

As you can see, I'm writing stuff for me, myself, and I. It's open source, if people want it they can download it (I've provided my own personal Picochess image) and use it however they like, but the first person I'm writing for is me.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: New engine release - Wukong JS

Post by maksimKorzh »

mvanthoor wrote: Tue Jan 19, 2021 7:22 pm
maksimKorzh wrote: Tue Jan 19, 2021 4:20 pm Marcel, you've made my day)))

But what is so genuine in working JS chess engine?
Did you have a look at WukongJS's source?
It's very simple and straightforward.
The problem is Javascript. (Or PHP, or Python, or any weak, untyped language). In some of those languages, it's possible for a variable to start out as an array, and end up as an int, being a float and a bool in between. Stuff like that creates subtle and hard to find bugs. If something breaks in Javascript, you often don't get any errors; stuff just stops working and nobody knows why.

My problem is not with Javascript per se; I like Typescript, which is Javascript with types (duh...), and I don't care if a language compiles to Javascript or whatever. (Rust compiles to LLVM's intermediate language, and is then optimized as if the original code was written in C.) I just dislike weakly typed languages, and I utterly hate weakly typed, dynamic languages.
What's the difference in say array manipulation typed vs untyped?
In a weakly typed language, a variable can change type. Lets say, in pseudo-code (non-existing functions, but you get the idea):

Code: Select all

let x = array(); <= x is now an an empty array, obviously.
x = create_some_stuff(); <= here, X is filled up.
x = delete_from_array(x, "bye") <= remove "bye" from X

// Assume "bye" is not in X, thus delete_from_array() returns false (instead of the original array), which doesn't give an error.
// Now... x is false, and it's a bool, not an array.

if (x !== undefined) {
	// X  isn't undefined... it's "false". But it's not what we expected it to be.
	let item = first_item_from_array(x) <= this should be "undefined" if the array is empty, or be x[0], but it crashes because x is no longer an array
	...
}
This makes code very error prone and hard to read.

PHP does similar things. I know... I've ported a massive (older) application recently, to a new platform. I've fixed hundreds of these bugs in the last 10 months.
And things like movestack are even simpler to implement compared to C because you can simply .push(move) and .pop() it back
and don't need to care about cleaning memory. Definitely it has some downsides in the performance but one of my subscribers
implemented almost 10x faster movegen just because he's good at optimizing JS code (he didn't use different algorithms).
This helped me to improve my version at least 6x times (his didn't have all the functionality yet, like piece lists, hashes, etc.)
And JS is extremely beneficial if you want to deliver your engine to people willing to play with it!
Javascript is easy to write, but hard to debug. I prefer the other way around: hard to write, but easy to debug :)

You know why I prefer Rust: because it's strictly and strongly typed, and certainly NOT dynamically typed, so the compiler is able to point out ANY mistake you made, before even compiling. Javascript (and Python, and PHP, etc...) are the complete opposites of Rust.
P.S. Making a product with "bells & whistles" exactly for users to play chess at different levels is my new prior goal now.
I've realized that the vast majority of chess players are 1700-2100 Elo and my engine would be a perfect sparring partner for them.
I still really doubt that I would be able to monetize it one day but at least the youtube community is growing and at very least it opens
some potential opportunities for me as a chess programmer.
At some point, Rustic will also get levels.

Instead of a user interface though, I'll probably lift the DGT-board code from Picochess first, and create a library out of it, so anyone can create a chess program / GUI to talk to a DGT-board. Now it's written in Python, and *IT DOESN'T RUN ON WINDOWS*. Not that I love Windows like nothing else, but if I write software, I don't want to instantly alienate like 80% of the potential users.

Rustic cleanly compiles on Windows, Linux (x64 and the Raspberry), and probably on the Mac too. I'd love to have a DGT-library that can do the same, and then write a Rust version of Picochess on top of it. Better yet, I can use my own chess engine/move generator as a backend for that project.

As you can see, I'm writing stuff for me, myself, and I. It's open source, if people want it they can download it (I've provided my own personal Picochess image) and use it however they like, but the first person I'm writing for is me.
Thanks for clarifications, Marcel, got your points)
Makes sense.
We're different... I hate Windows with all of my heart (and Type Script and whatever software created or bought by Microsoft, e.g. Skype)

And now a quote for all times:
Weak chess engine should be written in a weakly typed programming language.
- Code Monkey King -
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New engine release - Wukong JS

Post by mvanthoor »

maksimKorzh wrote: Tue Jan 19, 2021 7:30 pm Thanks for clarifications, Marcel, got your points)
Makes sense.
We're different... I hate Windows with all of my heart (and Type Script and whatever software created or bought by Microsoft, e.g. Skype)
Personally I don't "hate" Windows. I just like Linux (or more accurately, Unix) a lot more with regard to configuration, command line and transparency of the operating system. The main reason I stuck with Windows for so long is because I *NEEDED* it to run specific software, and it was easier to use Windows+That Software and do the rest with open source. The other reason is that in Linux, all software and the operating system is interwoven within the distro's repository. I don't like that I have to upgrade half the OS when the browser is updated. And, in Linux, too much stuff breaks all the time, except in Debian Stable (but that is _old_).

However...
- We now have regularly maintained Debian Backports for new kernels and drivers.
- FLATPAK! Whieeeee! Installing apps seperately from the operating system! Finally! (I don't consider Snap, because I dislike Canonical with a passion. Please go practice your Not Invented Here attitude somewhere outside of the Linux / OSS world...)
- There are only three programs I still use under Windows:

1. Capture One (photo RAW editor... no viable alternative in Linux, not even Darktable) + Monitor Calibrator (no possibility for Linux)
2. Fritz 17 (can replace that, probably. I use it for the GUI, not the chess engine.)
3. (Old) games (some of which -could- run on Linux using Wine.)

Therefore I'm thinking about switching to Linux permanently now, with the exception of photo editing and playing old games.
And now a quote for all times:
Weak chess engine should be written in a weakly typed programming language.
- Code Monkey King -
LOL :)
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: New engine release - Wukong JS

Post by maksimKorzh »

By the time of development process I've realized that if I can't make WukongJS very strong then at very least I can provide some
core features needed for chess players. So today I've added download PGN feature - it's compatible with lichess and especially with
ArenaGUI so that not only moves but scores including mating scores, depth and move time are getting stored. Also game can be played
from a specific FEN and it would get reflected in PGN header so Arena gui would adjust the position for you.

Try it now:
https://maksimkorzh.github.io/wukongJS/wukong.html

P.S. Next update would be adding bots/personalities, so that the vast majority of chess players could enjoy winning versus WukongJS
(for now only 2000+ Elo human players have a chance)
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New engine release - Wukong JS

Post by mvanthoor »

Is WukongJS a straight port of Wukong in C?

If not, how did you get it to play at 2000+ ELO; does it have lots of features already?
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: New engine release - Wukong JS

Post by maksimKorzh »

mvanthoor wrote: Fri Jan 22, 2021 11:33 am Is WukongJS a straight port of Wukong in C?

If not, how did you get it to play at 2000+ ELO; does it have lots of features already?
Hi Marcel

I said 2000+ rated humans would be able to bit it, it doesn't mean that it's rated 2000+ the latest development version should be around 1920 Elo.
The latest stable is now getting tested by Sergio Martinez from CCRL and should be only around 1740 Elo - we'll see.
The latest strength improvement is coming from optimizing move generator so it's now around 6x faster (I used JS objects which brought horrific slowdown).

re: features
- it uses all the search optimization techniques BBC used but much better tuned and aligned, also fixed bugs like allowing null move several times in a row and fixed evaluation margins.

The list of used techniques can be found here:
https://github.com/maksimKorzh/wukongJS ... s/SPECS.MD

I've just improved GUI playing experience so now user can:
- play with 4 bots
- download PGN

Try it;)
https://maksimkorzh.github.io/wukongJS/wukong.html

Also I've added statistics gathering so every time someone plays it I know from which part of the planet and which browser.
Obviously it allows to simply aggregate "views".
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: New engine release - Wukong JS

Post by maksimKorzh »

Hi guys, a new version of WukongJS is now available:
https://github.com/maksimKorzh/wukongJS

Direct download:
https://github.com/maksimKorzh/wukongJS ... S_v1.5.zip

What's new:
- 100+ Elo stronger than 1.4 (major movegen optimization) should be around 1900 Elo now
- GUI improvements
- PGN in SAN recording/downloading feature
- 4 "bots" with different own opening books
- board sounds (recorded with a mic on my own!)
- rewritten timing logic in UCI mode
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: New engine release - Wukong JS

Post by Ferdy »

maksimKorzh wrote: Fri Jan 22, 2021 3:05 pm Try it;)
https://maksimkorzh.github.io/wukongJS/wukong.html

Also I've added statistics gathering so every time someone plays it I know from which part of the planet and which browser.
Obviously it allows to simply aggregate "views".
Tried it on lowest level.

[Event "Friendly chess game"]
[Site "https://maksimkorzh.github.io/wukongJS/wukong.html"]
[Date "Sat Jan 23 2021 19:26:42 GMT+0800 (Taipei Standard Time)"]
[White "Ferdy"]
[Black "Baihua"]
[Result "0-1 Mate"]

1. e4 e5 2. d4 {3} Nc6 {(b8c6) -0.6/1 0} 3. Bc4 {3} exd4 {(e5d4) -1.62/1 0} 4. Qf3 {2} Nf6 {(g8f6) -1.77/1 0} 5. Bg5 {5} d6 {(d7d6) -1.73/1 0} 6. Qb3 {2} Ne5 {(c6e5) -1.89/1 0} 7. Be2 {6} Qe7 {(d8e7) -2.04/1 0} 8. Nd2 {2} a5 {(a7a5) -1.69/1 0} 9. a4 {2} Rg8 {(h8g8) -1.75/1 0} 10. f4 {1} Ng6 {(e5g6) -1.8/1 0} 11. Nf3 {2} h6 {(h7h6) -1.41/1 0} 12. Bxf6 {3} Qxf6 {(e7f6) -1.67/1 0} 13. 0-0 {3} Qxf4 {(f6f4) -2.12/1 0} 14. e5 {4} dxe5 {(d6e5) -3.24/1 0} 15. Re1 {4} Bc5 {(f8c5) -3.24/1 0} 16. Kh1 {2} e4 {(e5e4) -3.47/1 0} 17. Nxd4 {2} Qxd2 {(f4d2 b3f7) -4.06/1 0} 18. Qxf7+ {5} Kd8 {(e8d8 f7g8) +0.63/1 0} 19. Qxg8+ {2} Ke7 {(d8e7 g8g7) +1.79/1 0} 20. Qxg7+ {58} Kd8 {(e7d8 g7f6) +1.83/1 0} 21. Nb3 {21} Qxc2 {(d2c2 b3c5 c2c5 g7g6) +3.74/1 0} 22. Nxc5 {16} Qxc5 {(c2c5 g7g6) +3.74/1 0} 23. Rd1+ {2} Ke8 {(d8e8 g7g6) +3.78/1 0} 24. Qxg6+ {4} Ke7 {(e8e7 g6e4) +4.77/1 0} 25. Rf7+ {7} Ke8 {(e7e8 f7c7) +4.9/1 0} 26. Qg8+ {5} Qf8 {(c5f8 g8f8) +12.38/1 0} 27. Qxf8+ {1}

Some comments on pgn format.
* White won the game, but result is 0-1
* Date format should be yyyy.mm.dd or 2021.01.23
That would be:
[Date "2021.01.23"]
* Result format should be 0-1 or 1-0 or 1/2-1/2 or *
Not "0-1 Mate"
You can add however.
[Termination "white checkmates black"]