Tileworld Game

From: Ei Sabai Nyo (nyo_at_digisurf.com.au)
Date: 04/29/04


Date: Thu, 29 Apr 2004 19:56:47 GMT

Hi,

My problem is to write basic functions of BDI Agent in prolog. The problem

description(case) is about Tileworld and only one agent is invloved. Please

give me some ideas for the problem.

The Tileworld consists of a two-dimensional grid of locations, extending to

infinity in both directions. Some locations contain "food" resources (of

varying values), which agents must "eat" in order to score points. An agent

eats a piece of food by moving to its location and executing an eat action.

Agents can move one square at a time either horizontally or vertically. The

world is dynamic in that food may spontaneously appear at a randomly

determined location at any time.

The agent's beliefs at any time simply consist of a list containing one term

of the form at(X,Y) representing the current location of the agent. The

agent's beliefs are always correct.

The agent's goals at any time are a list of locations of food items and

their values. Each goal of the agent is represented as an term goal(X,Y,S),

where (X,Y) is the location of the food and S is its value.

The agent's intentions are these goals ordered according to some priority.

To fulfil an intention, the agent's action is just to move along some path

towards the corresponding goal and collect the reward (the actual path is

determined at run time).

There are three types of action the agent can execute in any one cycle:

null - the agent does nothing

eat(X,Y) - the agent eats the food at (X,Y) and gains the associated reward

move(X,Y) - the agent moves to the location (X,Y)

The agent's prioritization strategy is very simple: each new goal is

inserted into the list of intentions in order of the closeness of the food

item to the agent's current position (closer items coming earlier in the

list). However, once a goal is incorporated into the list of intentions, it

is never re-prioritized with respect to existing goals as the agent moves

about (hence after some time the list may not accurately reflect the

closeness of food to the agent).

The agent chooses to go towards the food item nearest to the agent when it

appeared. The

initial state of the world is always that there is no food and the agent is

at the location (0,0).

HERE ARE THE QUESTIONS. PLEASE GIVE ME SOME IDEAS OR ALGORITHMS. I AM LOST!!

1. How to write a Prolog procedure incorporate intentions(Options, Beliefs,

Intentions, Intentions1) which has four arguments: a list of options each of

the form goal(X,Y,S), a list of beliefs (here containing one term of the

form at(X,Y)), the current list of intentions each of the form goal(X,Y,S),

and computes a list which contains the new options inserted into the current

list of intentions in order of the Manhattan distance of the goal from the

agent's current location. If an option is the same distance from the agent

as an existing goal, the new goal should be placed later in the list.

2. How to write a Prolog procedure select action(Beliefs, Intentions,

Action) which takes the agent's beliefs (a singleton list containing an

term for the agent's location) and the list of intentions, and computes an

action to be taken by the agent. Note that the goal selected by the agent

is the first on the list of intentions, and in the case of a move action,
the

action should specify the coordinates to which the agent should move

