3131 */
3232public class MapAgent extends ProblemSolvingAgent {
3333
34- protected Map map = null ;
35- protected DynamicState state = new DynamicState ();
34+ protected final Map map ;
35+ protected final DynamicState state = new DynamicState ();
36+ protected final List <String > goals = new ArrayList <String >();
37+ protected int currGoalIdx = -1 ;
3638
3739 // possibly null...
38- private EnvironmentViewNotifier notifier = null ;
40+ protected EnvironmentViewNotifier notifier = null ;
3941 private Search search = null ;
4042 private HeuristicFunctionFactory hfFactory ;
41- protected String [] goals = null ;
42- protected int currGoalIdx = 0 ;
4343
4444 public MapAgent (Map map , Search search , String goal ) {
4545 this .map = map ;
4646 this .search = search ;
47- this . goals = new String [] { goal } ;
47+ goals . add ( goal ) ;
4848 }
4949
5050 public MapAgent (Map map , Search search , String goal , EnvironmentViewNotifier notifier ) {
5151 this (map , search , goal );
5252 this .notifier = notifier ;
5353 }
5454
55- public MapAgent (Map map , Search search , String [] goals ) {
55+ public MapAgent (Map map , Search search , List < String > goals ) {
5656 this .map = map ;
5757 this .search = search ;
58- this .goals = new String [goals .length ];
59- System .arraycopy (goals , 0 , this .goals , 0 , goals .length );
58+ this .goals .addAll (goals );
6059 }
6160
62- public MapAgent (Map map , Search search , String [] goals , EnvironmentViewNotifier notifier ) {
61+ public MapAgent (Map map , Search search , List < String > goals , EnvironmentViewNotifier notifier ) {
6362 this (map , search , goals );
6463 this .notifier = notifier ;
6564 }
6665
67- public MapAgent (Map map , Search search , String [] goals , EnvironmentViewNotifier notifier ,
66+ public MapAgent (Map map , Search search , List < String > goals , EnvironmentViewNotifier notifier ,
6867 HeuristicFunctionFactory hfFactory ) {
6968 this (map , search , goals , notifier );
7069 this .hfFactory = hfFactory ;
@@ -76,17 +75,15 @@ public MapAgent(Map map, Search search, String[] goals, EnvironmentViewNotifier
7675 @ Override
7776 protected State updateState (Percept p ) {
7877 DynamicPercept dp = (DynamicPercept ) p ;
79-
8078 state .setAttribute (DynAttributeNames .AGENT_LOCATION , dp .getAttribute (DynAttributeNames .PERCEPT_IN ));
81-
8279 return state ;
8380 }
8481
8582 @ Override
8683 protected Object formulateGoal () {
8784 Object goal = null ;
88- if (currGoalIdx < goals .length ) {
89- goal = goals [ currGoalIdx ++] ;
85+ if (currGoalIdx < goals .size () - 1 ) {
86+ goal = goals . get (++ currGoalIdx ) ;
9087 if (notifier != null )
9188 notifier .notifyViews ("CurrentLocation=In(" + state .getAttribute (DynAttributeNames .AGENT_LOCATION )
9289 + "), Goal=In(" + goal + ")" );
@@ -129,9 +126,8 @@ private void modifyHeuristicFunction(Object goal) {
129126 ef = ((BestFirstSearch ) search ).getEvaluationFunction ();
130127 else if (search instanceof RecursiveBestFirstSearch )
131128 ef = ((RecursiveBestFirstSearch ) search ).getEvaluationFunction ();
132- if (ef instanceof HeuristicEvaluationFunction ) {
129+ if (ef instanceof HeuristicEvaluationFunction )
133130 ((HeuristicEvaluationFunction ) ef ).setHeuristicFunction (hfFactory .createHeuristicFunction (goal ));
134- }
135131 }
136132 }
137133}
0 commit comments