0
我正在嘗試使用JESS以便利用基於規則的系統來製作機器人。我已經將robocode和JESS .jar導入Eclipse。這裏是我的代碼 -與JESS一起使用robocode的問題
public class myRobot extends Robot {
Rete r = new Rete();
public void run() {
try {
String reset = "(reset)";
r.executeCommand(reset);
String enemyInfo = "(deftemplate enemyInfo (slot present) (slot energy) (slot name))";
r.executeCommand(enemyInfo);
while (true) {
String command = "(assert (enemyInfo (present no) (energy -1) (name none)))";
r.executeCommand(command);
}
} catch (JessException ex) {
System.err.println(ex);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
try {
String command = "(assert (enemyInfo (present yes) (energy " + e.getEnergy() + ") (name " + e.getName() + ")))";
r.executeCommand(command);
} catch (JessException ex) {
System.err.println(ex);
}
}
}
我還沒有添加任何規則,因爲我只是想檢查Robocode和JESS是否正常運行在一起。當我啓動時,robocode應用程序打開。但是當我嘗試在戰鬥中加入這個機器人並開始它時,應用程序就完全凍結了。
我不能訪問機器人控制檯,看看有什麼不對,因爲它在我嘗試並開始戰鬥後立即掛起。由於我所有的System.out.println()調試語句都是打印到機器人的控制檯上,而不是主要的,所以我甚至不知道出了什麼問題。任何建議讓這個工作?
據我所看到的,你有myRobot.run()無限循環,起始於「而(真)」 – laune
@lauune:這是正確的。 robocode機器人是這樣編碼的。所以這沒有什麼問題。 –