(being one square from the agent's current location). Due to the use of

Manhattan distance and the fact that there are no obstacles in the world,

the exact path the agent takes towards the goal does not matter much,

so choose the simplest way of implementing this procedure.

3. How to write two Prolog procedures update beliefs(Observation, Beliefs,

Beliefs1) and update intentions(Observation, Intentions, Intentions1) to

compute the lists of beliefs and intentions resulting from the agent's

observations. (one line for each possible observation type)!

4. How to write a Prolog procedure trigger(Events, Options) which takes a

list of events, each of the form food(X,Y,S) and computes a list of options

for the agent, each of the form goal(X,Y,S).

_______________

The following Prolog program implements the experimental setup, including
the

generation of events (appearance of food) and the execution of actions, and
the

agent's BDI interpretation cycle and observation functions. It consists of
one

agent in the Tileworld that repeatedly executes the BDI interpretation cycle
for

20 iterations. The produced code must work with this program.

% Simulates a single agent in the Tileworld where food appears on each cycle

% at randomly % determined locations in the 10x10 grid with probability 0.3

% run a trial of 20 cycles of the BDI interpreter starting with the agent at
(0,0)

agent_trial :-

                init,

                agent_trials(0, 20, [at(0,0)], [], 0, Score),

                write('Total score: '), print(Score), !.

% initial state of the world

init :-

                assert(robot_at(0,0)).

% run trials up to N

agent_trials(N, N, _, _, Score, Score) :- !.

agent_trials(N1, N, Beliefs, Intentions, Score, Score2) :-

                N1 < N,

                agent_cycle(N1, Beliefs, Beliefs1, Intentions, Intentions1,
S),

                Score1 is Score + S,

                N2 is N1 + 1,

                agent_trials(N2, N, Beliefs1, Intentions1, Score1, Score2).

% the BDI interpretation cycle used by the agent

agent_cycle(N, Beliefs, Beliefs1, Intentions, Intentions2, S) :-

                write('Cycle '), write(N), print(':'),

                new_events(N, Events),

                trigger(Events, Options),

                incorporate_intentions(Options, Beliefs, Intentions,
Intentions1),

                write(' Intentions: '), print(Intentions1),

                select_action(Beliefs, Intentions1, Action),

                write(' Action: '), write(Action),

                execute(Action, S),

                write(' scores '), print(S),

                observe(Action, Observation),

                write(' Observation: '), print(Observation),

                update_beliefs(Observation, Beliefs, Beliefs1),

                write(' New Beliefs: '), print(Beliefs1),

                update_intentions(Belief, Intentions1, Intentions2),

                write(' New Intentions: '), print(Intentions2).

% with probability 0.3, a new food item appears in random location on the
10x10 grid

new_events(N, [food(X,Y,S)]) :-

                Prob is random(1),

                Prob =< 0.3, !,

                X is round(random(10)),

                Y is round(random(10)),

                S is round(random(10)),

                write(' Events: food value '), write(S), write(' appears
at '), write('('), write(X), write(','), write(Y), print(')'),

                assert(food(X, Y, S)).

new_events(N, []) :-

                print(' Events: none').

% execute action in the Tileworld -- always successfully!

execute(null, 0).

execute(eat(X,Y), S) :-

                retract(food(X, Y, S)),

                assert(eaten(X,Y)).

execute(move(X1,Y1), 0) :-

                retract(robot_at(U, V)),

                distance((U,V), (X1,Y1), 1),

                assert(robot_at(X1, Y1)).

% observe result of action -- always correctly!

observe(null, at(X,Y)) :-

                robot_at(X, Y).

observe(move(_,_), at(X,Y)) :-

                robot_at(X, Y).

observe(eat(_,_), eaten(X,Y)) :-

                retract(eaten(X,Y)).

Thanks.

Regards,

ESN



Relevant Pages

  • need help for this procedure
    ... The goal selected by the agent is the first on the list of ... intentions, and in the case of a move action, the action should specify the ... The agent's goals at any time are a list of locations of items and their ... How could I implement this using lists in prolog? ...
    (comp.lang.prolog)
  • Re: Replace dangerous side steps
    ... inexpensively when you live in an expensive neighborhood. ... When I read mailing lists, people are always changing the subject line ... even though Agent does sort by thread. ... I've used Netscape a little for news, but not enough to see how it ...
    (alt.home.repair)
  • Re: forming Ticker-Tape in Status Bar after running web Query
    ... I donot know how to write the scrolling TickerTape program ... > You'll have 4 lists. ... >> Now, after i extract data on a worksheet, i want to also refresh the ... >> column in the worksheet which would contain the full list of agent ID's ...
    (microsoft.public.excel.programming)
  • Re: Paging Gene Kearns...
    ... Some people use Agent or Mozilla apps simply to "boycott" Microsoft. ... In a newsgroup, imagine two sorted lists. ... could not sort ALL the watched threads so they'd be at the top of the ... general heap of threads. ...
    (rec.boats)
  • Re: lists
    ... The goal selected by the agent is the first on the list of ... intentions, and in the case of a move action, the action should specify the ... The agent's goals at any time are a list of locations of items and their ... to the agent's current position (closer items coming earlier in the list). ...
    (comp.lang.prolog)