for(GdlRule rule : model.getRules(curForm)) {
GdlSentence head = rule.getHead();
List<GdlVariable> varsInHead = GdlUtils.getVariables(head);
Assignments assignments = AssignmentsFactory.getAssignmentsForRule(rule, model, functionInfoMap, Collections.EMPTY_MAP);
AssignmentIterator asnItr = assignments.getIterator();
while(asnItr.hasNext()) {
Map<GdlVariable, GdlConstant> assignment = asnItr.next();
boolean isGoodAssignment = true;
GdlSentence transformedHead = CommonTransforms.replaceVariables(head, assignment);
if(trueFlowSentences.contains(transformedHead))
asnItr.changeOneInNext(varsInHead, assignment);
//Go through the conjuncts
for(GdlLiteral literal : rule.getBody()) {
if(literal instanceof GdlSentence) {
if(curForm.matches((GdlSentence) literal))
throw new RuntimeException("Haven't implemented recursion in the game flow");
GdlSentence transformed = CommonTransforms.replaceVariables((GdlSentence) literal, assignment);
SentenceForm conjForm = model.getSentenceForm(transformed);
if(constantForms.contains(conjForm)) {
if(!constantChecker.isTrueConstant(transformed)) {
isGoodAssignment = false;
asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
}
} else {
if(!trueFlowSentences.contains(transformed)) {
//False sentence
isGoodAssignment = false;
asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
}
}
} else if(literal instanceof GdlNot) {
GdlSentence internal = (GdlSentence) ((GdlNot) literal).getBody();
GdlSentence transformed = CommonTransforms.replaceVariables(internal, assignment);
SentenceForm conjForm = model.getSentenceForm(transformed);
if(constantForms.contains(conjForm)) {
if(constantChecker.isTrueConstant(transformed)) {
isGoodAssignment = false;
asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
}
} else {
if(trueFlowSentences.contains(transformed)) {
//False sentence
isGoodAssignment = false;
asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
}
}
}
//Nothing else needs attention, really
}
//We've gone through all the conjuncts and are at the
//end of the rule
if(isGoodAssignment) {
trueFlowSentences.add(transformedHead);
if(varsInHead.isEmpty())
break; //out of the assignments for this rule
else
asnItr.changeOneInNext(varsInHead, assignment);
}
}
}
//We've gone through all the rules
}