-
Notifications
You must be signed in to change notification settings - Fork 164
Description
Consider a custom move which does the following on a problem with list variable:
- Unassign value A from entity X at position Y in the list.
- Unassign value B from entity X at position Y+1 in the list.
This should be simple, but it's not. At the time the move executes this operation, Y and Y+1 are fixed. But when the first unassign happens, the old Y+1 becomes Y. (A was removed from the list, shifting B to where A used to be.) This in turn causes all sorts of ArrayIndexOutOfBounds exceptions.
Before MoveDirector, the user could deal with this manually:
A: Call before() methods
A: Do the unassigning
A: Call after() methods
A: Trigger var listeners
B: Call before() methods
B: Do the unassigning
B: Call after() methods
B: Trigger var listeners
Now that MoveDirector tries to abstract this complexity away, the user only does this:
moveDirector.unassign(A);
moveDirector.unassign(B);
And then eventually, the solver triggers var listeners and calculates score. The internal representation is messed up after A changes, which makes the B change fail. This problem needs solving. We don't want to expose the var listener triggers. We also don't want users to keep their own track of these indexes, or think of this problem at all. So what other options are there?
- Do a manual trigger within each
unassignoperation. Is that possible? Will it work with undo? Is it efficient? - Inside the list var state, shift every index when we read that something was unassigned (and assigned, and moved)? This is possibly a massive slowdown on each such operation.
- Provide a bulk unassign operation, where we take care of this internally?
- Keep an internal representation of these events, aggregate them, and only execute them once before score calculation?
- Something else?
Note: This will affect most (if not all) operations on the list variable. Once a variable is removed from the list, or another added, indexes of other variables are invalidated and keep being invalid until the next var listener trigger.