1

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();
  • it might be caused by the same thing. When I retrieve something from Drools with a Query and try to cast it ot the right class in java it gives me (how classloader works? can drools and robocode be using different class loaders?):Exception: java.lang.ClassCastException: drools_robocode.Action cannot be cast to drools_robocode.Action – Túlio Caraciolo Jul 12 '11 at 13:08
  • Could you please include the code showing how you are creating the knowledge base and session. Because I tried your DRL with the basic classes you described and rules one and three fire as expected. – Perception Jul 14 '11 at 13:03
  • Hello Perception, in some machines it works. We couldn't figure out the difference (same drools, jdk, jre and robocode version numbers) except that the ones that work are 32-bit and the ones that doesn`t are 64-bit. not sure this is the case. – Túlio Caraciolo Aug 02 '11 at 16:00

1 Answers1

1

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.

Pavel Savara
  • 3,427
  • 1
  • 30
  • 35