>>> PROLOG <<<

Df0edc8d0f85d69e84fcab7c5fabfcb7
0
rego 101 Jan 11, 2005 at 20:37

hey,

i’m having trouble causing a program to stop running or halt when an event is triggered for example winning a game. i tried using the fail. predicate but that just causes backtracking and makes the program really messy!
does anyone have any other solutions?

many thanks

1 Reply

Please log in or register to post a reply.

E72f771c34f4e58f34a2eac1844b214e
0
Trident 101 Jan 12, 2005 at 17:33

@rego

hey,

i’m having trouble causing a program to stop running or halt when an event is triggered for example winning a game. i tried using the fail. predicate but that just causes backtracking and makes the program really messy!
does anyone have any other solutions?

many thanks

[snapback]15059[/snapback]

Depends on the version. But generally you launch your program with a question with one variable and when it ends just instantiate that variable and cut.

stop_game:-X is ok,!.
start_game(X):-%your game here.
?- start_game(X);

Or, if you do not want to lug that X around and do not care about start_game evaluating to false you may just !,fail when needed, IIRC (note that, fail,!. is obviously pointless.) As I already said I nearly forgot the whole thing…