logoalt Hacker News

gabesullicetoday at 12:53 PM0 repliesview on HN

One of my favorite projects that I ever worked on was an project that is really reminiscent of this. The project was to create a browser-based educational tangram[1] puzzle game for kids. It was filled with neat mathematical challenges like how to implement "snapping" between puzzle pieces. The most interesting was how to detect when a puzzle was "complete" or "incorrect" since there can be multiple valid solutions (and I didn't want to find them all) and the library had to accommodate the addition of new puzzles, meaning the approach had to be generic.

We ended up with some rules like "all puzzle pieces must be adjacent to another puzzle piece", "no puzzle piece may overlap another puzzle piece", and "all puzzle pieces must overlap the silhouette" (the puzzle goal), and "no piece may partially overlap the silhouette".

I didn't really know how to detect "overlap" reliably so I ended up implementing some heuristic methods. I remember tearing my hair out over the way JavaScript numbers worked and figuring out how to reliably compare floating point numbers. Good times.

The github repo for the library is still around. Last commit... 9 years ago, woof, time flies! And of course one of the last commits is "Fix overlap bug". Figures.

[1] https://en.wikipedia.org/wiki/Tangram [2] https://github.com/gabesullice/libshapes