Homework 1: 60 points For each of the two following problems, design a finite state machine (FSM) that will make the robot solve the problem. This means that you must specify the states, and which state is the start state. For each state, define the Execute action. This will usually consist of one of the allowed actions specified for the problem, and one of more if-then statements that call ChangeState to get to the next state. When appropriate, specify Entry actions and Exit actions. 1. Consider this robot-lightbulb problem. There is a room with a lightbulb on the ceiling of the room. In the room is a robot and a chest. Inside the chest is a cane. The robot wants to break the lightbulb. It can't do it while standing on the floor, and it can't do it while standing on the closed chest unless it is holding the cane so that it can swing the cane at the lightbulb. Design an FSM that will solve this problem. In your FSM, you can assume the availability of the following tests: sameLocation(X,Y) - X is at the same location as Y. (If X is next to Y or X is underneath Y or Y is underneath X, then sameLocation(X,Y) is true.) Possible values for X and Y are robot, chest, cane, bulb. on(robot,Y) - robot is on Y. The only values of Y that are relevant are Y = floor or Y = chest. holding(robot,cane) - robot is holding cane. open(chest) - chest is open. The chest is closed when it is not open. broken(bulb) - the bulb is broken, which is what the robot wants. These can be tested for being true or for being false. (In other words, you can use the not function when appropriate.) The actions that are available are: swing(robot,X,Y) - robot swings X at Y, breaking Y if the conditions are right. push(robot,X,Y) - robot pushs object X to the same location as Y. It is assumed that if the cane is in the chest, the location of the cane is the same as the location of the chest. This cannot be done while holding the cane. The chest can be pushed only when it is closed. climb(robot,chest) - robot climbs onto the chest. This can be done while holding the cane. makeOpen(robot,chest) - robot opens the chest. makeClosed(robot,chest) - robot closes the chest. It can do this while holding the cane. goTo(robot,X) - robot goes to the location of X so that they are at the same location. grab(robot,cane) - robot grabs cane if the conditions are right. Assume that initially the cane is in the chest, the chest is closed, and the robot is on the floor. It is not known initially which instances of sameLocation(X,Y) are true. 2. Assume that there is a room represented by a grid of square tiles. The tiles are one unit wide and the coordinates of the center of each tile are integer values. The square room is completely walled in except at location (8,4), which is a door. That door is either open or it is closed. If it is closed, it may be locked or unlocked, but the only way to tell whether it is locked is to try to open it. Next to the door, there is a lock at (8,3). There may be a key on the floor somewhere in the room, located at (Kx,Kz). There is one character (robot) in the room at location (Cx,Cz). Here is a picture of what the room and its contents might look like at the start of the problem: x 0 1 2 3 4 5 6 7 8 0 # # # # # # # # # 1 # # 2 # C # 3 # # z4 # D 5 # # 6 # K # 7 # # 8 # # # # # # # # # As you can see, the room is 7 tiles by 7 tiles of floor space. It is not necessary to implement a representation of this game world. Instead, assume that you have access to the following variables to know about the environment: Cx = x coordinate of the character Cz = z coordinate of the character Kx = x coordinate of the key Kz = z coordinate of the Key D.isOpen = True if the door is open and the character can move through it The location of D is (8,4). The location of D's lock is (8,3). The following actions are possible: move(dx,dz) - This moves C from (Cx,Cz) to (Cx+dx,Cz+dz). Returns True if move was successful. Returns False if move is not successful and Cx,Cz do not change. The character C can move onto the same location as the key, but cannot move onto any location that is occupied by anything else (another character, the closed door or the wall). The values dx and dz can only be 1, 0 or -1. Diagonal moves are allowed except when passing through the open door. Note that C can move to location (8,4) only if it is at location (7,4) and D is open. pickupKey() - C picks up key, provided Cx == Kx and Cz == Kz. Returns True if successful, False otherwise. Once key is picked up, the key moves with C until it is put in the lock. (However, you do not have to keep track of where the key is once it is picked up. That would be taken care of by the game physics if this game were implemented.) unlock() - This is successful only if C has the key and (Cx,Cz) == (7,3). It makes the door D unlocked (if it wasn't already). openDoor() - If D is not open but is unlocked and (Cx,Cz) == (7,4), D becomes open and the openDoor() succeeds. Otherwise it fails and returns False. Write a finite state machine for C such that no matter where C and K are in the room initially and what the state of the door is, C can get out of the room to location (9,4). Use the variables and actions listed above as part of your tests and actions in the FSM. Note: you just have to describe the states and the transitions of the machine.