makebecisionForTask2() function in this ta: n this task, the exit may be to the left or to the right of the robot n the previous task, the exit can only be on the right so this task is a little more difficult to do than th Previously, the robot searches for the exit by turning to the right only Now, in this task, rather than just the right hand side, you also need to make the robot search the le You can extend the idea from the previous task to something like this Step 1. The robot moves north until there is a wall above a If the robot sees a wall above, it turns east (go to step 2) and searches for the exit Step 2. The robot moves east, searches for the exit until there is a wall on the east a If the exit is found (ie. no wall above), the robot will go north (back to step 1) and movet b. If the robot sees a wall on the east, it turns around (go to step 3) and searches for the ex Step 3. The robot moves west and searches for the exit a If the exit is found (i e. no wall above), the robot will go north (back to step 1) and move t You need to add one more state which asks the robot to move west, with the appropriate transition Then, the above logic can be represented by the following state diagram Action: NONE Condition: If connot move north Go north Go east Action: EAST Action: NORTH Action: NONE Action: NONE Condition: If can move north Condition: If cannot move east Action: NONE Condition: If can move north Go west Action: WEST

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 13PE
icon
Related questions
Question
Make sure you write the code inside the makeDecisionForTask2() function in this task!
• In this task, the exit may be to the left or to the right of the robot
• In the previous task, the exit can only be on the right so this task is a little more difficult to do than the previous one
Previously, the robot searches for the exit by turning to the right only
• Now, in this task, rather than just the right hand side, you also need to make the robot search the left hand side
• You can extend the idea from the previous task to something like this:
Step 1. The robot moves north until there is a wall above
a If the robot sees a wall above, it turns east (go to step 2) and searches for the exit
Step 2. The robot moves east, searches for the exit until there is a wall on the east
a If the exit is found (ie. no wall above), the robot will go north (back to step 1) and move to the exit
b. If the robot sees a wall on the east, it turns around (go to step 3) and searches for the exit
Step 3. The robot moves west and searches tor the exit
a. If the exit is found (ie. no wall above), the robot will go north (back to step 1) and move to the exit
• You need to add one more state which asks the robot to move west, with the appropriate transitions
Then, the above logic can be represented by the following state diagram
Action: NONE
Condition: If cannot move north
Action: NORTH
Go north
Go east
Action: EAST
Action: NONE
Condition: if connot move east
Action: NONE
Condition: If can move north
Action: NONE
Condition: If can move north
Go west
Action: WEST
• In this task, you need to write the code to put the above diagram in the makeDecisionForTask2() function
• The state of the diagram is then stored inside the currentStateForTask2 variable
• You can use the "NEXT STEP" button below to visualize each step the robot should make
Transcribed Image Text:Make sure you write the code inside the makeDecisionForTask2() function in this task! • In this task, the exit may be to the left or to the right of the robot • In the previous task, the exit can only be on the right so this task is a little more difficult to do than the previous one Previously, the robot searches for the exit by turning to the right only • Now, in this task, rather than just the right hand side, you also need to make the robot search the left hand side • You can extend the idea from the previous task to something like this: Step 1. The robot moves north until there is a wall above a If the robot sees a wall above, it turns east (go to step 2) and searches for the exit Step 2. The robot moves east, searches for the exit until there is a wall on the east a If the exit is found (ie. no wall above), the robot will go north (back to step 1) and move to the exit b. If the robot sees a wall on the east, it turns around (go to step 3) and searches for the exit Step 3. The robot moves west and searches tor the exit a. If the exit is found (ie. no wall above), the robot will go north (back to step 1) and move to the exit • You need to add one more state which asks the robot to move west, with the appropriate transitions Then, the above logic can be represented by the following state diagram Action: NONE Condition: If cannot move north Action: NORTH Go north Go east Action: EAST Action: NONE Condition: if connot move east Action: NONE Condition: If can move north Action: NONE Condition: If can move north Go west Action: WEST • In this task, you need to write the code to put the above diagram in the makeDecisionForTask2() function • The state of the diagram is then stored inside the currentStateForTask2 variable • You can use the "NEXT STEP" button below to visualize each step the robot should make
This is the function for task 0
def makeDecisionForTask0():
return "NORTH"
#This is the function for task 1
def makeDecisionForTaskl():
global currentStateForTaskl
if currentStateForTaskl = "Go north":
if northisWal1():
currentStateForTaskl = "Go east"
return "EAST"
else:
return "NORTH"
elif currentStateForTaskl = "Go cast":
if not northlsWal1):
currentStateForTaskl = "Go north"
return "NORTH"
else:
return "EAST"
# This is the function for task 2
def makeDecisionForTask2():
global currentStateForTask2
if currentStateForTask2 = "Go north":
if northlsWal10:
currentStateForTask2 = "Go east"
return "EAST"
else:
return "NORTH"
elif currentStateForTask2 = "Go cast":
if not northisWall():
currentStateForTask2 = "Go north"
return "NORTH"
else:
return "EAST"
if eastIsWall():
currentStateForTask2='Go west'
return "WEST"
else:
return "EAST"
elif currentStateForTask2 = 'Go west':
il not eastIs Wal1():
currentStateForTask"Go north"
return "NORTH"
else:
return "WEST"
Transcribed Image Text:This is the function for task 0 def makeDecisionForTask0(): return "NORTH" #This is the function for task 1 def makeDecisionForTaskl(): global currentStateForTaskl if currentStateForTaskl = "Go north": if northisWal1(): currentStateForTaskl = "Go east" return "EAST" else: return "NORTH" elif currentStateForTaskl = "Go cast": if not northlsWal1): currentStateForTaskl = "Go north" return "NORTH" else: return "EAST" # This is the function for task 2 def makeDecisionForTask2(): global currentStateForTask2 if currentStateForTask2 = "Go north": if northlsWal10: currentStateForTask2 = "Go east" return "EAST" else: return "NORTH" elif currentStateForTask2 = "Go cast": if not northisWall(): currentStateForTask2 = "Go north" return "NORTH" else: return "EAST" if eastIsWall(): currentStateForTask2='Go west' return "WEST" else: return "EAST" elif currentStateForTask2 = 'Go west': il not eastIs Wal1(): currentStateForTask"Go north" return "NORTH" else: return "WEST"
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT