1
votes

As the question says, thats kind of what i wanna simulate in prolog. So i'm making a game,here's some code:

move(X):-
    get_char(Y)
    get_char(_),
    get_char(Z),
    not(OldLoc='Z'),
    not(NewLoc = 'Z'),
    validmove(OldLoc,NewLoc).
move(_):-
    write('Thanks for playing!'), nl.
move(X):-
    write('Invalid move!'), nl,
    write('Try Again?'), nl,
    move(X).

what i want to do is if the first predicate check fails at not(OldLoc='Z'),not(NewLoc = 'Z'), then go to the next predicate move(_) and it fails at validmove(OldLoc,NewLoc) then go to the next move(X). I'm very new to prolog and i'm almost completely clueless.

1

1 Answers

1
votes

If-then-else: http://www.swi-prolog.org/pldoc/doc_for?object=send_arrow/2

Another if-then-else: http://www.swi-prolog.org/pldoc/doc_for?object=(*-%3E)/2

Sample #1:

?- test = test -> print('TRUTH') ; print('FALSE').
TRUTH

Sample #2:

?- test = test -> (test2 = test3 -> print('TRUTH'); print('FALSE2')); print('FALSE').
FALSE2