lundi 9 mai 2016

strategy/pattern to create working chain

I need a pattern/strategie to solve my problem. Do you know some book or something where I could read it up?

My problem (all theory): I have some kind of game and there I have 2 NPCs. They are workers, that have to repair some stuff. For that they need different materials depending on the error. When an error comes in I calculate which NPC would be the fastest. To do that I calculate for each NPC every move the NPC would have to take (walking, waiting,...). Workers could also be occupied for some time with another task, so I also have to consider that in my calculation.

Now my thoght was I could use the same code (with little modification) to let the NPC walk after I decided which one would fit best for that task, but in my eyes that's a huge redundancy and I would like to avoid that. Also I would have to stop some tasks midway and let the NPC go work somewhere else. Don't think that would be easy to handle this way.

So my second thought was to create something like a working chain. In my time calculation I already decide what the NPC would have to to/where to walk. So I could, at this point, add something that writes that action into a list. A loop would execute the actions and it would be easy to stop at any point. (Of course I would have two lists after each calculation, one for each NPC. But only the fastest would be used.)

If there is a pattern or something alike someone came up with, I would appreciate if you could point me to that source.

Or is there even a better way to solve that?

-Regards

Aucun commentaire:

Enregistrer un commentaire