Skip to content

Commit afcafd9

Browse files
Ruediger.LundeRuediger.Lunde
authored andcommitted
Percept generation of MapEnvironment extended with possible action information.
1 parent 199ac3f commit afcafd9

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/aima/search/map/DynAttributeNames.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,32 @@
1515
public class DynAttributeNames {
1616
/**
1717
* Name of a dynamic attribute, which contains the current location of the
18-
* agent.
18+
* agent. Expected value type: String.
1919
*/
2020
public static final String AGENT_LOCATION = "location";
2121
/**
2222
* Name of a dynamic attribute, which maintains the total traveling distance
23-
* of the agent since birth. Should be of type Integer.
23+
* of the agent since birth. Expected value type: Integer.
2424
*/
2525
public static final String AGENT_TRAVEL_DISTANCE = "travelDistance";
2626
/**
2727
* Name of a dynamic attribute, which indicates the current status of the
28-
* agent, such as traveling, completed or aborted.
28+
* agent, such as traveling, completed or aborted. Expected value type:
29+
* String.
2930
*/
3031
public static final String AGENT_STATUS = "status";
3132

3233
/**
33-
* Name of a dynamic attribute, which tells the agent where it is.
34+
* Name of a dynamic attribute, which tells the agent where it is. Expected
35+
* value type: String.
3436
*/
3537
public static final String PERCEPT_IN = "In";
3638
/**
3739
* Name of a dynamic attribute, which tells the agent which actions are
38-
* possible at the current location of the agent.
40+
* possible at the current location of the agent. Expected value type: List
41+
* of alternating Strings and Integers.
3942
*/
40-
public static final String PERCEPT_POSSIBLE_ACTIONS = "Signpost";
43+
public static final String PERCEPT_POSSIBLE_ACTIONS = "PossibleActions";
4144
/**
4245
* Name of a dynamic attribute. It provides access to informations which are
4346
* available at the current location of the agent.

src/aima/search/map/MapEnvironment.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package aima.search.map;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import aima.basic.Agent;
47
import aima.basic.Environment;
58
import aima.basic.Percept;
@@ -43,8 +46,15 @@ public void executeAction(Agent a, String act) {
4346

4447
@Override
4548
public Percept getPerceptSeenBy(Agent anAgent) {
46-
return new Percept(DynAttributeNames.PERCEPT_IN, anAgent
47-
.getAttribute(DynAttributeNames.AGENT_LOCATION));
49+
String currLoc = (String) anAgent.getAttribute(
50+
DynAttributeNames.AGENT_LOCATION);
51+
List<Object> possibleActions = new ArrayList<Object>();
52+
for (String a : aMap.getLocationsLinkedTo(currLoc)) {
53+
possibleActions.add(a);
54+
possibleActions.add(new Integer(aMap.getDistance(currLoc, a)));
55+
}
56+
return new Percept(DynAttributeNames.PERCEPT_IN, currLoc,
57+
DynAttributeNames.PERCEPT_POSSIBLE_ACTIONS, possibleActions);
4858
}
4959

5060
public Map getMap() {

0 commit comments

Comments
 (0)