private void cleanAnteriorFacts() { DEBUG.message("clean anterior facts"); for (FactHandle referencedFact : this.currentReferencedFacts) { ksession.retract(referencedFact); } this.currentReferencedFacts.clear(); }
/** * Will check if {@link CoreTokenConstant.CTS_STORE_HOSTNAME} property will need to be updated and * need the host port appended to the connection string. * * @param serverName the name of the server Instance. * @param serverProperties the configuration of the server Instance. */ protected void checkCTSStoreConnections(String serverName, Properties serverProperties) { String ctsHostName = serverProperties.getProperty(CoreTokenConstants.CTS_STORE_HOSTNAME); String ctsPort = serverProperties.getProperty(CTS_STORE_PORT); String ctsLocation = serverProperties.getProperty(CoreTokenConstants.CTS_STORE_LOCATION); DEBUG.message( "Checking CTS Store properties for instance: " + serverName + " \n properties: " + "ctsHostName: " + ctsHostName + " ctsPort: " + ctsPort + " ctsLocation: " + ctsLocation); // if no host and port values then return if (StringUtils.isBlank(ctsHostName) && StringUtils.isBlank(ctsPort)) { return; } // check current instance values and set to default if needed if (StringUtils.isBlank(ctsHostName)) { ctsHostName = ctsDefaultHostName; DEBUG.message("ctsHostName defaulting to : " + ctsDefaultHostName); } if (StringUtils.isBlank(ctsPort)) { ctsPort = ctsDefaultHostPort; DEBUG.message("ctsPort defaulting to : " + ctsDefaultHostPort); } if (StringUtils.isBlank(ctsLocation)) { ctsLocation = ctsDefaultLocation; DEBUG.message("ctsLocation defaulting to : " + ctsDefaultLocation); } // if the configuration is default, the host or port is blank from defaults or if there is // already a colon in // CTS host name then skip if (!"external".equals(ctsLocation) || StringUtils.isBlank(ctsHostName) || ctsHostName.contains(COLON_CHAR) || StringUtils.isBlank(ctsPort)) { return; } // store properties to be updated propertiesToModify.put(serverName, ctsHostName + COLON_CHAR + ctsPort); }
private void createKnowledgeBase() { String rulesFile = System.getProperty("robot.rules", BaguetteSOLO.RULES_FILE); DEBUG.message("Creating knowledge base"); kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); DEBUG.message("Loading rules since " + rulesFile); kbuilder.add( ResourceFactory.newClassPathResource(rulesFile, BaguetteSOLO.class), ResourceType.DRL); if (kbuilder.hasErrors()) { System.err.println(kbuilder.getErrors().toString()); } kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); DEBUG.message("Creating session)"); ksession = kbase.newStatefulKnowledgeSession(); }
private void loadBattleState() { DEBUG.message("load battle state"); BattleState battleState = new BattleState( getBattleFieldWidth(), getBattleFieldHeight(), getNumRounds(), getRoundNum(), getTime(), getOthers()); currentReferencedFacts.add(ksession.insert(battleState)); }
/** * Set the default values from the server-default values. * * @param props the properties from the server */ protected void setDefaultValues(Properties props) { ctsDefaultLocation = props.getProperty(CoreTokenConstants.CTS_STORE_LOCATION); ctsDefaultHostName = props.getProperty(CoreTokenConstants.CTS_STORE_HOSTNAME); ctsDefaultHostPort = props.getProperty(CTS_STORE_PORT); DEBUG.message( "Setting External CTS Store properties defaults: " + "\n ctsDefaultHostName: " + ctsDefaultHostName + " ctsDefaultHostPort: " + ctsDefaultHostPort + " ctsDefaultLocation:" + ctsDefaultLocation); }
private Vector<Action> loadActions() { DEBUG.message("load actions"); Action action; Vector<Action> actionsList = new Vector<Action>(); for (QueryResultsRow result : ksession.getQueryResults(BaguetteSOLO.CONSULT_ACTIONS)) { action = (Action) result.get("action"); // get the Action object action.setRobot(this); // link it to the current robot actionsList.add(action); ksession.retract(result.getFactHandle("action")); // clears the fact from the active memory } return actionsList; }
public void run() { DEBUG.enableDebugMode(System.getProperty("robot.debug", "true").equals("true")); // Creates a knowledge base createKnowledgeBase(); DEBUG.message("KBase created"); // COLORS setBodyColor(Color.blue); setGunColor(Color.white); setRadarColor(Color.red); setScanColor(Color.white); setBulletColor(Color.red); // Make any movement from tank, radar or gun independent setAdjustGunForRobotTurn(true); setAdjustRadarForGunTurn(true); setAdjustRadarForRobotTurn(true); while (true) { DEBUG.message("TURN BEGINS"); loadRobotState(); loadBattleState(); // Fire rules DEBUG.message("Facts in active memory"); DEBUG.printFacts(ksession); DEBUG.message("firing rules"); ksession.fireAllRules(); cleanAnteriorFacts(); // Get Actions Vector<Action> actions = loadActions(); DEBUG.message("Resulting Actions"); DEBUG.printActions(actions); // Execute Actions DEBUG.message("firing actions"); executeActions(actions); DEBUG.message("TURN ENDS\n"); execute(); } }
@Override public void perform() throws UpgradeException { try { DEBUG.message("External CTS Configuration upgrading: " + propertiesToModify); UpgradeProgress.reportStart("upgrade.cts.property"); for (Entry<String, String> serverProperty : propertiesToModify.entrySet()) { // get existing values Map<String, String> existingServerProperties = new HashMap( ServerConfiguration.getServerInstance(getAdminToken(), serverProperty.getKey())); // add new values to existing values existingServerProperties.put( CoreTokenConstants.CTS_STORE_HOSTNAME, serverProperty.getValue()); existingServerProperties.keySet().remove(CTS_STORE_PORT); ServerConfiguration.upgradeServerInstance( getAdminToken(), serverProperty.getKey(), null, existingServerProperties); } UpgradeProgress.reportEnd("upgrade.success"); } catch (Exception ex) { DEBUG.error("Unable to upgrade External CTS properties", ex); throw new UpgradeException(ex); } }
public void onScannedRobot(ScannedRobotEvent event) { DEBUG.message("received on scanned robot"); currentReferencedFacts.add(ksession.insert(event)); }
public void onRobotDeath(RobotDeathEvent event) { DEBUG.message("received on robot death"); currentReferencedFacts.add(ksession.insert(event)); }
public void onHitWall(HitWallEvent event) { DEBUG.message("received on hit wall"); currentReferencedFacts.add(ksession.insert(event)); }
public void onHitByBullet(HitByBulletEvent event) { DEBUG.message("received hit by bullet"); currentReferencedFacts.add(ksession.insert(event)); }
public void onBulletMissed(BulletMissedEvent event) { DEBUG.message("received bullet miss"); currentReferencedFacts.add(ksession.insert(event)); }
public void onBulletHitBullet(BulletHitBulletEvent event) { DEBUG.message("received on bullet hit another bullet"); currentReferencedFacts.add(ksession.insert(event)); }
private void executeActions(Vector<Action> actions) { DEBUG.message("execute actions"); for (Action action : actions) { action.initExecution(); } }
public void onHitRobot(HitRobotEvent event) { DEBUG.message("received on hit robot"); currentReferencedFacts.add(ksession.insert(event)); }
private void loadRobotState() { DEBUG.message("load robot state"); RobotState robotState = new RobotState(this); currentReferencedFacts.add(ksession.insert(robotState)); }