NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

location(T1,R,C) :-
% recursive call of all times player been at such point
% this addition fixes such calls.
% exp: location(T, 1, 1) -> T = 1, T = 3, T = 12...
nonvar(T1), nonvar(R), nonvar(C),
T0 is T1 - 1,
RN is R - 1,
RS is R + 1,
CW is C - 1,
CE is C + 1,
(
((action(T0,eat); action(T0,clockWise); action(T0,counterClockWise)), location(T0, R, C));
((action(T0,attack); action(T0,forward)), bump(T1), location(T0, R, C));
((action(T0,attack); action(T0,forward)), dir(T0,north), not(bump(T1)), location(T0, RS, C));
((action(T0,attack); action(T0,forward)), dir(T0,south), not(bump(T1)), location(T0, RN, C));
((action(T0,attack); action(T0,forward)), dir(T0,west), not(bump(T1)), location(T0, R, CE));
((action(T0,attack); action(T0,forward)), dir(T0,east), not(bump(T1)), location(T0, R, CW))
).

dir(T1,north) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,north));
(action(T0,clockWise), dir(T0,west));
(action(T0,counterClockWise), dir(T0,east))
).

dir(T1,east) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,east));
(action(T0,clockWise), dir(T0,north));
(action(T0,counterClockWise), dir(T0,south))
).

dir(T1,south) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,south));
(action(T0,clockWise), dir(T0,east));
(action(T0,counterClockWise), dir(T0,west))
).

dir(T1,west) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,west));
(action(T0,clockWise), dir(T0,south));
(action(T0,counterClockWise), dir(T0,north))
).

/**
README
All procedures designed to be time independent which may lower or
increase performance.

Important assumption, there could be no close entities that could
simultaneously cause a "effect" such as enemy, food, or pit.
*/

/* Wall variables related */
isWall(T,R,C) :-
isWall(R,C).
isWall(X,Y):- % change in Q1
(X =:= 0; Y =:= 0);
(CW is Y - 1, location(T,X,CW), dir(T,east), TN is T + 1, bump(TN));
(RN is X - 1, location(T,RN,Y), dir(T,south),TN is T + 1, bump(TN));
(CE is Y + 1, location(T,X,CE), dir(T,west), TN is T + 1, bump(TN));
(RS is X + 1, location(T,RS,Y), dir(T,north),TN is T + 1, bump(TN)).
isClear(T,R,C) :- % change in Q1
hasNotEnemy(T,R,C),
hasNotPit(T,R,C),
not(isWall(R,C)).

% initilization, "no such procedure" fix...
% change this to check existance of a procedure each time...
action(-1,_).
enemySight(-1).
enemySmell(-1).
pitBreeze(-1).
foodSmell(-1).
full(-1).
bump(-1).
isWall(-1,-1).
isWall(-1,-1,-1).

hasNotEnemy(T,R,C) :- % change in Q2
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A, (enemySmell(A), not(A = -1)), ET),
not(
(
hasEverBeenAt(ET,R,CW), !;
hasEverBeenAt(ET,R,CE), !;
hasEverBeenAt(ET,RN,C), !;
hasEverBeenAt(ET,RS,C)
)
).

% helper function to check if player
% ever been at given location in given times.
hasEverBeenAt([],R,C) :- fail.
hasEverBeenAt([H|T],R,C) :-
location(H,R,C), !; hasEverBeenAt(T,R,C).

hasNotPit(T,R,C) :- % change in Q2
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A, (pitBreeze(A), not(A = -1)), PT),
not(
(
hasEverBeenAt(PT,R,CW), !;
hasEverBeenAt(PT,R,CE), !;
hasEverBeenAt(PT,RN,C), !;
hasEverBeenAt(PT,RS,C)
)
).

