【问题标题】:Problems when using robocode with JESS在 JESS 中使用 robocode 时的问题
【发布时间】:2014-05-06 16:32:50
【问题描述】:

我正在尝试使用 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() 调试语句都打印到机器人的控制台而不是主控制台,我什至无法弄清楚出了什么问题。有什么建议可以让它工作吗?

【问题讨论】:

  • 据我所知,myRobot.run() 中有一个无限循环,从“while(true)”开始
  • @lauune:这是正确的。 robocode 机器人就是这样编码的。所以这没有什么问题。

标签: eclipse freeze jess robocode


【解决方案1】:

问题是,robocode 应用程序不知道 JESS 库。您需要将其包含在导出机器人的 jar 中。

How to include librarys to jars

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-27
    • 2017-12-09
    • 2018-11-03
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多