Fox Forge
Fox Forge

Reputation: 57

Simple 2 Boolean Efficiency

Just a quick one guys - y'know when your brain hurts just looking at something. Just seeing if there is a "better" way to do this in terms of boolean logic.

private RegenerationType AccquireRegenerationState (int floor, int playerFloor)
{
    bool entranceExists = (floorBlocks[floor].doorBlocks.Count != 0) ? true : false;

    if (floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited)
    {
        if (entranceExists)
        {
            return RegenerationType.Still;
        }
        else
        {
            return RegenerationType.Limit;
        }
    }
    else
    {
        if (entranceExists)
        {
            return RegenerationType.Prime;
        }
        else
        {
            return RegenerationType.Full;
        }
    }
}

Upvotes: 0

Views: 102

Answers (2)

Timothy Ghanem
Timothy Ghanem

Reputation: 1616

I guess that's the best you can achieve. Of course, assuming that you maintain code readability and clearness:

private RegenerationType AccquireRegenerationState (int floor, int playerFloor)
{
    var entranceExists = floorBlocks[floor].doorBlocks.Count != 0;

    var whatever = floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited;

    if (whatever)
    {
        return entranceExists ? RegenerationType.Still : RegenerationType.Limit;
    }
    else
    {
        return entranceExists ? RegenerationType.Prime : RegenerationType.Full;
    }
}

Upvotes: 3

AlexD
AlexD

Reputation: 32576

bool entranceExists = (floorBlocks[floor].doorBlocks.Count != 0);
return
    (floor + 1 == playerFloor || !floorBlocks[floor + 1].isVisited)?
    (entranceExists? RegenerationType.Still: RegenerationType.Limit):
    (entranceExists? RegenerationType.Prime: RegenerationType.Full); 

Upvotes: 2

Related Questions