Using prolog, can I continue execution after a line returns false?
I have to create a tic-tac-toe game. I want to check for a winning state after each player's turn.
checkwin returns true when there is a winning state, but false otherwise. The issue then is that after it returns false, I can't move on to the next player's move.
How can I check it every turn, and continue to execute the code that follows the check? Is there a way to 'continue if false'?
adjustGame(PosX, PosY, Gameboard, Token) :-
update(PosX, PosY, Gameboard, Newboard, Token),
display(Newboard),
checkwin(Newboard,Token),% This is false until the game has a winner
play(Newboard,Token). % but I want to execute this line until then
checkwin([A,B,C,D,E,F,G,H,I],T) :-
same(A,B,C,T);
same(D,E,F,T);
same(G,H,I,T);
same(A,D,G,T);
same(B,E,H,T);
same(C,F,I,T);
same(A,E,I,T);
same(C,E,G,T).
same(X,X,X,X).
Thanks!
ignore/1
. – fferriadjustGame/4
is called? You could use((checkwin(...) -> true ; play(...))
, but then you lose the choice point before this call, and I'm not sure if you need it. I suspect the logic might need to be refactored a little to achieve what you want. – lurker