% assumes there are no pit close by that can cause breeze
hasPit(T,R,C) :- % change in Q3
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A,(pitBreeze(A), not(A = -1)),PT),
(
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,R,CE)), !;
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,RN,C)), !;
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,RS,C)), !;
(hasEverBeenAt(PT,R,CE), hasEverBeenAt(PT,RN,C)), !;
(hasEverBeenAt(PT,R,CE), hasEverBeenAt(PT,RS,C)), !;
(hasEverBeenAt(PT,RN,C), hasEverBeenAt(PT,RS,C))
).

% helper procedure to hasEnemy,
% if agent have seen the enemy and felt the smell
% then there definitely is a enemy
hasEnemySighted(R,C) :-
enemySight(T), not(T = -1),
location(T,SR,SC),
( % If anything has been spoted
(SR = R, ((SC =< C, dir(T,east ));(SC >= C, dir(T,west )))), !;
(SC = C, ((SR =< R, dir(T,south));(SR >= R, dir(T,north))))
),
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A,(enemySmell(A),not(A = -1)),PT),
( % If there were any smell around, then there is a enemy
hasEverBeenAt(PT,R,CW), !;
hasEverBeenAt(PT,R,CE), !;
hasEverBeenAt(PT,RN,C), !;
hasEverBeenAt(PT,RS,C)
).

% If enemy has not seen in location of question
% assumes there are no enemy close by that can cause smell
hasEnemy(T,R,C) :- % change in Q3
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A,(enemySmell(A),not(A = -1)),PT),
% There was an enemy sight in R,C
(hasEnemySighted(R,C), !;
( % If there is breeze in more than one neighbor, then there is a pit
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,R,CE)), !;
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,RN,C)), !;
(hasEverBeenAt(PT,R,CW), hasEverBeenAt(PT,RS,C)), !;
(hasEverBeenAt(PT,R,CE), hasEverBeenAt(PT,RN,C)), !;
(hasEverBeenAt(PT,R,CE), hasEverBeenAt(PT,RS,C)), !;
(hasEverBeenAt(PT,RN,C), hasEverBeenAt(PT,RS,C))
)
).
% Assumes agent only attack to kill.
hasDeadEnemy(T,R,C) :- % change in Q3
action(T1,attack), not(T1 = -1),
location(T1,AR,AC),
(
(AR = R, ((AC =:= (C - 1), dir(T1,east ));(AC =:= (C + 1), dir(T1,west )))), !;
(AC = C, ((AR =:= (R - 1), dir(T1,south));(AR =:= (R + 1), dir(T1,north))))
).

% helper function to check if player
% ever been at given location in given times.
doesContain([],R,C) :- fail.
doesContain([[RH|CH]|T],R,C) :-
(RH =:= R, CH =:= C), !; doesContain(T,R,C).

hasFood(T,R,C) :- % change in Q4
% check if any food has been eaten in given location.
findall([FLR,FLC], (full(A), not(A = -1), location(A,FLR,FLC)), FLT),
not(doesContain(FLT,R,C)),
% if there were any food smell around,
% then tell hasFood to force agent to try eat action.
findall(A,
(
foodSmell(A), not(A = -1),
% weed out smells around eaten foods.
location(A,SR,SC), not(doesContain(FLT,SR,SC))
),FT),
RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
(
hasEverBeenAt(FT,R,CW), !;
hasEverBeenAt(FT,R,CE), !;
hasEverBeenAt(FT,RN,C), !;
hasEverBeenAt(FT,RS,C)
).

hasNotFood(T,R,C) :- % change in Q4
% if a food has eaten here, assert true immediately
findall([FLR,FLC], (full(A), not(A = -1), location(A,FLR,FLC)), FLT),
doesContain(FLT,R,C), !;

RN is R - 1, RS is R + 1,
CW is C - 1, CE is C + 1,
findall(A,(foodSmell(A),not(A = -1)),FT),
% If there were not any smell around
not(hasEverBeenAt(FT,R,CW)),
not(hasEverBeenAt(FT,R,CE)),
not(hasEverBeenAt(FT,RN,C)),
not(hasEverBeenAt(FT,RS,C)).

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.