So the past week with Stardance Chess has been rough, like actually rough. Lemme tell.
The Game Broke and I Could Hear Pieces But Not See Them 🥀😭
This was the worst one. I’d start a game, the board would show up, I’d click to move a piece and I could literally hear the sound effect play like the click and everything, but the pieces on screen were just frozen. Like the game was playing itself behind the scenes but the visuals weren’t keeping up ahh thing.
Spent hours on this. Turned out there were two things going on. First, the coordinate system was messed up on high DPI displays. The canvas was rendering at one scale but the click detection was calculating at a different scale. So when I thought I was clicking e4, the game thought I was clicking somewhere totally different. Basically the math for “where did the user click” and “where is the board” were using different units.
Second issue was that the animation system and the audio system had a dependency order problem. The audio manager needed to be created before the animation manager because of how the combo system connects them, but I had them backwards. So the animations were silently failing while audio was fine.
Fixed both by correcting the coordinate passing in main.js and swapping the initialization order.
The Bot Just Stopped Playing, Stockfish would load fine but The bot would just stare at the board forever. No error, no crash, just silence. The problem was in how the Stockfish worker communicates. It uses UCI protocol over a Web Worker, and my code was waiting for a bestmove message to resolve a promise. But there was no timeout. If the worker stalled or the messages got out of order, that promise would just hang forever and the game would be stuck.
Also, if getBestMove got called twice before the first one finished, the second call would overwrite the resolve function of the first one. So the first promise could never resolve.
Added a timeout that force-resolves with null after a reasonable wait, added a request ID counter so only the latest call can resolve, and added error recovery that tries to reinitialize the worker if it dies. Also if Stockfish fails twice in a row, it automatically switches to a fallback bot that just makes random legal moves. The fallback bot is pretty dumb but at least the game doesn’t freeze.
Before when you moved a piece from e2 to e4, the movement was bad like i thought it was good but nuh uhh when i played it looked kinda bad. So i tried to make it like the piece lifts up in an arc like it has actual weight, starts slow then picks up speed then decelerates at the end, does a little squash and stretch at peak velocity, has a shadow underneath that fades as it lifts, dust type trail behind it. It feels like a real piece being picked up and placed down instead of just sliding across the board. The horse had butterish movement but still it needed to look like it was jumping from one square to another so made that better to and also did the same for bishops movement. still need to work on the animations 😭😭 ╰(°▽°)╯
Comments 2
waww
@subhansh thank u
Sign in to join the conversation.