summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-04-02 15:44:24 +1100
committerJed Barber <jjbarber@y7mail.com>2014-04-02 15:44:24 +1100
commita37f9b2c78e5b48917593c0c047fef7e3bb7f264 (patch)
treeccfd887c8a37868f786304c6ae554d49dc9f1f90
parent320e9630c3ecff0105ea97fd3e09836619b54b62 (diff)
Added pits, finished init
-rw-r--r--agent.prolog51
1 files changed, 24 insertions, 27 deletions
diff --git a/agent.prolog b/agent.prolog
index fb49cde..2ff60eb 100644
--- a/agent.prolog
+++ b/agent.prolog
@@ -15,7 +15,10 @@ init :-
initPits,
initWumpus,
initGold,
- initBats, !.
+ initBats,
+ roomList(Rooms),
+ filter(Rooms, hazardAt, Walkable),
+ isConnected(Walkable) *-> !; init.
initPos :-
@@ -26,7 +29,9 @@ initPos :-
asserta(here(X)).
-initPits :- true.
+initPits :-
+ retractall(pitsAt(_)),
+ insert(5,pitsAt).
initWumpus :-
@@ -40,38 +45,25 @@ initWumpus :-
initGold :-
retractall(goldAt(_)),
retractall(haveGold(_)),
- insertGold(3),
+ insert(3,goldAt),
asserta(haveGold(0)).
-insertGold(N) :-
- N > 0,
- Nx is N - 1,
- insertGold(Nx),
- roomList(Rooms),
- filter(Rooms, somethingAt, Emptyrooms),
- random_member(X,Emptyrooms),
- asserta(goldAt(X)).
-insertGold(0) :- true.
-
-
initBats :-
retractall(batsAt(_)),
- insertBats(2).
+ insert(2,batsAt).
-insertBats(N) :-
+insert(N,Thing) :-
N > 0,
Nx is N - 1,
- insertBats(Nx),
+ insert(Nx,Thing),
roomList(Rooms),
filter(Rooms, somethingAt, Emptyrooms),
random_member(X,Emptyrooms),
- asserta(batsAt(X)).
-insertBats(0) :- true.
-
-
-
+ P =.. [Thing,X],
+ asserta(P).
+insert(0,_) :- true.
@@ -249,10 +241,13 @@ lose(pit) :-
% miscellaneous clauses
somethingAt(X) :- current_predicate(here/1), here(X).
-somethingAt(X) :- current_predicate(wumpusAt/1), wumpusAt(X).
-somethingAt(X) :- current_predicate(pitAt/1), pitAt(X).
somethingAt(X) :- current_predicate(goldAt/1), goldAt(X).
-somethingAt(X) :- current_predicate(batsAt/1), batsAt(X).
+somethingAt(X) :- hazardAt(X).
+
+
+hazardAt(X) :- current_predicate(wumpusAt/1), wumpusAt(X).
+hazardAt(X) :- current_predicate(pitAt/1), pitAt(X).
+hazardAt(X) :- current_predicate(batsAt/1), batsAt(X).
intercalate([X|Y], Spacer, Result) :-
@@ -278,8 +273,10 @@ tail(X,[_|Y]) :- X = Y.
isConnected([]) :- true.
-isConnected([_]) :- true.
-isConnected([X|Y]) :- connectTail([X],Y).
+isConnected(X) :-
+ head(Y,X),
+ tail(Z,X),
+ connectTail([Y],Z).
connectTail(_,[]) :- true.
connectTail([],_) :- false.