我正在尝试使用 JESS 来利用基于规则的系统来制作机器人。我已经将 robocode 和 JESS .jar 都导入了 Eclipse。这是我的代码 -
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() 调试语句都打印到机器人的控制台而不是主控制台,我什至无法弄清楚出了什么问题。有什么建议可以让它工作吗?