DEV Community

Cover image for Build a Simple Chess AI in JavaScript

Build a Simple Chess AI in JavaScript

Zhang Zeyu on December 20, 2020

Chess is a great game. It’s even better if you’re good at it. Regrettably, I’ve never taken the time to learn chess strategy, so I decided to rely ...
Collapse
 
katsos profile image
Nikos Katsos

var?????

man this is 2020. almost 2021. come on!

cheers

Collapse
 
rockykev profile image
Rocky Kev • Edited

I've taken Kyle Simpson's (Of You Don't Know JS) course and he has a lot to say about var vs let/const. I don't agree with his thoughts, but it did gave me pause.

His stance is that he uses var pretty often and the problems people actually had versus what TC39's specified isn't solving the real problems.

Again, I'm not super in agreement. But I definitely jumped off the bandwagon of declaring var as evil, and everything should be let/const. I wish I could find a public blog post where he articulates it better. But it's one (of his many) frontend master courses where he goes on that rant.

Collapse
 
katsos profile image
Nikos Katsos

I'm working in the industry for 8+ years, writing frontend & backend javascript every day - all day since I've been taught.
I cannot mention enough how evil & unpredictable var can be. Especially if your team has a junior or two, it is guaranteed that var will lead you to problems.

I recommend you to replace them. Scoped variables are your friends.
If you insist to use var, I'm gonna tell you "I told ya"

Thread Thread
 
rockykev profile image
Rocky Kev

I'm not disagreeing with you. And I can point to my industry experience as well if you want to go there. I'm simply sharing a perspective that made me reconsider my own stance.

And again, I disagree with a lot of his perspectives - but this one was something that made me ponder. Kyle Simpson also points out the reasoning for why he came about that, and I wish I could find the spot in his lecture. It was a fascinating perspective to say the least.

Collapse
 
niubo profile image
Rolando Niubo

LOL

Collapse
 
madza profile image
Madza

This is awesome and well written 😉
Next up: Go 👀

Collapse
 
blankfella profile image
blank

Maybe a rewrite in Go lang for faster results :D

Collapse
 
xavortm profile image
Alex Dimitrov

Yeaaaah, about that :D

Collapse
 
ryanphpjs profile image
Ryan Matheus

One implementation that I would use to further improve the evaluation is instead of randomizing the moves is arranging them intelligently, in general, moves of pieces with higher values are better, as well as moves that give checks, arranging this could improve even more the execution

Collapse
 
jeffprod profile image
JeffProd

Good explanations.
But, I think that as the king can't be taken (the game is over on the previsous move), there is no need to set a high score for the piece. If you set it to 0 it is the same.

Collapse
 
promikecoder2020 profile image
ProMikeCoder2020

He has to so the AI minimax algorithm prioritizes the king

Collapse
 
pmgysel profile image
Philipp Gysel

epic🙌

Collapse
 
jeffchavez_dev profile image
Jeff Chavez

Awesome!

Collapse
 
nechoor profile image
nechoor

Good... Thank you

Collapse
 
anabii99 profile image
anabii99

learning a lot!, thank you