1

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:

  1. performing unit - the unit that performs the action
  2. receiving unit(optional) - the unit on witch the action is applied
  3. supported actions - A list of actions that the receiving unit can perform while applying this action on him.
  4. action time - how long does it takes to execute the action

Rules:

  1. Units can only perform one action in a time
  2. 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)

Ilya Gazman
  • 909
  • 3
  • 15
  • 33
  • 2
    What scheduling algorithms have you looked at? Also, Is there a necessary sequence of actions, does one have to be done before the other or can they be done whenever, also what exactly do you mean by associated with? – lPlant Jul 14 '14 at 19:43
  • @lPlant please tell me if my edit clear things up – Ilya Gazman Jul 14 '14 at 19:55
  • 1
    I don't know whether it's a good idea to post two separate different versions of the same question. The problem is that rather than fixing the problems in the older one (the problems that made it vague and unclear), you left it around in a problematic state. It might be better to edit your previous question into an acceptable state. The purpose of this site is to build an archive of high-quality questions and answers that will be useful to others beyond merely yourself, so leaving around old questions in a bad state is not ideal. It might be better to curate your old questions. – D.W. Jul 14 '14 at 23:54
  • 1
    Also, I find this question unclear. What do you mean by "can be associated with"? Is it a symmetric relation? What exactly are the constraints on what actions can be performed simultaneously? If actions 1 and 2 can be associated with each other, is it illegal to perform them simultaneously? legal? does it depend upon some other criteria? (if so, what?) Please try to articulate exactly which sequences of actions are allowed, based upon the properties of the actions; don't force us to infer it. Finally, are there any "happens-before" constraints, where action i must occur before action j? – D.W. Jul 15 '14 at 00:05
  • @D.W. Ok, please tell me if that edit helps. May be you right about that I shouldn't start a new question, I don't know how to fix it now. – Ilya Gazman Jul 15 '14 at 00:20
  • 1
    Please don't edit your question by just adding "Edit: some extra stuff that should have been in the original question" to the end. We have revision control, and all revisions are accessible by clicking on the link under your question; you don't need to mark your edits. Instead, re-write your question to be a well-posed question that is as clear as possible, for someone who has never seen it before, without detritus from previous edits. – D.W. Jul 15 '14 at 00:42
  • 1
    I still don't see a clear, precise specification of which sequences of actions are allowed or not. (Example: you say "When one unit is attacking the other unit need to take damage." So what? How does this affect where that action can appear in the sequence? The question doesn't say; we are forced to guess.) "look as real and logical as possible" is not a well-defined goal. Also, please try to abstract the question. What kind of constraints do you have? "Action x must occur before action y"? (happens-before) "Action x cannot occur in parallel with action y"? (not-simultaneous) Something else? – D.W. Jul 15 '14 at 00:44
  • @D.W. I really been working hard on this one, how about now? – Ilya Gazman Jul 15 '14 at 01:16
  • 1
    I still find this rather unclear. For example, suppose unit A is supposed to attack unit B but unit B is supposed to move. Presumably, the attack fails if B moves first so the order of the actions seems to make a very big difference. – David Richerby Jul 15 '14 at 07:09
  • I edited the question, please review it again – Ilya Gazman Jul 15 '14 at 20:09
  • ilya there are many great game dev books for those starting out & many come with code you can experiment with, some of it probably fairly close to what you are asking about... give it a shot eh? – vzn Jul 15 '14 at 20:47
  • @vzn I am experience game dev, I have more than 5 years of experience and my games seen more than 1,000,000 downloads. I am asking a question here because it's complicate and not trivial. – Ilya Gazman Jul 15 '14 at 20:49
  • lol ok it sounds like basically fairly close to an NP complete optimization problem. essentially you have a lot of constraints about what can occur when and to start it and want to minimize the total overall time (although why you want to do this in the context of the game is not so clear). it sounds to me roughly like a case of MAX-SAT which attempts to maximize clauses satisfied.... it sounds like a hybrid between SAT (some constraints about noninterfering events must be satisfied) and MAX-SAT (try to find as many noninterfering events as possible in the shortest time) – vzn Jul 15 '14 at 20:55
  • there are two chapters on game scheduling in this book Game engine gems vol1 – vzn Jul 15 '14 at 22:25

1 Answers1

2

Your set of rules is self-conflicting. You require

Same unit cannot perform two actions in parallel

but also

When unit perform attack, the interacting unit must perform take damage [...] during the attack-action time of the performing unit.

and

Multiple units can attack single unit at once

In other words, you require that multiple take damage actions be performed simultaneously while demanding that that may not happen.

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • I understand that multiple take damages can be merged together. And probably the same for miss. – Apiwat Chantawibul Jul 15 '14 at 11:47
  • I don't see the conflict here, unit a attacks unit b, while unit b perform take damage. The performing unit a doing one action while the interacting unit b doing one action. The restriction is on the SAME unit. Unit a cannot perform attack and move in the same time. Units a and b can simultaneously attack unit c iff unit c perform take damage. In the same time unit e can attack unit f. Please look again on the definition of performing and interacting units, do I need to edit it? – Ilya Gazman Jul 15 '14 at 12:37
  • I think that you answer should be a comment, you are pointing on halls of the question rather than answering it. – Ilya Gazman Jul 15 '14 at 12:40
  • 1
    @Ilya_Gazman The answer is "it's not possible". (I think you mean "hole"?) This may be because of a fundamental issue with your model, or maybe just because your description of it is lacking. How can we tell? – Raphael Jul 15 '14 at 13:08
  • @Raphael You can tell by asking me in a comment. But can you reply for my first comment. I don't understand the conflict. – Ilya Gazman Jul 15 '14 at 13:48
  • I think the comments of D.W. and David Richerby above apply. – Raphael Jul 15 '14 at 14:36