Lesson 3 Project: Dungeon Crawler
Deepseek is a master at playing role playing games. If you ask it to come up with a scenario and play a game with you, it will be more than happy to do so. In today's project, we're going to figure out how to get it to play a dungeon crawling role playing game with us.
We will be utilizing the following topics:
- Prompt Patterns
- The Deepseek API
- Prompt Roles
- JSON Responses
- Conversations with API
Instructions
The Prompt Pattern
This project is going to be an upgrade from the standard chatbot code that we gave you before. In this project, Deepseek will respond using JSON instead of standard messages.
We want it to respond with a JSON that includes a description of what's happening, as well as a list of actions that the player can take. These are numbered actions, such as
Come up with a setting for your dungeon crawler game. It could be that a dragon is threatening to burn down a village. Or you could make it about anything. Have one set in space. Your imagination is the limit.
The Program
This program is more complicated than our previous chatbot code. We will give you the skeleton code for this program.
Deepseek
- Locate the comment labeled "DEEPSEEK TASK".
- Call Deepseek using the JSON method and give it the chat history.
- Save Deepseek's JSON response into a variable named .
assistant_response - Print out the description of .
assistant_response - Add the description of to
assistant_response. Remember to put it under the assistant role.chat_history
User
- Locate the comment labeled "USER TASK".
- Iterate through every element in the action field of . Print out each action.
assistant_response - Ask the user to enter in a number. Keep asking the user to enter a number until they enter a valid option from the action list.
- Once the user has entered a valid option, get the action corresponding to the number they entered.
- Add the action to . Remember to put it under the user role.
chat_history
How to Use
Here's an example on how the program should look. Here we simulate 5 responses between the two characters.
Extend Your Project
- Give your character stats like HP and defense. What do you have to change to get this done?
- Maybe you could have Deepseek play its own game. How would you make it so that a character like Spongebob plays the RPG instead of you?