An alternative is the library
tuProlog I used to make a chess game using java for the interface and Prolog as inference engine
In the Java file would have something like:
static Prolog engine = new Prolog();
engine.setTheory(new Theory(new FileInputStream("prolog/xadrez.pl")));
engine.solve("iniciarJava.");
info = engine.solve("mostrartab(T).");
In the file Prolog the rules and logic:
mostrartab(T):-
findall((P,Cl,(L,C)),p_atual(P,Cl,(L,C)),T).
/*carrega a base de fatos que será o tabuleiro durante a partida*/
iniciarJava:- retractall(p_atual(_,_,(_,_))),retractall(cemiterio(_,_)),
assert(p_atual('T','B',(1,1))),assert(p_atual('H','B',(1,2))),
assert(p_atual('B','B',(1,3))),assert(p_atual('Q','B',(1,4))),
assert(p_atual('K','B',(1,5))),assert(p_atual('B','B',(1,6))),
assert(p_atual('H','B',(1,7))),assert(p_atual('T','B',(1,8))),
assert(p_atual('T','W',(8,1))),assert(p_atual('H','W',(8,2))),
assert(p_atual('B','W',(8,3))),assert(p_atual('Q','W',(8,4))),
assert(p_atual('K','W',(8,5))),assert(p_atual('B','W',(8,6))),
assert(p_atual('H','W',(8,7))),assert(p_atual('T','W',(8,8))),
assert(p_atual('P','B',(2,1))),assert(p_atual('P','B',(2,2))),
assert(p_atual('P','B',(2,3))),assert(p_atual('P','B',(2,4))),
assert(p_atual('P','B',(2,5))),assert(p_atual('P','B',(2,6))),
assert(p_atual('P','B',(2,7))),assert(p_atual('P','B',(2,7))),
assert(p_atual('P','W',(7,1))),assert(p_atual('P','W',(7,2))),
assert(p_atual('P','W',(7,3))),assert(p_atual('P','W',(7,4))),
assert(p_atual('P','W',(7,5))),assert(p_atual('P','W',(7,6))),
assert(p_atual('P','W',(7,7))),assert(p_atual('P','W',(7,8))),
assert(p_atual(' ',' ',(_,_))).
To catch the return of the Prolog:
info.getVarValue("T")
to work just put the . jar as library of the project?
– roooooon
this, then you import in the classes of tuProlog
– fernandoandrade
in this case, it has 2p.jar and tuprolog.jar. 2p.jar contains some packages of tuprolog.jar, I think it would be more recommended to add only 2p.jar so ne?
– roooooon
It will depend on which packages you will use, if 2p.jar has what you need just use it.
– fernandoandrade