Simple reactive agent World: agent-cistic.zip - Environment in Java. We will work with reactive agents in simple world implemented in Java. World is static, deterministic and contains only one agent. It is a room with obstacles and dirties, which should be cleaned by the agent. The world is implemented as two dimensional array of integers, where: 0 = clean 1 = dirty 2 = wall(obstacle) For visualization of the world we have a simple GUI. World can be fixed or random. The textfile 'world.txt' describes random world in the following form: 1. First row contains a string. If it is "random", dirties and walls are generated randomly. 2. Second row is an integer = width of the world. 3. Third row is an integer = height of the world. 4. Fourth row is an float = probability of dirt occurence. 5. Fifth row is an float = probability of wall occurence. The textfile 'reactive.txt' describes fixed world in the following form: 1. First row is empty. 2. Second row is an integer W = width of the world. 3. Third row is an integer H = height of the world. 4. Follows H lines, each conisting of W characters of the form: o '#': denotes WALL tile o ' ': denotes CLEAN tile o '*': denotes DIRTY tile o '@': denotes AGENT's starting position on CLEAN tile o '0': denotes AGENT's starting position on DIRTY tile Agent: Agent has only one sensor that is implemented by the percept() method. This method returns a two-dimensional (2n+1)x(2n+1) array of integers, where n is agent's perception (parameter describing agent's horizon). Agent's percept may be 0 as well as bigger than the size of the world. In the first case, agent sees only only its actual tile. In the second case, everything outside the boundaries of the world is seen as WALL. The percept size of the agent can be acquired by the getPerceptSize() method. The first line of the percept array always represent the north side of percepted area. The orientation of agent can be acquired by the getOrientation() method which returns numbers 0 (World.NORTH), 1 (World.EAST), 2 (World.SOUTH, 3 (World.WEST). Agent's starting orientation in random worlds is random as well. In fixed worlds it is fixed to the North. Agent knows dimensions of the world. These can be found in the MyAgent's constructor. Agent's actuators are implemented by methods: moveFW() (one step forward according to agent's orientation) turnLEFT() rotating 90° left turnRIGHT() rotating 90° right suck(), which cleans agent's position from dirty Actuators should be called in the method act(), which is executed regularly in a given time period. At most one of the actuator's method should be executed during the act() execution, otherwise program will be halted with an exception. The method halt() terminates the program and displays the number of executed actions (actuator's methods). We will not use it in this exercise. Download and unzip agent-cistic.zip. Eclipse(Indigo) project import: 1. 2. 3. 4. 5. File->Import General->Existing Projects into Workspace Select root directory -> Browse choose folder "agent-cistic" Finish Running Eclipse(Indigo): 1. 2. 3. 4. Run->Run Configurations... double click on "Java Applications" in tab "Main" choose/write 'GuiStarter' for the main class in tab "Arguments" copy "world.txt WAIT-TIME PERCEPT-SIZE" into Program arguments text-box, where WAIT-TIME is time between two agent's steps in milliseconds and PERCEPT-SIZE is length of agent's horizon. 5. Apply, Run Exercise (1 point): Implement a simple reflex (reactive) agent, that is able to clean the environment (That is, given an unlimit amount of time, the world will be clean). Agent cannot store anything (except of the current percept), it should act according to actual percept and orientation only. An agent does not have to halt but can not loop or get stuck. Implement the agent for different PERCEPT-SIZE (0, 1). In both cases agent has to suck dirties below the agent, and with PERCEPTSIZE=1 agent furthermore must be able to move to the Agents and environments - Goal-oriented agent agent-cistic.zip - Environment in Java. We will work in the Agent-cleaner environment. Observe that: MyAgent has a constructor with world's height and width arguments. Use them appropriately. Screen of the world will be saved into agent-cistic/screen.png, if an agent is halted with halt() method. Today, we are interested in goal-oriented agent, that will use simple path-finding algorithm for finding the shortest path between two tiles. Goal-oriented agent has an internal state, so it can create its own model (map) of the world and remember anything. However, it is still allowed to perform only one call of the method percept() and one action (method moveFW(), turnLEFT(),turnRIGHT() or suck()). Exercise Consider the problem of agent-cleaner and define what correspond to following terms: state, state space. Assume that agent only moves forward, turns left and right (that is, it can not suck dirties). How many states correspond to the following two-tiled-world? Draw the whole state space diagram. The breadth-first search can be described with the following pseudocode: OPEN - the queue of states that will be visited CLOSE - the set of already visited states State - variable containg state that is currently visited SucState - variable containg a successor state of State 1. OPEN = {starting-state} 2. CLOSE = {} 3. WHILE (OPEN IS NOT EMPTY) 4. State = get and remove first element from OPEN 5. if (State ∉ CLOSE) 6. add State to CLOSE 7. 8. 9. 10. 11. if (State is our goal) return path from starting-state to State for all successors SucState of State if (SucState ∉ CLOSE) add SucState as last to OPEN 12. return failure Exercise Which data structures are useful for efficient BFS implementaion? You may findthis survey of data structures helphul. How can the path (line 8) be computed? Exercise Assume the two-tiled map with the starting state as on picture above and the set of goal states where the agent is on the right tile. Simulate the breadth-first search and write actual content of OPEN and CLOSE lists. Exercise Set the agent's percept to 8. Implement the breadth-first search and use it for navigation to the lower left corner of the 'reactive.txt' world. How much actions did agent perform? Is it the shortest path? Exercise Implement a new method void updateMap(int[][] percept) that will gradually create the map of the world. That is, the part of the agent's map is rewritten by the current percept. Test your solution by printing agent's map and running the agent with percept=1 on the 'reactive.txt' world. Exercise (1 point, Monday) In this exercise, assume that agent can move to the next tile only if it is not wall and the next tile is horizontally or vertically adjacent with wall. That is, if the next tile is clean but the upper, lower and tiles on the left and the right are not walls, the tile is not reachable. Set the agent's percept to 20. Implement the breadth-first search and use it for cleaning the 'catmove.txt' world from the dirty. Exercise (1 point, Wednesday) In this exercise, assume that agent can not suck and is able to move only from dirty tile to clean one and vice versa. Set the agent's percept to 20. Implement the breadth-first search and use it for navigation to the upper left corner of the 'sachovnica.txt' world. Program will be tested only on the 'sachovnica.txt' world, therefore the coordinations of the goal tile can be hard coded. Exercise (1 point, Thursday) In this exercise, assume that agent is able to move to the next tile only if it is not wall and the next tile is horizontally or vertically adjacent at most with one wall. That is, if the next tile is adjacent with two or more walls, the tile is not reachable. Set the agent's percept to 20. Implement the breadth-first search and use it for cleaning the 'claustrophobic.txt' world from all dirties. At the end, agent should halt. horizontally/vertically (diagonals are not necessary) adjacent dirty tiles. Agent will be tested on the 'reactive.txt' map.