An inventory that doesn't fight you
Stacking, limits and the edge cases that bite.
Add an inventory to my game. Items have <describe — name, type, stackable?>. - The data structure, and why that one. - Adding an item when the inventory is full, or partly full for a stack — split it, or refuse it? Say which and be consistent. - Removing a specific quantity across multiple stacks. - Sorting and filtering. - Serialising for a save, in a way that survives me adding new item types later. Handle these explicitly: adding zero, adding more than the stack limit, removing more than I have, and an item type that no longer exists in a loaded save.
The unknown-item-type case matters. Remove an item from your game and every old save containing it must load rather than crash.