Robocode 机器人与 Drools Expert

发布于 2024-11-19 18:22:49 字数 1540 浏览 6 评论 0原文

我有一个班级作业,要使用 Drools 作为推理机来创建机器人。然而,我的大多数规则都表现得很奇怪,因为它们不会为该类而触发,而是为其超类而触发。像这样的事情:

我的规则:

import the.manifested.Robotonikku;
import the.manifested.Strategy;
import the.manifested.Action;

import robocode.TeamRobot;

rule "One"
    when
        Robotonikku();
    then
        System.out.println("roboto is present");
end

rule "Two"
    when
        not Robotonikku();
    then
        System.out.println("roboto is not present");
end

rule "Three"
    when
        TeamRobot();
    then
        System.out.println("robot is present");
end

rule "Four"
    when
        not TeamRobot();
    then
        System.out.println("robot is not present");
end

正如

public class Robotonikku extends TeamRobot

Robocode 模拟器调用的 Robotonikku 的 run() 方法中所预期的那样,我插入实例作为事实:

ksession.insert(this)

我希望规则一和三应该触发,但规则二和三被触发。为什么它将该实例识别为 TeamRobot 而不是 Robotonikku?

提前致谢。

加载代码:

    String ficheroReglas = System.getProperty("robot.reglas", RobotDrools.FICHERO_REGLAS);

    kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    kbuilder.add(ResourceFactory.newClassPathResource(ficheroReglas, RobotDrools.class), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        System.err.println(kbuilder.getErrors().toString());
    }

    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    ksession = kbase.newStatefulKnowledgeSession();

i have a class assignment to create a Robot using Drools as an inference machine. however, most of my rules act strange since they don't fire for the class but fire for it's superclass. Something like this:

my rules:

import the.manifested.Robotonikku;
import the.manifested.Strategy;
import the.manifested.Action;

import robocode.TeamRobot;

rule "One"
    when
        Robotonikku();
    then
        System.out.println("roboto is present");
end

rule "Two"
    when
        not Robotonikku();
    then
        System.out.println("roboto is not present");
end

rule "Three"
    when
        TeamRobot();
    then
        System.out.println("robot is present");
end

rule "Four"
    when
        not TeamRobot();
    then
        System.out.println("robot is not present");
end

and as expected

public class Robotonikku extends TeamRobot

inside the run() method of Robotonikku that is called by Robocode's simulator I insert the instance as a fact:

ksession.insert(this)

i would expect that rules One and Three should fire but rule Two and Three are fired. Why it recognizes the instance as a TeamRobot and not as Robotonikku?

thanks in advance.

loading code:

    String ficheroReglas = System.getProperty("robot.reglas", RobotDrools.FICHERO_REGLAS);

    kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    kbuilder.add(ResourceFactory.newClassPathResource(ficheroReglas, RobotDrools.class), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        System.err.println(kbuilder.getErrors().toString());
    }

    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    ksession = kbase.newStatefulKnowledgeSession();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡间太子 2024-11-26 18:22:49

Robocode 引擎将机器人加载到安全的类加载器中。加载到机器人类加载器中的类对于 robocode 进程中的其余类加载器不可见。我想你必须将 drools 加载到与机器人相同的 classLoader 中(最简单的方法是将机器人上的类合并到 classPath 并添加 drools .class 文件或合并 jar)。我不确定 drools 是否仍然可以在 robocode 的安全限制下工作,因此您可能需要关闭 robocode 安全性。

Robocode engine loads the robot into secured classloader. The classes loaded into robot classLoader are not visible to rest of the classLoaders in robocode process. I guess you have to load the drools into same classLoader as robot (easiest way is to merge classes on the robot the classPath and add drools .class files or merge jars). I'm not sure drools will still work under security restrictions of robocode, so you may need to turn off robocode security.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文