uchicago-cs / chiventure

A text adventure game engine developed in UChicago's CMSC 22000 - Introduction to Software Development
40 stars 13 forks source link

dsl: implement npc (aside from dialogue) based on design document) #1254

Closed wzeng0 closed 2 years ago

wzeng0 commented 2 years ago

Link to design document is here

We want to implement this design into the DSL parser. For the sake of making this task more manageable, we've split it up into having one task for the npc and its properties and items, and another task for the NPC's dialogue (which is likely to be a more difficult task).

The NPC dialogue implementation task is #1420 The NPC grammar task (that has been closed) is #1343 The NPC grammar specification pull request is #1410

team members: andi, jay, william

awliu2 commented 2 years ago

Making progress on dsl/npc-support-modified branch. Currently implemented grammar rules and the intermediate conversion to a dictionary. Now I need to work on conversion to JSON.

wzeng0 commented 2 years ago

Updated dsl_parser.py to be able to take in NPCS and places all its values in a dictionary. Right now, we are supporting only short description, long description, age, gender, and inventory.

awliu2 commented 2 years ago

More progress is being made (in dsl/npc-support-modified). We now support the inventory of items, and we also fixed some bugs (such as NPCs only being able to be defined at the bottom of the DSL file). We've generated an npc.wdl file as a proof-of-concept and included it in the examples/wdl subdirectory, along with an npc.dsl file in the examples/dsl subdirectory.

awliu2 commented 2 years ago

This:

"""
dsl definitions of the game and the rooms here
"""
NPC OAK IN room B
  short desc: "Kanto's premier Pokemon expert"
  long desc: "Enjoys exploring human-Pokemon relationships"
  age: "25"
  gender: "Male"
  INVENTORY
    item_id1: "CHARMANDER"
    item_id2: "SQUIRTLE"
    item_id3: "BULBASAUR"
    item_id4: "POKEBALL"

ITEM CHARMANDER IN OAK
  short desc: "A fire pokemon"
  long desc: "Prefers hot places. When it rains, steam is said to spout from the tip of its tail." 

ITEM SQUIRTLE IN OAK
  short desc: "A water pokemon"
  long desc: "After birth, its back swells and hardens into a shell. Powerfully sprays foam from its mouth." 

ITEM BULBASAUR IN OAK
  short desc: "A grass Pokemon"
  long desc: "It can go for days without eating a single morsel. In the bulb on its back, it stores energy."

ITEM POKEBALL IN OAK
  short desc: "A pokeball"
  long desc: "A pokeball used to capture pokemon"
  actions: TAKE
    TAKE success: "You take the pokeball"
    TAKE fail: "You cannot take the pokeball"

generates this:

{
  "GAME": {
    "start": "room B",
    "end": {
      "in_room": "room C"
    },
    "intro": "Welcome!"
  },
  "ROOMS": {
    "room B": {
      "short_desc": "A dungeon room.",
      "long_desc": "The walls are damp and moldy and, yet, the scent of freshly\n    cut lavender flowers pervades the air.",
      "connections": [
        {
          "direction": "NORTH",
          "to": "room A"
        },
        {
          "direction": "EAST",
          "to": "room C"
        }
      ],
      "NPCS": [
        "OAK",
        {
          "location": "room B",
          "short desc": "Kanto's premier Pokemon expert",
          "long desc": "Enjoys exploring human-Pokemon relationships",
          "age": "25",
          "gender": "Male",
          "INVENTORY": {
            "item_id1": "CHARMANDER",
            "item_id2": "SQUIRTLE",
            "item_id3": "BULBASAUR",
            "item_id4": "POKEBALL"
          }
        }
      ],
      "items": [
        "CHARMANDER",
        "SQUIRTLE",
        "BULBASAUR",
        "POKEBALL"
      ],
      "npcs": []
    }
  },
  "ITEMS": {
    "POKEBALL": {
      "short_desc": "A pokeball",
      "long_desc": "A pokeball used to capture pokemon",
      "actions": [
        {
          "action": "TAKE",
          "text_success": "You take the pokeball",
          "text_fail": "You cannot take the pokeball"
        }
      ],
      "in": "OAK"
    },
    "BULBASAUR": {
      "short_desc": "A grass Pokemon",
      "long_desc": "It can go for days without eating a single morsel. In the bulb on its back, it stores energy.",
      "in": "OAK",
      "actions": []
    },
    "SQUIRTLE": {
      "short_desc": "A water pokemon",
      "long_desc": "After birth, its back swells and hardens into a shell. Powerfully sprays foam from its mouth.",
      "in": "OAK",
      "actions": []
    },
    "CHARMANDER": {
      "short_desc": "A fire pokemon",
      "long_desc": "Prefers hot places. When it rains, steam is said to spout from the tip of its tail.",
      "in": "OAK",
      "actions": []
    }
  },
  "NPCS": {}
}
awliu2 commented 2 years ago

We've been continuing to work on this issue, and ironing out any bugs. Hopeful to get a pull request in by thursday night.

jhsivadas commented 2 years ago

Current WDL output file. Seems to be working fully going to run some tests and then if working put in a pull request.

DSL File

GAME START lab END room other
    intro: "Welcome!"

ROOM lab
    short desc: "Oak's lab."
    long desc: "Professor Oak's lab in Pallet Town"
    connections: NORTH TO room other
        EAST TO room house

    ITEM COMPUTER IN lab
    short desc: "A computer."
    long desc: "A computer in Oak's lab"

