2013-08-29 22 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 } 
}