user746461
user746461

Reputation:

How to simplify complicate conditional statement by Math knowledge

I have a complicated business logic and I believe boolean algebra that sort of things should have the ability to simplify the logic. Can anyone tell me how to do it by solving the following problem?

The problem comes from a game X3: Reunion. Here is the universe map, if helps.

In the universe there are sectors linked together by warp gates. To go from one sector to another, you can fly there or jump there (which is more fast). If you jump to another sector, you should make sure there is not too crowd near the warp gate (otherwise you will crash to other people). You must have jump device and enough energy in order to jump.

There are some isolated sectors that can only be reached by jumping.

The question is that given a ship and its current sector and destination sector, determine how the ship should get to the sector (by jumping or flying). Plus, if the two sectors are adjacent, don't bother to jump.

Let's set:

a: two sectors are adjacent
b: have jump device and enough energy
c: destination sector is not isolated
d: not too crowd near the gate of the destination

if(!a && b && d) 
  jump now
end

if(!a && b && !d)
  can jump but wait until there is not too crowd near the gate of the destination. 
  Should recheck before the jump, because the ship may be losing the energy
  that makes it not enough to jump.
end

if(!b && c)
  fly to destination
end

Can you convert the above if-end statements to if-else if-...else-end statement? And I'd like to know what does the final "else" means. I need not only the result but also the procedure that approaches the result.

Thanks a lot!

Upvotes: 0

Views: 186

Answers (1)

John3136
John3136

Reputation: 29266

Your first 2 conditions both rely on !a && b, and so the difference between them is determined by the value of d. The last condition just depends on !b && c

I'd do it like this:

if (!b && c) { fly }
else if (!a && b) {
    if (d) { jump now } else { wait }
}

Or you could base it on 'b' first:

if (b) {
    if (!a) {
        if (d) { jump now } else { wait }
    }
}
else {
    if (c) { fly }
}

Upvotes: 0

Related Questions