Many Prolog systems meanwhile implement tabling. SWI-Prolog has adopted much of XSB tabling. XSB tabling suggest converting game search:
win(X) :- move(X,Y), \+ win(Y).
Into this tabling:
:- table win/1.
win(X) :- move(X,Y), tnot(win(Y))
Is it worth considering tabling for game search in practical game search? What would be the impact on Tic-Tac-Toe?
My point of departure was the Prolog Tic-Tac-Toe tictac.p, link is given at the end of the post. But I wasn't using tnot/1, only the table/1 directive. First we must be careful in adding the right tabling.
So the below first take in adding the table/1 directive is nonsense since the recursive call of best/3 in the negation as failure meta argument has an implicit existential quantifier. The 3rd argument will make best/3 non deterministic and blow up the table:
What works better, is only taking the first solution of best/3 into a new predicate best/2. This will not change the result of negation as failure. And then table this new predicate best/2:
Interesting find, SWI-Prolog negation as failure is much faster than mine, but it is bothered with some overhead, since when switching to tabling it cannot speed up the game search. Was comparing the Prolog texts tictac.p and tictac2.pl:
On the other hand I get a ca. two fold speed-up:
Open source:
Tic-Tac-Toe without tabling
https://github.com/jburse/jekejeke-samples/blob/master/jekrun/benchmark/tests/tictac.p
Tic-Tac-Toe with tabling
https://gist.github.com/jburse/713b6ad2b7e28de89fe51b98be3d0943#file-tictac2-pl