3 ms·
Spot the fun logic bugs! Here's a great example of where AI requires some careful attention to detail: const tentsFacingNorth = getAllUnitIds() .fi
by Jasper_ 2y ago
Spot the fun logic bugs! Here's a great example of where AI requires some careful attention to detail:
const tentsFacingNorth = getAllUnitIds()
.filter(unitId => getUnitString(unitId, "unitStrings/tags")?.includes("tent"))
.filter(unitId => Math.abs(getUnitRotation(unitId) % (2 * Math.PI)) < 0.01).length;
This code only works if getUnitRotation() returns values between -pi and pi, with north pointing up. This isn't an unheard of convention, but it would surprise me -- if you asked the AI to generate movement code I'm sure it would do const moveX = Math.cos(); for instance.
I would more traditionally expect a range of 0 to 2pi, but then this code wouldn't work for anything close to 2pi on the other side. And if the range was -pi to pi, why have the modulo use 2pi :)
Additionally, "facing north" probably implies a bigger epsilon than 0.01 radians. That's only half a degree! Even if it was super tight, I would expect maybe 10 degrees slop in either direction, which would be 0.17 radians.
The gameplay programmer way to do this would be to get the facing vector and dot that with the vector for north, and compare the results. Dealing with angles isn't worth it.
Oh, also, I'm guessing getUnitString().includes("tent") would work for anything with substring tent, so no adding tentacles to your game.
- wasteduniverse 2y ago[dead]