Currently Online

Latest Posts

Topic: Making wild animals reproducible

hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1609
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-24, 16:35

Nordfriese wrote:

EDIT: How about I just make a branch with this (expected effort: <<1h) and then we can test it face-wink.png

I already thought I suggested that. face-wink.png I'll make my mind about a good testscenario in the meantime.

Sorry for the complaints.


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 17:30

Did you? Sorry, must have overlooked it face-sad.png

Compiler is running now. In the meantime I'd appreciate a list for each animal with

  • is it a herbivore and/or carnivore? what exactly does it like to eat?

  • how hungry is it (0-100)

  • how often does it reproduce (0-100)


Top Quote
JanO
Avatar
Joined: 2015-08-02, 11:56
Posts: 164
Ranking
At home in WL-forums
Posted at: 2020-02-24, 18:54

I think it might be easier (or more efficient) to not give each critter a list of what other critters it can consume, but solve this via numbers. Simply give each critter a number related to its size, rabbits are 1 and buffaloes are 10, same for carnivores. If a carnivore meets a herbivore, it can kill it, if h < c+1 (carnivores kill bigger herbivores from time to time, even if they don't eat them completely). Carnivores can kill other carnivores, if they are smaller. Maybe probability of preying can generally be calculated from the difference in size.
Also I think its enough to trigger those interactions only for idle moments of the animals and not when they meet while moving. Coming along with that, I would increase the idle time and the roaming distance. Let the distance increase in areas with many other critters would be nice, too, but would come with quite some more CPU load than the other points (because roaming is triggered more often).
Last suggestion of mine (is similar to king of nowhere's) A carnivore that has lately eaten something might get some "bonus-points" which are reduced via time. Maximum value 2 or 3, reduced by 1 per minute or something like that. The amount of collected points depends on the size of prey (h=c+1 get 3 points, each smaller gets one less). Now if two carnivores meet and at least one of them have valuable points, there is additional reproduction. If both have bonus-points, there even is additional additional reproduction, maximum would be 1+3+3=7 new carnivores.
For the sake of readability, here the same again in a list:

  • only trigger preying & reproducing in idle positions
  • carnivores c, herbivores h
  • who eats whom not per named lists, but by size-indicating numbers from 1 to 10 (also makes it easier to add new species)
  • carnivores can kill herbivores with size h=c+1 and other carnivores with size -1
  • probability of killing depends on difference in size
  • carnivores get bonus-points for their reproduction after preying
  • increase idle time for the roaming-function
  • increase roaming distance and make it dependent on number of nearby other animals

You know what? This could be further developed into a non-military warfare ability at least for barbarians. Is this desired? I mean, we talk about widelands being an economic simulation with only a little bit of soldiers... face-wink.png

Edited: 2020-02-24, 19:48

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 19:51

I have uploaded a branch now: https://github.com/Noordfrees/widelands/tree/clevercritters

The parameters still need tweaking, after fifteen minutes the map is densely populated with carnivores.

For now I hardcoded the prey scheme of every carnivore into the init.lua. I think I'll change it according to JanO's suggestion face-smile.png

P.S. I don't strictly separate carnivores and herbivores – it is perfectly legal to create an omnivore that eats fields as well as animals. Only carnivores that like to eat their own species are forbidden (though this is not a coding necessity…). IMHO it should also be allowed for carnivores to eat much bigger animals though with a very low success rate (perhaps make the probability a 1/(x+m) function shifted so that smaller animals are much more likely?)


Top Quote
JanO
Avatar
Joined: 2015-08-02, 11:56
Posts: 164
Ranking
At home in WL-forums
Posted at: 2020-02-24, 20:16

Good you mention the omnivores yourself - otherwise I had brought them up later face-wink.png
I think big predators don't hunt very small animals. Those tiny things are just to agile and still would leave the successful big carnivore hungry. That's another reason for my suggestion to use numbers for size. We could even do calculations with those. Say, two carnivores c with sizes 3 and 2 idle on one field. A herbivore h with size 7 decides to rest on that field, too. Normally they wouldn't interact, but now the two c could ally together and try to kill the h ( c3+1 + c2+1 = h7).
Do you plan to implement that herbivores delay the crops on fields?


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 20:35

Okay, so I summarize the model:

  • The list of carnivore foods is replaced with a size defined for every animals in arbitrary units (~1-10), and an optional boolean flag carnivore.

  • When a carnivore C enters a field:

    • For every animal P on the field which is of different species than oneself

      • Find other carnivores C1..Cn on the same field which are of a different species than the potential prey

      • Sum up our combined size s(C); the C1..Cn should have their size effects reduced somewhat (e.g. count only half as much) because they merely help C to hunt here

      • Compare with P's size s(P) using a weighting function that looks something like this sigmoid suggestion

      • On success remove P, end loops

carnivores get bonus-points for their reproduction after preying

This would be more difficult, I'd prefer to keep this implementation lightweight

increase idle time for the roaming-function

increase roaming distance and make it dependent on number of nearby other animals

Will do so. What exactly should this dependence be – carnivores like crowds, herbivores like solitude, omnivores unaffected?

Do you plan to implement that herbivores delay the crops on fields?

Yes. I'm not 100% sure if this will work as I intend but I'll try

You know what? This could be further developed into a non-military warfare ability at least for barbarians

I don't really understand, could you explain?

Edited: 2020-02-24, 20:38

Attachment: wl-prey.png (9.0 KB)

Top Quote
JanO
Avatar
Joined: 2015-08-02, 11:56
Posts: 164
Ranking
At home in WL-forums
Posted at: 2020-02-24, 21:36

Nice face-smile.png
Is there a second bool for herbivores? (How do gamekeepers know that they actually are breeding herbivores?)

Nordfriese wrote:

  • The list of carnivore foods is replaced with a size defined for every animals in arbitrary units (~1-10), and an optional boolean flag carnivore.

  • When a carnivore C enters a field:

    • For every animal P on the field which is of different species than oneself

      • Sum up our combined size s(C); the C1..Cn should have their size effects reduced somewhat (e.g. count only half as much) because they merely help C to hunt here

      • On success remove P, end loops

We must be careful here, I guess. Imagine a couple of Ps on the field. Maybe they should ally up as well. Also if two carnivore species show up on one field (imagine lions and hyenas), what happens? Suggestion: As long as there are any Ps, all Cs ally up (species independent, if your current implementation handles that without problems, otherwise the function might be triggered by each carnivore species after each other). If there is no herbivore on the field, carnivores start fighting (should have lower probability to kill each other)

carnivores get bonus-points for their reproduction after preying

This would be more difficult, I'd prefer to keep this implementation lightweight

That's ok. As you observed, your first implementations seems to favour carnivores anyway.

increase idle time for the roaming-function

increase roaming distance and make it dependent on number of nearby other animals

Will do so. What exactly should this dependence be – carnivores like crowds, herbivores like solitude, omnivores unaffected?

I thought the other way round face-wink.png Think of sheep, cows, antilopes, horses... and of almost any other carnivore except lions, hyenas or wolves.
I guess each species should consider three values: Same species, same class (h or c) and other class.

  • default roaming-distance can stay with 2 (or 3 - or species-dependent)
  • Same species get a threshold of x individuals (lets test 4 for a start) within a radius of 2. Below this threshold roaming-distance is not increased. This is for mating
  • Same species get an increase of roaming-distance of 1 per 4 (test value) individuals within radius of 5. The function should simply cut off decimal digits of the calculation. But at the moment I do not have a good idea how to prevent this from interfering with the previous point.
    Also maybe those values can be species-dependent to differ herd- and solitary animals? Probably doesn't make sense, as the positioning of the idle animations do not allow for a real herd-feeling anyway face-wink.png
  • Same class-other-species individuals increase roaming-distance by 1 per 3 individuals within radius of 3 (should have a smaller effect than same species, I guess - except we really differ herd- and solitary animals)
  • Other class: Herbivores increase roaming distance by 1 per 2 predators within radius of 4 (or 3 or species dependent)
  • Other class: Carnivores do not increase distance if potential prey is nerby

Do you plan to implement that herbivores delay the crops on fields?

Yes. I'm not 100% sure if this will work as I intend but I'll try

Consider making it size-dependent, too, please face-wink.png

You know what? This could be further developed into a non-military warfare ability at least for barbarians

I don't really understand, could you explain?

Sure face-smile.png
Just think about some gamekeepers close to the borderline that get two checkboxes for breeding herbivores or carnivores. With some adjustments to the roaming-function and the herbivores delaying crop-production, it would be possible to seriously mess up food production of other players. Close to your own farms you breed some herbivores to protect your own fields. Probably tibor will not like this...

Edited: 2020-02-24, 21:39

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 22:14

Just think about some gamekeepers close to the borderline that get two checkboxes for breeding herbivores or carnivores. With some adjustments to the roaming-function and the herbivores delaying crop-production, it would be possible to seriously mess up food production of other players. Close to your own farms you breed some herbivores to protect your own fields. Probably tibor will not like this...

I like this idea a lot, but this would be a significant impact on game mechanics and might mess up tribe balance which would have to be carefully checked…

Is there a second bool for herbivores?

Carnivores are defined as carnivore = true; herbivores as herbivore = {"field"} (by specifying the attributes they like to eat)

(How do gamekeepers know that they actually are breeding herbivores?)

they don't – their selection range is currently hardcoded as bunny chamois deer elk reindeer sheep stag wildboar wisent in their init.lua. Allowing them to switch between two different lists might be very difficult…

Suggestion: As long as there are any Ps, all Cs ally up (species independent, if your current implementation handles that without problems, otherwise the function might be triggered by each carnivore species after each other). If there is no herbivore on the field, carnivores start fighting (should have lower probability to kill each other)

Okay, can be implemented easily

For the hunting success chance, I implemented a sigmoid curve now. If the combined strength of all animals is equal to the prey's size, the success rate is 50%. If the difference between combined strength and prey size is at least preysize², the chance is 100%. For all other values from -preysize² to max it is interpolated sigmoid with the following completely intuitive and not at all performance-hungry (the latter I'm testing currently… – EDIT: yes, it really has no measurable impact on performance face-tongue.png ) function:

const int32_t S = total_strength / 2 - foodsize; // weighted combined strength *difference*
const int32_t N = foodsize * foodsize; // definition of N: the resulting chance is 1 if and only if S >= N
const double weighted_success_chance = S <= -N ? 0.0 : S >= N ? 1.0 : -(std::log(S * S + 1) - 2 * S * std::atan(S) - M_PI * S -
                                                std::log(N * N + 1) + N * (2 * std::atan(N) - M_PI)) / (2 * N * M_PI);

which produces pretty reasonable chances:

MO(1832,badger): Yummy, a badger loves a bunny...
MO(1832,badger):     *** [total strength 3] vs [prey 1] *** success chance 1,000000
MO(1832,badger):     SUCCESS :)
MO(2918,badger): Yummy, a badger loves a wisent...
MO(2918,badger):     *** [total strength -6] vs [prey 10] *** success chance 0,008941
MO(2918,badger):     failed :(
MO(1983,badger): Yummy, a badger loves a lynx...
MO(1983,badger):     *** [total strength 2] vs [prey 2] *** success chance 0,552880
MO(1983,badger):     failed :(

Will do so. What exactly should this dependence be – carnivores like crowds, herbivores like solitude, omnivores unaffected?

I thought the other way round face-wink.png Think of sheep, cows, antilopes, horses... and of almost any other carnivore except lions, hyenas or wolves.

I guess each species should consider three values: Same species, same class (h or c) and other class.

Wow, you really thought this through face-smile.png Will implement as you said, except that species-dependent behaviour would be overkill imho. Let's have only the three classes herbivores, carnivores, and others.

Do you plan to implement that herbivores delay the crops on fields?

Yes. I'm not 100% sure if this will work as I intend but I'll try

Consider making it size-dependent, too, please face-wink.png

If it works, this will be easy then face-smile.png

Edited: 2020-02-24, 22:15

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 22:22

The birth control system also needs an enhancement, after ten to fifteen minutes the map is getting very crowded…
Current implementation: 2.f / (1.f + population_size_2) + 4.f / (2.f + population_size_5)

By the way here attached is the map I use for testing


Attachment: clevercritterstest.wmf.zip (68.8 KB)

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1089
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-24, 22:24

FYI
the same map after 18 minutes

Edited: 2020-02-24, 22:27

Attachment: shot0000.png (3.7 MB)

Top Quote