Skip to main content

Lesson 4: Dynamic Castle Crasher Challenge

In the Dynamic Castle Crasher Challenge, the VR Robot must now knock ALL pieces off of each iteration of the Dynamic Castle Crasher Playground, in the quickest way possible!

A top down view of the Dynamic Castle Crasher playground showing the VR Robot has been moved from its starting position, but all castles have been pushed off of the playground, leaving the playground empty.

Learning Outcome

  • Apply logic of repeated decisions with multiple sensors to solve the Dynamic Castle Crasher Challenge.

Putting It All Together

Algorithms enable a user to create more diverse and efficient projects. Algorithms are precise sequences of instructions that can use selection and iteration to instruct the VR Robot to use information from its environment to execute behaviors.

A top down view of the Dynamic Castle Crasher playground showing the VR Robot in front of a caslte. Red and green lines show the VR Robot's Distance Sensor detecting the castle in front of it.

Algorithms use loops to continually check sensor values, and repeat behaviors. Nesting conditional statements inside loops such as infinite while loops or while loops with a not condition will instruct the VR Robot to continually check those conditions.

def main():
	while True:
		if distance.found_object():
			# Knock over the building found using the Distance Sensor
			drivetrain.drive(FORWARD)
		else:
			# Turn to find a building using the Distance Sensor
			drivetrain.turn(RIGHT)
		wait(5, MSEC)

Selection is employed by using conditional statements such as if else to instruct the VR Robot to execute certain behaviors, depending on reported conditions, such as sensor values.

On the left is the Python code from Lesson 2. On the right is the top down view of the Dynamic Castle Crasher playground with the playground interface visible. The Distance Sensor's measurement on the playground interface reads 568 mm and is highlighted with a red box. This shows that the castle in the middle of the playground is 568 millimeters from the VR Robot.

On the left is the Python code from Lesson 2. On the right is the top down view of the Dynamic Castle Crasher playground with the playground interface visible. The Distance Sensor's measurement on the playground interface reads 1354 mm and is highlighted with a red box. This shows that the castle at the top of the playground is 1354 millimeters from the VR Robot.

Using sensors with loops and selection enables the VR Robot to interact with a changing environment, such as the Dynamic Castle Crasher Playground.

An angled view of the Dynamic Castle Crasher Playground showing all of the castles in the playground that the VR Robot will be knocking over.

Dynamic Castle Crasher Challenge

In this challenge, create a project where the VR Robot uses an algorithm to knock all the castle pieces off of the Dynamic Castle Crasher Playground, in the shortest amount of time possible.

Solving the Dynamic Castle Crasher challenge requires the use of the timer in the Playground Window.

 

Follow these steps to complete the challenge:

  • Create a new project or load a project from previous Lessons in this Unit. If creating a new project, select the Dynamic Castle Crasher Playground when prompted.
  • Rename the project Unit9Challenge.
  • Open the Playground window if it is not already open. Be sure the Dynamic Castle Crasher Playground opens.
  • Add the commands necessary to drive the VR Robot to push all of the building pieces off of the Dynamic Castle Crasher Playground in the shortest amount of time. The VR Robot should not fall off of the Playground.
  • Start the project to test if it works. The algorithm should work regardless of the layout of the Playground.
  • Document the time it took to complete the challenge on a piece of paper.
  • Continue to revise and run the project until the VR Robot successfully completes the Dynamic Castle Crasher Challenge in the shortest time.
  • Save the project once the VR Robot successfully knocks all of the building pieces off of the Dynamic Castle Crasher Playground in record time.

Congratulations! You have successfully completed the Dynamic Castle Crasher Challenge!

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf