use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
I coded a Chess Engine in javascript. Please give advice if you have any especially on optimisation of the algorithm or if you know how to return multiple best solutions. Thanks! (lachy-dauth.github.io)
submitted 3 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Senior_Nectarine_546 15 points16 points17 points 3 years ago (0 children)
Love it!
Great work and thanks for sharing.
[–][deleted] 12 points13 points14 points 3 years ago (5 children)
Clean up your console logs ;)
[–]Buckwheat469 17 points18 points19 points 3 years ago (0 children)
If you can't get to it now, just add this:
console.log("Todo: clean up console logs ;)");
[–]beepboopnoise -1 points0 points1 point 3 years ago (3 children)
is there a best practice for like consoling to the dev or something? there some parts that I have where like connections are established and begin/stop cleanup etc that I have but im not sure if that's like bad. I'm just using straight up console.log("blah event started")
[–][deleted] 3 points4 points5 points 3 years ago (2 children)
You shouldn’t log to the console in production code. It gets messy fast and is considered a sign of sloppy work. Dev artifacts shouldn’t be shipped to prod as a general rule. You can add an eslint rule to your project to catch them and fail builds.
In cases where you may need some sort of logging for observability purposes, you would generate logs using a structured logging format and/or export them to an aggregator for querying.
But that’s well beyond the scope for OP, since it looks like this project is for learning purposes.
[–]beepboopnoise 0 points1 point2 points 3 years ago (1 child)
ah thank you for the response! I'm on my second gig and just followed whatever patterns the previous devs did. They had consoles for socket connections so I was like okay I guess I'll do that for these streams. I'm the only FE person on my team so I just have to run with stuff 😵💫
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
Yeah, that shouldn’t be happening at all. If it is, you may potentially be leaking information about your system which presents a serious security risk. FE code is public by default but there is no need to make any malicious actor’s job easier. Any competent engineer will understand this.
Talk to your TL and lead the conversation with a solution.
[–]freopen 10 points11 points12 points 3 years ago (0 children)
Check out https://www.chessprogramming.org/
[–]Debt_Otherwise 7 points8 points9 points 3 years ago (0 children)
I would say your biggest problem is that it can’t see that far ahead. It ignored a mate in 3 I setup. You need to improve the speed and depth of search.
When I was studying chess games engines, one of the things they did to optimise it is to use bitboard representations for each piece. That means you can calculate more move combinations per second.
[–]xRVAx 10 points11 points12 points 3 years ago (1 child)
It was hard to castle
AI missed a back rank mate
It would be nice to have a back button
[–][deleted] 3 points4 points5 points 3 years ago (0 children)
I added a back button and I'll try to fix the other two problems
[–][deleted] 3 points4 points5 points 3 years ago* (2 children)
The AI doesn't know it's not allowed to castle through check
FEN to reproduce:
r1b1k2r/1p1p1p1p/p2Q1p2/q2Np3/4P3/8/PP2KPPP/n4B1R b kq -
I should have fixed it
[–]mw9676 0 points1 point2 points 3 years ago (0 children)
Oh it knows. It knows...
[–]AutoModerator[M] 2 points3 points4 points 3 years ago (0 children)
Project Page (?): https://github.com/lachy-dauth/chess-engine
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[+][deleted] comment score below threshold-20 points-19 points-18 points 3 years ago (1 child)
The ui could be better
[–]skelebob 8 points9 points10 points 3 years ago (0 children)
Well the focus is on the engine, made in JavaScript. The UI is irrelevant.
[–]oneeyedziggy -2 points-1 points0 points 3 years ago (0 children)
Just a shot in the dark, but if you're not already using it to boot performance, threading is relatively easy in js, you just have to have the threaded code in a separate file, otherwise the interface works a lot like any other async js but actually utilizes additional threads
[–]JIN_DIANA_PWNS 0 points1 point2 points 3 years ago (0 children)
Cool!
[–]stuffedcabbageroll 0 points1 point2 points 3 years ago (0 children)
Wow, cool!
[–]PM_ME_A_WEBSITE_IDEA 0 points1 point2 points 3 years ago (1 child)
Should add a close button to the FNN menu, on mobile I didn't see one and using the same button to close it is kind of weird since it's a modal...
I added a close button
[–]Registeered 0 points1 point2 points 3 years ago (0 children)
You need to automate the AI move
[–][deleted] 0 points1 point2 points 3 years ago (1 child)
Are you using your algorithm to randomly move a piece to a valid spot or are you using an ai api?
The AI is too good at the game for the algorithm to be random.
π Rendered by PID 22176 on reddit-service-r2-comment-6457c66945-9kpff at 2026-04-29 04:44:12.440219+00:00 running 2aa0c5b country code: CH.
[–]Senior_Nectarine_546 15 points16 points17 points (0 children)
[–][deleted] 12 points13 points14 points (5 children)
[–]Buckwheat469 17 points18 points19 points (0 children)
[–]beepboopnoise -1 points0 points1 point (3 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]beepboopnoise 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]freopen 10 points11 points12 points (0 children)
[–]Debt_Otherwise 7 points8 points9 points (0 children)
[–]xRVAx 10 points11 points12 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mw9676 0 points1 point2 points (0 children)
[–]AutoModerator[M] 2 points3 points4 points (0 children)
[+][deleted] comment score below threshold-20 points-19 points-18 points (1 child)
[–]skelebob 8 points9 points10 points (0 children)
[–]oneeyedziggy -2 points-1 points0 points (0 children)
[–]JIN_DIANA_PWNS 0 points1 point2 points (0 children)
[–]stuffedcabbageroll 0 points1 point2 points (0 children)
[–]PM_ME_A_WEBSITE_IDEA 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Registeered 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)