Rocket Landing Simulator

Gate Check #4 - Artificial Intelligence
Go Back to the Assignment Description

Part 1 (Overview) - Part 2 (Getting Ready) - Part 3 (AI Logic Part I) - Part 4 (AI Logic Part II) - Part 5 (AI Training)

Let's Build an AI (Part I)

The time has finally come to create the Artificial Intelligence that will pilot your rocket. Download the following files, and make sure they are in the same folder as your code.

Then go ahead and rename rocket_ai_template so that the word "template" is replaced with your first and last name (e.g., rocket_ai_adriandefreitas).

You may (i.e., should) be wondering what these modules contain. Here's a quick rundown:

For now, let's open rocket_ai_[YOUR_NAME] and look at run_autopilot(). Look at how many parameters it has! Basically, this function receives all of the information it needs from your main program to determine what thrusters need to fire, such as:

This function returns a tuple that specifies the amount the rocket should thrust in each direction (left, right, up--in that exact order). Right now, run_autopilot() returns a tuple containing only zeros, which means it is not telling the rocket to fire any thrusters. This is fine for now, but we will obviously need to update it soon.

In order to use run_autopilot(), we need to call it from your main program. Import both of these modules at the top of your main program. Then, go to get_input(), and update this function as follows (using the below logic design as a guide):

# Don't Forget to Import rocket_ai_[YOUR NAME] and ga_helper
import rocket_ai_[YOUR NAME]
import ga_helper

. . .

def get_input():
    global 
    
    1.  Set thrust up, thrust right, and thrust left amounts to 0.0
    
    2.  If the rocket is NOT in the Boost Phase:
        2a.  ai_decision = ga_ai_[YOUR NAME].run_autopilot(give it all the parameters it needs)
        2b.  Set thrust up, thrust right, and thrust left to the values contained in ai_decision
    
    # COMMENT OUT ALL OF THE BELOW CODE
    #2.  If the rocket is NOT in the Boost Phase:
    #    2a.  If the player is holding down the left key, set the left thruster to amount to some small value (<0.5)
    #    2b.  If the player is holding down the right key, set the right thruster to amount to some small value (<0.5)
    #    2c.  If the player is holding down the up key, set the up thruster amount to some small value (<0.5) 

Testing

If you were to press play at this point, your rocket would simply fall into the ocean. Try modifying run_autopilot() so that it returns a non-zero tuple (e.g., (1.0, 0.0, 0.0)). If you did the above correctly, you should see that your function now has direct control over the rocket's thrusters. Now, all we need to do is add some intelligent logic so that the autopilot actually directs the rocket to the boat. This will be discussed on the following page.

Proceed to the next section.