For this homework you will re-implement your Action Castle game from Homework 1 but turning it into a task-oriented dialog system, specifically in the form of a “Skill” for Amazon Alexa. You will be able to reuse a lot of the code you wrote in Homework 1, but the focus of this homework will be to implement commands using Alexa Intents and a command parser by creating Alexa Request Handlers. You can use the original Action Castle game, or if you want to be creative, you can implement any other interactive fiction game you would like. We will play all of your games and give full credit if there are no errors in the flow of the game.
You will not be using Colab for this assignment.
Before we explain what you will be doing, there are first some Alexa-specific terms we need define.
We have provided starter code for an Alexa adventure game. You are free to modify it however you want and bring in any dependencies you feel will be useful, but do not forget to add them to requirements.txt
.
lambda_function.py
file contains all of the Request Handlers. Add your Request Handlers here.game_classes.py
and game_utils.py
hold all of the Action Castle code. Put your game code here.constants.py
is just a list of global constants you want the entire application to have access to. You might not need this.utils.py
unless you want to add extra utilities.Sign in to the Alexa Developer Console (see image above).
Then click on “Create Skill”. Select the Custom Model and Alexa Hosted (Python) options. In the next page select the Start from Scratch option. Once you create your skill, click on it and go on the Code
tab. There you can copy and paste the template files we gave you in lambda.zip
, or even better, you can use Python’s import
functionality.
You will be defining a set of Amazon Intents and implementing Request Handlers to parse them. You may find it useful to look into the ASK Skills Documentation.
In lambda_function.py
, each Request Handler has its own class, and within that class there is a can_handle()
function and a handle()
function. can_handle()
is where you specify the Intent (aka the keywords) to trigger this. handle()
is what will happen when it’s triggered.
Add a new Handler class for each command and then add it to the SkillBuilder()
at the end of the file with the command sb.add_request_handler(yourHandlerClass())
.
Note: We have implemented the “direction” Request Handler for you (lines 30-70 of lambda_function.py
). You will still have to implement the Intents in the Interaction Model. You can use the “direction” Request Handler as a guide for creating other Request Handlers.
Once you have your Handlers all setup, you need to add them to the Interaction Model as Intents. You can find the Intents in the Developer Console by going to the “Build” tab, selecting “Interaction Model” and then “Intents”. The Intents page should look something like this:
ask_utils.is_request_type(type)(handler_input)
: checks if the Request type is equal to the input type.ask_utils.is_intent_name(name)(handler_input)
: checks if the Request Intent name is equal to the input name.ask_utils.request_util.get_slot(handler_input, slot_name)
: returns an object of the Slot with name slot_name. You can use obj.value to get the string name of the Slot.open action castle
In order to submit your code, you should invite the TAs as beta testers. Here are the instructions on how to do this. Our emails are:artemisp@seas.upenn.edu
& ldugan@seas.upenn.edu
. When you release a Skill for beta testing you need to complete the Privacy and Compliance Component. You can safely answer no to all those questions.
You should invite the TAs to be beta testers for your Skill, as instructed in the relevant section above. You should also submit:
playthrough.txt
with all of the commands that we would need to complete your game. It shold be a plain text file with one command per line.lambda.zip
that contains the code for your game.Submissions should be done on Gradescope.
Amazon Alexa, Your First Alexa Skill.
Chris Ainsley / Adventuron Software Limited, Adventuron Classroom. This is a tutorial aimed at teaching elementary school kids how to program by writing a text adventure game. I modeled our text adventure game after this Adventuron system.
The Hitchhiker’s Guide to the Galaxy (H2G2), How to Make a Text-Based Adventure - Commands and Parser.