M
M
Maxim2019-05-12 09:21:28
Algorithms
Maxim, 2019-05-12 09:21:28

How to properly develop the possibility of a variety of characteristics in characters?

Example:
There is a class-character "Kolobok", which we do not control (bot). It has a method (some kind of internal logic) that must make a decision when a subject (s) appears on the horizon: a fox, a wolf, a hare, a bear, as well as their combinations, the number of which is finite. The task is to make sure that each kolobok has a unique character, but at the same time, each of them has the same methods (walk, look, talk, go around, run away). When creating an object Gingerbread Man, you need to somehow determine its nature, on which further actions with other subjects of the game and their combinations will depend. Examples of the variety of koloboks:
- The first one, when a fox appears on the horizon, should run away, when a hare appears, talk to him. His brother (another bot) has a similar character, but when meeting any hero other than a hare or a fox, a random method is triggered.
- At the second kolobok, on the contrary, when a fox appears on the horizon - talk to her (but in case of an attack - run away), when a hare appears - bypass, if the hare moves in his direction - go on a run.
- The third kolobok has a different character - to speak only when all the other characters are nearby, in other cases - to run away.
And this internal logic for each kolobok should be unique and depend on some parameters (character) passed when creating the "Kolobok" object.
For now, I have an idea to create some json structure (kolobok character) and cover it with switch/case, if/else to implement the variability of actions.

[{
  "visionArea": 0, // поле зрения
  "heroesActions": [
    "hero1": "action", // при появлении в поле зрения hero1, поговорить с ним, убежать и т.д.
    "hero2": "action",
  ],
  "multipleHeroesActions": [ // действия, в случае если несколько героев находятся рядом
    {
      "heroes": ["hero1, hero2, hero3"],
      "action": "action"
    },
    {
      "heroes": ["hero4, hero5, hero6"],
      "action": "action"
    },
  ]
}]

I think, in this way, to implement the unique behavior of each kolobok bot. Is it correct? I'm not entirely sure, because, in my opinion, this is all the worst hardcoding. I'm looking for the best way to do it. Maybe there are ready-made methods for developing characteristics for newbie game developers?
And in general, I’m interested in how such a task is called in game development and what is useful to read in order to master such a topic?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rsa97, 2019-05-12
@Rsa97

{
  "parameters": {
    "speed": ...,
    "visionArea": ...,
    ...
  },
  "events": {
    "getSight": [
      {
        "objects": ["fox", "wolf"],
        "actions": [
          {
            "probability": 0.5,
            "action": "run"
          }, {
            "probability": 0.5,
            "action": "wait"
          }
        ]
      }, {
        "objects": ["carrot"],
        "actions": [
          {
            "probability": 1,
            "action": "eat"
          }
        ]
      }
    },
    "hungry": [ ... ],
    "thirsty": [ ... ].
    ...
  }
}

S
stictt, 2019-05-13
@stictt

A very simple design task. You inherit the common features of koloboks from the base class, then by including the class, composition, through upcasts, you turn on the unique logic for the desired living creature. Upcast is a reduction from the particular to the general. You can make 100500 classes, but they implement 1 interface, which has 1 interaction interface, and through type casting, bring any of the 100500 classes to the interface, now without changing the code, you can easily change the logic of the creature, where some of the 100500 classes describes this logic for the kolobok. This approach is very flexible, for example, for another kolobok you want it to eat hares, and keep its distance from foxes, and affa koloboks, or kolobok the main character, implement a unique behavior. All this is possible without changing the logic of the kolobok itself.

V
Vadim, 2019-05-13
@Matmode

Maxim did not try to look towards the strategy design pattern ? Each behavior is a certain strategy, described by the class. The factory will be responsible for creating koloboks, which accepts a character as input and uses a mapper to obtain the necessary behavior strategies for the character.
The strategies themselves can be combined with each other using the decorator design pattern.

D
dollar, 2019-05-12
@dollar

I would do so. Randomize all stats for 100,000 koloboks, then run each one into 100 random situations with wolves and foxes, and see if they survive or not. Then I would leave only those who have a 90% survival rate. I would bring the characters of these lively guys into the database, and during the game I would spawn from the base of a random kolobok.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question