List<Gdl> newDescription = new ArrayList<Gdl>();
//First: Clean up all rules with zero-element bodies
for(Gdl gdl : description) {
if(gdl instanceof GdlRule) {
GdlRule rule = (GdlRule) gdl;
if(rule.getBody().size() == 0) {
newDescription.add(rule.getHead());
} else {
newDescription.add(gdl);
}
} else {
newDescription.add(gdl);
}
}
//TODO: Add (role ?player) where appropriate, i.e. in rules for
//"legal" or "input" where the first argument is an undefined
//variable
//Get rid of "extra parentheses", i.e. zero-arity functions
description = newDescription;
newDescription = new ArrayList<Gdl>();
for(Gdl gdl : description) {
if(gdl instanceof GdlRelation) {
newDescription.add(cleanParentheses((GdlRelation)gdl));
} else if(gdl instanceof GdlRule) {
newDescription.add(cleanParentheses((GdlRule)gdl));
} else {
newDescription.add(gdl);
}
}
//TODO: Get rid of GdlPropositions in the description
//TODO: Get rid of (not (or ...))
//Get rid of (not (distinct _ _)) literals in rules
//TODO: Expand to functions
description = newDescription;
newDescription = new ArrayList<Gdl>();
for(Gdl gdl : description) {
if(gdl instanceof GdlRule) {
GdlRule cleaned = removeNotDistinctLiterals((GdlRule)gdl);
if(cleaned != null)
newDescription.add(cleaned);
} else {
newDescription.add(gdl);
}