ROOM gym
    short desc: "Brock's Gym"
    long desc: "Gym Leader Brock's gym in Pewter City"
    connections: NORTH TO room house
        EAST TO room lab

ROOM house
    short desc: "Oak's house."
    long desc: "Professor Oak's house in Pallet Town"
    connections: NORTH TO room lab
        EAST TO room other

ITEM CHARMANDER IN OAK
  short desc: "A fire pokemon"
  long desc: "Prefers hot places. When it rains, steam is said to spout from the tip of its tail." 

ITEM SQUIRTLE IN OAK
  short desc: "A water pokemon"
  long desc: "After birth, its back swells and hardens into a shell. Powerfully sprays foam from its mouth." 

ITEM BULBASAUR IN OAK
  short desc: "A grass Pokemon"
  long desc: "It can go for days without eating a single morsel. In the bulb on its back, it stores energy."

ITEM POKEBALL IN OAK
  short desc: "A pokeball"
  long desc: "A pokeball used to capture pokemon"
  actions: TAKE
    TAKE success: "You take the pokeball"
    TAKE fail: "You cannot take the pokeball"

NPC OAK IN lab
  short desc: "Kanto's premier Pokemon expert"
  long desc: "Enjoys exploring human-Pokemon relationships"
  age: "80"
  gender: "Male"
  INVENTORY
    item_id1: "CHARMANDER"
    item_id2: "SQUIRTLE"
    item_id3: "BULBASAUR"
    item_id4: "POKEBALL"

NPC ASH IN other
  short desc: "Pokemon Master"
  long desc: "ASH Ketchum is THE Pokemon Master"
  age: "10"
  gender: "Male"

NPC RED IN house
  short desc: "Original player"
  long desc: "Strongest pokemon player of all time"
  age: "25"
  gender: "Male"

WDL File

{
  "GAME": {
    "start": "lab",
    "end": {
      "in_room": "room other"
    },
    "intro": "Welcome!"
  },
  "ROOMS": {
    "house": {
      "short_desc": "Oak's house.",
      "long_desc": "Professor Oak's house in Pallet Town",
      "connections": [
        {
          "direction": "NORTH",
          "to": "room lab"
        },
        {
          "direction": "EAST",
          "to": "room other"
        }
      ],
      "items": [
        "CHARMANDER",
        "SQUIRTLE",
        "BULBASAUR",
        "POKEBALL"
      ]
    },
    "gym": {
      "short_desc": "Brock's Gym",
      "long_desc": "Gym Leader Brock's gym in Pewter City",
      "connections": [
        {
          "direction": "NORTH",
          "to": "room house"
        },
        {
          "direction": "EAST",
          "to": "room lab"
        }
      ],
      "items": []
    },
    "lab": {
      "short_desc": "Oak's lab.",
      "long_desc": "Professor Oak's lab in Pallet Town",
      "connections": [
        {
          "direction": "NORTH",
          "to": "room other"
        },
        {
          "direction": "EAST",
          "to": "room house"
        }
      ],
      "items": [
        "COMPUTER"
      ]
    }
  },
  "ITEMS": {
    "POKEBALL": {
      "short_desc": "A pokeball",
      "long_desc": "A pokeball used to capture pokemon",
      "actions": [
        {
          "action": "TAKE",
          "text_success": "You take the pokeball",
          "text_fail": "You cannot take the pokeball"
        }
      ],
      "in": "OAK"
    },
    "BULBASAUR": {
      "short_desc": "A grass Pokemon",
      "long_desc": "It can go for days without eating a single morsel. In the bulb on its back, it stores energy.",
      "in": "OAK",
      "actions": []
    },
    "SQUIRTLE": {
      "short_desc": "A water pokemon",
      "long_desc": "After birth, its back swells and hardens into a shell. Powerfully sprays foam from its mouth.",
      "in": "OAK",
      "actions": []
    },
    "CHARMANDER": {
      "short_desc": "A fire pokemon",
      "long_desc": "Prefers hot places. When it rains, steam is said to spout from the tip of its tail.",
      "in": "OAK",
      "actions": []
    },
    "COMPUTER": {
      "short_desc": "A computer.",
      "long_desc": "A computer in Oak's lab",
      "in": "lab",
      "actions": []
    }
  },
  "NPCS": {
    "RED": {
      "location": "house",
      "short_desc": "Original player",
      "long_desc": "Strongest pokemon player of all time",
      "age": "25",
      "gender": "Male"
    },
    "ASH": {
      "location": "other",
      "short_desc": "Pokemon Master",
      "long_desc": "ASH Ketchum is THE Pokemon Master",
      "age": "10",
      "gender": "Male"
    },
    "OAK": {
      "location": "lab",
      "short_desc": "Kanto's premier Pokemon expert",
      "long_desc": "Enjoys exploring human-Pokemon relationships",
      "age": "80",
      "gender": "Male",
      "INVENTORY": {
        "item_id1": "CHARMANDER",
        "item_id2": "SQUIRTLE",
        "item_id3": "BULBASAUR",
        "item_id4": "POKEBALL"
      }
    }
  }
}
awliu2 commented 2 years ago

Pull request created: https://github.com/uchicago-cs/chiventure/pull/1653

jacknugent1529 commented 2 years ago

Issue Score: Excellent

Comments: Nice work on this issue! It was spread out over two sprints, but it looks like you were able to work through the problems you encountered, and the comments documented your progress very well.