66import aima .core .environment .wumpusworld .Room ;
77import aima .core .environment .wumpusworld .WumpusCave ;
88import aima .core .environment .wumpusworld .WumpusEnvironment ;
9+ import javafx .scene .Node ;
910import javafx .scene .layout .Pane ;
1011import javafx .scene .layout .StackPane ;
1112import javafx .scene .paint .Color ;
@@ -57,12 +58,12 @@ protected void update() {
5758 }
5859 }
5960
60- // visualize agent position
61- List <Agent > agents = env .getAgents ();
62- if (!agents .isEmpty ()) {
63- AgentPosition pos = wEnv .getAgentPosition (agents .get (0 ));
61+ // visualize agent positions
62+ for (Agent agent : wEnv .getAgents ()) {
63+ AgentPosition pos = wEnv .getAgentPosition (agent );
6464 Pane pane = getSquareButton (pos .getX (), pos .getY ()).getPane ();
65- addAgentMarker (pane , agents .get (0 ).isAlive () ? Color .RED : Color .LIGHTGRAY , pos .getOrientation ());
65+ pane .getChildren ().add (createAgentSymbol (pane , agent .isAlive () ? Color .RED : Color .LIGHTGRAY ,
66+ pos .getOrientation ()));
6667 }
6768 }
6869
@@ -74,33 +75,32 @@ protected void onEdit(int x, int y) {
7475 actionLabel .setText ("Cave can only be edited after initialization." );
7576 else if (!room .equals (cave .getStart ().getRoom ()) && !room .equals (cave .getGold ())) {
7677 if (cave .isPit (room )) {
77- if (cave .getWumpus ().equals (room )) {
78+ if (cave .getWumpus ().equals (room ))
7879 cave .setPit (room , false );
79- } else {
80+ else
8081 cave .setWumpus (room );
81- }
8282 } else {
8383 cave .setPit (room , true );
8484 }
8585 update ();
8686 }
8787 }
8888
89- private void addAgentMarker (Pane pane , Color color , AgentPosition .Orientation orientation ) {
89+ private Node createAgentSymbol (Pane pane , Color color , AgentPosition .Orientation orientation ) {
9090 int size = squareSize .get () / 2 ;
91- Polygon marker = new Polygon (-size / 3 , size , size / 3 , size , 0 , 0 );
92- marker .setFill (color );
91+ Polygon result = new Polygon (-size / 3 , size , size / 3 , size , 0 , 0 );
92+ result .setFill (color );
9393 switch (orientation ) {
9494 case FACING_EAST :
95- marker .setRotate (90 );
95+ result .setRotate (90 );
9696 break ;
9797 case FACING_SOUTH :
98- marker .setRotate (180 );
98+ result .setRotate (180 );
9999 break ;
100100 case FACING_WEST :
101- marker .setRotate (270 );
101+ result .setRotate (270 );
102102 break ;
103103 }
104- pane . getChildren (). add ( marker ) ;
104+ return result ;
105105 }
106106}
0 commit comments