Robocode Robot with Drools Expert
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();
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.
精彩评论