I am building a strategy game where units can interact with each other.
As input I am getting a list of actions. I need to output a scheduler, that will tell when to start each action. The goal is to find the shortest time combination of all the actions.
Action is defined as interaction between two users or user with him self, it build from 4 parts:
- performing unit - the unit that performs the action
- receiving unit(optional) - the unit on witch the action is applied
- supported actions - A list of actions that the receiving unit can perform while applying this action on him.
- action time - how long does it takes to execute the action
Rules:
- Units can only perform one action in a time
- Units may have to perform more than one action
The best solution will be: Is to run all those actions in parallel. There are two things that stops me from doing it.
If more than one action have the same performing unit, they cannot start simultaneously as units can perform only one action in a time.(Rull 1)
The other problem is actions with receiving unit. I need to make sure that the receiving unit is currently performing one of the supported actions(defined in action part 4), if it's not, this actions cannot be started.
In case of actions without receiving unit, they can all be started simultaneously. How ever I need to make sure that I am not left with action that have a receiving unit, that cannot be started as the receiving unit already performed all his actions.(So supported action will never be started)