You are browsing as a guest. Sign up (or log in) to start making projects!

10h 47m 49s logged

I am trying to make a chess game like not just a boring grid with pieces moving around, but something that actually has WEIGHT and IMPACT when you capture a piece.
So here’s the thing. I started with chess.js for the game logic because honestly why would I write chess rules from scratch when there’s a library that does it perfectly. But the rendering? Pure Canvas 2D. No WebGL. No Three.js. Just me, a element, and a LOT of ctx.drawImage() calls. And yeah it sounds like a bad idea but hear me out — it actually runs at 60fps bruhhhhhhh. It also has an elo system just like standard chess when u win elo rating increases and likewise if u lose it decreases.

So i added stockfish in my game so that people can do a bot verses match with the world’s strongest open-source chess engine. It’s been around forever and it’s insanely good — like stronger than any human who has ever lived. The thing is, it’s written in C++, not JavaScript. So you can’t just drop it into a website or an app and call it a day.
What I did was take the WebAssembly version of Stockfish — that’s basically the C++ code compiled down to something a browser can run. And I stuck it in a Web Worker, which is like a helper thread that runs in the background. So while Stockfish is busy calculating the best move, the rest of the game doesn’t freeze or lag. The player can still see the board, the animations keep running, everything stays smooth.
The fun part is making it feel human. Stockfish at full strength would destroy anyone, so I had to nerf it. It has a built-in “skill level” setting from 0 to 20.

I mapped that to four difficulty levels:

  • Beginner — barely thinks, makes silly moves
  • Intermediate — thinks a little, plays okay
  • Advanced — thinks harder, plays decent
  • Expert — thinks deep, plays strong

For now i have added some animations while capturing and moving the pieces which look like;

  • Pawns have a quick glide with low arc
  • Knights get the “butter” easing with high arc (because they jump)
  • Rooks are heavy and deliberate
  • Kings are the heaviest with the most squash-and-stretch on landing
    But they aren’t smooth and need a hell lot of work if i need to them to look like as i imagine them to look so now i will work on that and make them better as much as I can and until i am satisfied >.
0
6

Comments 0

No comments yet. Be the first!