2013-08-29 23 views
0

我有一個複雜的業務邏輯,我相信布爾代數,應該有能力簡化邏輯的能力。任何人都可以告訴我如何解決以下問題?如何簡化複雜的條件陳述的數學知識

問題來自遊戲X3:團聚。 Here is the universe map,如果有幫助。

在宇宙中,有些扇區通過經向門連接在一起。從一個部門到另一個部門,你可以飛到那裏或跳到那裏(這是更快)。如果你跳到另一個部門,你應該確保經線門附近沒有太多人羣(否則你會撞到其他人)。你必須有跳躍裝置和足夠的能量才能跳躍。

有一些孤立的部門只能通過跳躍到達。

問題是,給定一艘船及其目前的行業和目的地部門,確定船舶應該如何進入該部門(通過跳躍或飛行)。另外,如果兩個部門相鄰,不要費心去跳。

讓我們設置:

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 

您可以將上述如果年底語句的if-else如果-...其他-end語句?我想知道最後的「其他」是什麼意思。我不僅需要結果,還需要接近結果的程序。

非常感謝!

回答

1

您的第一個2條件都依賴!a & & b,所以它們之間的差異由d的值決定。最後一個條件只是依賴於B & &Ç

我會做這樣的:

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

或者你可以將它基於 'B' 第一:

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