You may write your agent from scratch or utilize the objects in the code repository provided with the textbook (with this caveat). I recommend that you draw on the pseudocode in the book to help design your agent. If you use the step names in the book such as Interpret-Input and Rule-Action (p. 47), it will be easy to extend your agent with new capabilities or port it to different applications in the future.
Input: The percepts will be provided to the agent in a file, with one perception per line, and the perceptions will be represented as integers with a minimum value of 0 and maximum value of 20. The agent should accept its input file via stdin so that we can test the agent with different input files. The agent needs to run at the command ReflexRover like so (without the parens around the file name of course):
% ReflexRover < < filename >
A sample input file is provided here.
We have provided a function that reads the input file and provides percepts to the agent. The code is available in C++, Perl, Java, Lisp, C, Python, Resolve.
Output: The agent should output the percept it received at each time step and the action it chose to perform. Output should be to stdout in exactly this format:
Perceived: < X > Action: < action >
An example output sequence is:
Perceived: 1 Action: N
Perceived: 7 Action: N
Perceived: 0 Action: G
Perceived: 6 Action: G
Grading: To receive full credit on this assignment, your program must have a function with this declaration: char SimpleReflexAgent(int percept) that returns a character representing the action it took, and the output produced must be appropriate given the input file (we will use a different input file when we test your program).
A reflex agent with state (25 points) |
The picture above shows the sort of hardware platform you should imagine your software is controlling. A soil probe reads the soil composition at the rover's CURRENT location, and the camera looks out in front of the rover to plan its locomotion. Locations are descretized into a grid of x,y coordinates. The grid has only 2 rows (a top and bottom location) in each column, but it can have any number of columns. The grid has the standard cartesian orientation, with the southern-most row in row 1 (y=1), and the Westernmost column in column 1 (x=1). The robot's soil probe returns the same set of values as in the first part of this assignment. In addition, to plan the agent's movements, we will use the vision sensor that tells the robot whether the direction the camera is currently facing is CLEAR, meaning that the robot can move onto that position, or BOULDER, in which case the robot cannot move onto that grid position. Since the robot might damage itself running into the boulder, we want the robot to look at each location before attempting to move there. The robot must choose the direction to point the camera using the actions LOOKNORTH, LOOKSOUTH, LOOKWEST, LOOKEAST. The visual percept received by the agent depends on the direction the camera is pointing. For example, if the robot is at grid position (1,1) and looks EAST, the robot will see whether square (2,1) is clear or not. The agent should only move onto grid positions that are CLEAR. Movement is accomplished via a repertoire of new movement actions: GONORTH, GOSOUTH, GOEAST, GOWEST,
Beginning from (1,1) (a location that you may hard-code) the robot should traverse the grid and collect rock samples from each CLEAR position only when it perceives a compound that it has not previously collected. You should traverse the grid methodically, for example start at the western end of the grid and proceed by exploring each column, then moving east. You can also hard-code the direction that the camera is pointed at start-up.
Input
The input file for the agent will contain a description of its
environment represented as a grid with either a Boulder or a numeric
soil composition in each position. Since the agent now has two
sensors, the percept for each grid position has two values: the number
for the soil compound located at the robot's present position, and
whether the direction the robot is looking is 'CLEAR' or 'BOULDER'. If
the agent looks toward a direction that is outside of the defined grid
(such as position (0,5) in the example), it will SEE a NULL.
Each row of the grid will be described on a separate line in this format:
row number, then pairs that describe the entries in that row: 'Clear'/'Boulder' and soil compound number
A sample input file is provided here.
Once again, we have provided a function that reads the input file and provides percepts to the agent. C++, Perl, Java, Lisp, C, Python and Resolve.
Here's a map corresponding to the grid in the sample input file:
-------------------------- | B | 9 | B | 1 | 6 | -------------------------- | 0 | 15 | 4 | 4 | B | --------------------------The corresponding positions are:
------------------------------- | 1,2 | 2,2 | 3,2 | 4,2 | 5,2 | ------------------------------- | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | -------------------------------The agent should run at the command-line like so (without parentheses around the file name) :
> StateRover < < filename >
Or alternately if written in a compiled language like java:
> java StateRover < < filename >
Output
The agent should output its current position at each time
step, the perception it received and the action chosen, written to
stdout in exactly this format:
Position: <row,col> Looking: (direction) Perceived: <Num,Status> Action: (action)
as well as a summary line showing how many compounds
were collected and how many moves were made.
An example output sequence is shown below. The agent starts in square (1,1) looking South. Remember that the agent reads its sensors, then prints out the action it is about to do, so the second line of output says 'LOOKEAST', the robot turns its camera east, and the sensor readings shown on the third line reflect the fact that the rover is sill reading the soil sample from position (1,1) and is now getting the vision perception from square (2,1). This output does not necessarily
contain the optimal sequence of actions for the agent:
Position: <1,1> Perceived: <0,NULL> Action: LOOKNORTH Position: <1,1> Perceived: <0,BOULDER> Action: LOOKEAST Position: <1,1> Perceived: <0,CLEAR> Action: GOEAST Position: <2,1> Perceived: <15,CLEAR> Action: GRAB Position: <2,1> Perceived: <15,CLEAR> Action: LOOKWEST Position: <2,1> Perceived: <15,CLEAR> Action: LOOKNORTH ... Total Compounds Collected: 1 Total Moves: 1Grading: To receive full credit on this assignment, your program should include an agent function called ReflexAgentWithState(percept) that returns an action, and the output produced much be appropriate given the input file we will specify for the agent when we test your program.
> submit c630aa lab1 hw1
You can learn about using the submit command by typing man
submit at a unix command prompt. If you cannot get the
submit command to work, you can email your files to the grader,
but please don't use this option unless you're having trouble
with submit.
Important Note Every so often, a student claims to
have submitted their program, yet it does not show up in the grader's submit directory, so I advise you to save the confirmation you receive from submit that shows the time stamp of your submission (and also says where you sent the files).
Also, any
code you use from the repository should be clearly credited. Do not
make it appear to be your own work. Code Repository Disclaimer
The code repository provided by
the textbook authors is most likely very reliable code, however, be
warned that I haven't tested it and don't guarantee that it will work
as described. If you decide to use code from the repository, don't
expect your instructor or the grader to debug it for you.