I'll start right with an example:
The game has a bag that players will use to store their items (items have variable sizes), and the bag also has a variable size.
In the bag of 8x15 slots I need to insert an element that occupies 2x2 slots, I can find the space to check if there is enough space to store this element - this is easy, but what if I donโt put on, t there is enough space to store the requested element? This is a real problem.
I am trying to find a way to actually rearrange all the current items in the current bag to make room for the new item.
Is there any algorithm that will help me do this?
EDIT
Rules:
- I cannot delete any of the current items in the bag, just rearrange them to save a new one if there is not enough space.
source share