Prolog if-elseif-else -
as question says, thats kind of wanna simulate in prolog. i'm making game,here's code:
move(x):- get_char(y) get_char(_), get_char(z), not(oldloc='z'), not(newloc = 'z'), validmove(oldloc,newloc). move(_):- write('thanks playing!'), nl. move(x):- write('invalid move!'), nl, write('try again?'), nl, move(x).
what want if first predicate check fails @ not(oldloc='z'),not(newloc = 'z'),
go next predicate move(_) , fails @ validmove(oldloc,newloc)
go next move(x). i'm new prolog , i'm clueless.
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
Comments
Post a Comment