if條件的語法是完全錯誤的。你想做什麼?您正在混合分配和條件代碼。
你可以做分配是這樣的:
if (chanceDir >= 0.5) {
Dir = IRobot.AHEAD;
Vir = IRobot.BEHIND;
Hir = IRobot.AHEAD;
Sir = IRobot.BEHIND;
} else {
Dir = IRobot.RIGHT;
Vir = IRobot.LEFT;
Hir = IRobot.LEFT;
Sir = IRobot.RIGHT;
}
if (oppchanceDir >= 0.5) {
Dir = IRobot.BEHIND;
Vir = IRobot.AHEAD;
Hir = IRobot.BEHIND;
Sir = IRobot.AHEAD;
}else {
Dir = IRobot.LEFT;
Vir = IRobot.RIGHT;
Hir = IRobot.RIGHT;
Sir = IRobot.LEFT;
}
或者你也可以做檢查的條件類似的:
if (chanceDir >= 0.5 && ((Dir == IRobot.AHEAD) && (Vir == IRobot.BEHIND) && (Hir == IRobot.AHEAD) && (Sir == IRobot.BEHIND))) {
// do something here
}else if((Dir == IRobot.RIGHT) && (Vir == IRobot.LEFT) && (Hir == IRobot.LEFT) && (Sir == IRobot.RIGHT)){
// do something here
}else{
// do something here
}
if (oppchanceDir >= 0.5 && ((Dir == IRobot.BEHIND) && (Vir == IRobot.AHEAD) && (Hir == IRobot.BEHIND) && (Sir == IRobot.AHEAD))) {
// do something here
} else if ((Dir == IRobot.LEFT) && (Vir == IRobot.RIGHT) && (Hir == IRobot.RIGHT) && (Sir == IRobot.LEFT)) {
// do something here
}else{
// do something here
}
它看起來像你想要做的任務,而不是你有一個布爾條件。刪除&&和括號,用分號分隔每個賦值。 – 2014-10-27 22:24:29
你沒有對if/else body的布爾值做任何事情,那就是問題 – engineercoding 2014-10-27 22:24:58
@SteBra你在說什麼循環? – f1sh 2014-10-27 22:25:18