public void testTicTacToe() throws IOException
{
GameInformation info = MetaGdl.examineGame("game-defs/tictactoe.kif", parser_);
KnowledgeBase staticKb = new BasicKB();
staticKb.loadWithFacts(info.getAllGrounds());
AbstractReasoner r = new BasicReasoner(staticKb, info.getIndexedRules(), parser_);
Fact initQuestion = Fact.fromExpression(parser_.parse("init ?x"));
// Compute the initial state
List<GroundFact> inits = r.getAllAnswers(initQuestion);
KnowledgeBase currentState = new BasicKB();
RelationNameProcessor trueProcessor = new RelationNameProcessor(parser_.TOK_TRUE);
for (GroundFact init: inits) {
currentState.setTrue(trueProcessor.processFact(init));
}
assertEquals(10, currentState.getNumFacts());
GroundFact [] moves;
// Do some updates
moves = new GroundFact [] {
(GroundFact) makeFact("does xplayer (mark 1 1)"),
(GroundFact) makeFact("does oplayer noop"),
};
currentState = updateKbWithMoves(r, currentState, moves);
System.out.println(currentState.stateToGdl());
assertEquals(10, currentState.getNumFacts());
moves = new GroundFact [] {
(GroundFact) makeFact("does xplayer noop"),
(GroundFact) makeFact("does oplayer (mark 1 3)"),
};
currentState = updateKbWithMoves(r, currentState, moves);
System.out.println(currentState.stateToGdl());
assertEquals(10, currentState.getNumFacts());
}