davidrmiller / biosim4

Biological evolution simulator
Other
3.1k stars 435 forks source link

ensure sensorVal in SIM_FWD; cast as float #21

Closed venzen closed 2 years ago

venzen commented 2 years ago

Two code changes in lines 354-357 and on line 368. The second change fixes #20.

As per the comment for case GENETIC_SIM_FWD

        case Sensor::GENETIC_SIM_FWD:
        {
            // Return minimum sensor value if nobody is alive in the forward adjacent location,
            // else returns a similarity match in the sensor range 0.0..1.0
            Coord loc2 = loc + lastMoveDir;
            if (grid.isInBounds(loc2) && grid.isOccupiedAt(loc2))
            {
                const Indiv &indiv2 = peeps.getIndiv(loc2);
                if (indiv2.alive)
                {

an else condition is added to ensure sensorVal = 0.0 // minimum if indiv2.alive == false.

The other code change is an oddity - perhaps simply the way C++ handles types... Changing the following console output type for sensorVal from int to float eliminates the error output reported in issue #20:

std::cout << "sensorVal=" << (int)sensorVal << " for " << sensorName((Sensor)sensorNum) << std::endl;

There are a lot of "changes"marked in red, below. My dev app VS Code automatically changed the entire file's indentation. If this is not acceptable then I can turn off this VS Code behavior and create a new PR.

venzen commented 2 years ago

This PR can be closed. Initializing sensorVal as per David's latest commit resolves the issue.