davidrmiller / biosim4

Biological evolution simulator
Other
3.21k stars 460 forks source link

getSignalDensityAlongAxis and getPopulationDensityAlongAxis assertions #90

Open MrSlinkyman opened 1 year ago

MrSlinkyman commented 1 year ago

I saw in a previous issue where these two assertions were added. I'm curious, however, if the program asserts that the direction is not CENTER, how do you prevent creatures from actually using that direction when these sensors are called? https://github.com/davidrmiller/biosim4/blob/33d683248b382d264e28669d6a9751b2e9a7bcd2/src/getSensor.cpp#L22 https://github.com/davidrmiller/biosim4/blob/33d683248b382d264e28669d6a9751b2e9a7bcd2/src/getSensor.cpp#L120

In the getSensor() call I would imagine that the creatures would have a last move direction as CENTER just by chance. https://github.com/davidrmiller/biosim4/blob/33d683248b382d264e28669d6a9751b2e9a7bcd2/src/getSensor.cpp#L311

In my implementation in Java, these assertions are preventing the program from moving forward so I changed them to early returns where the method just returns 0.5 if the direction supplied is CENTER. But I am not sure if that is the right interpretation.

Would love some insight.

davidrmiller commented 1 year ago

From a quick look, I think that the lastMoveDir member variable will not be CENTER because it is initialized to Dir::random8() (which can't be CENTER) and modified only in one place in Peeps::drainMoveQueue(). The lastMoveDir member is only modified there if the individual is alive and if the newLoc grid location is empty, which prevents it from being set on the CENTER location which is where the individual resides.