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

  1. Locate the comment labeled "DEEPSEEK TASK".
  2. Call Deepseek using the JSON method and give it the chat history.
  3. Save Deepseek's JSON response into a variable named
    assistant_response
    .
  4. Print out the description of
    assistant_response
    .
  5. Add the description of
    assistant_response
    to
    chat_history
    . Remember to put it under the assistant role.

User

  1. Locate the comment labeled "USER TASK".
  2. Iterate through every element in the action field of
    assistant_response
    . Print out each action.
  3. 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.
  4. Once the user has entered a valid option, get the action corresponding to the number they entered.
  5. Add the action to
    chat_history
    . Remember to put it under the user role.

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

  1. Give your character stats like HP and defense. What do you have to change to get this done?
  2. 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?