Next Dining: The Video Game 3

This commit is contained in:
Anthony Wang 2024-02-04 01:23:25 -05:00
parent 1b06311e52
commit 5896b95994
Signed by: a
SSH key fingerprint: SHA256:B5ADfMCqd2M7d/jtXDoihAV/yfXOAbWWri9+GdCN4hQ
2 changed files with 128 additions and 0 deletions

62
engine.py Normal file
View file

@ -0,0 +1,62 @@
import json
import sys
from openai import OpenAI
from termcolor import cprint
client = OpenAI(api_key="12345", base_url="http://boss-baby:8080/v1/")
c = json.load(open(sys.argv[1]))
print(c["description"])
c["player"]["name"] = input("Enter your name: ")
while c["player"]["health"] > 0 and c["player"][c["win"]["property"]] < c["win"]["value"]:
act = input("Enter go or do: ")
if act == "go":
while True:
c["player"]["location"] = input("Choose location from " + str(c["locations"].keys()) + ": ")
if c["player"]["location"] in c["locations"].keys():
break
print("Invalid location. Try again.")
act = "Enter the " + c["player"]["location"]
else:
while True:
act = input("Enter your action (limit 30 chars): ")
if len(act) <= 30:
break
print("Action is", len(act), "chars long. Try again.")
prompt = c["prompt"] + "\n"
prompt += "I am not allowed to use an item that is not in my inventory. Actions that harm me will cause me to lose health points.\n"
prompt += "I am at the " + c["player"]["location"] + " which is " + c["locations"][c["player"]["location"]] + "\n"
prompt += "Player status:\n" + json.dumps(c["player"]) + "\n"
prompt += "NPC statuses:\n" + json.dumps({k: v for k, v in c["npc"].items() if v["location"] == c["player"]["location"]}) + "\n"
prompt += "Player action: " + act + "\n"
prompt += "Please write one single paragraph about what happens due to this action referring to me, the player, in second person. Do not write more than one paragraph. Then, return the player status and NPC statuses updated to reflect changes due to this action. Make sure to meticulously update the states of both the player and the NPCs!"
# cprint(prompt, "green")
stream = client.chat.completions.create(messages=[{"role": "user", "content": prompt}], model="", stream=True)
updated = ""
for chunk in stream:
text = chunk.choices[0].delta.content or ""
if updated == "":
if "\n" in text:
print(text[:text.index("\n")], end="")
updated += text[text.index("\n"):]
print(text, end="")
else:
updated += text
# cprint(updated, "red")
lines = list(filter(lambda i: i != "", updated.split("\n")))
newp = json.loads(lines[1])
newp["location"] = c["player"]["location"]
c["player"] = newp
for k, v in json.loads(lines[3]).items():
c["npc"][k] = v
print(c["player"])
if c["player"][c["win"]["property"]] >= c["win"]["value"]:
print("Congratulations! You won the game!")
else:
print("Oops! You ran out of health!")

66
nd3.json Normal file
View file

@ -0,0 +1,66 @@
{
"description": "Welcome to Next Dining: The Video Game 3! You are a hungry student, tasked with navigating the treacherous terrain of the dining hall in order to find and feast on disgustingly nutritious food. You are currently at the entrance to the dining hall, nervously trying to avoid looking at the Good Evening Lady.",
"prompt": "You are now going to simulate one round of the epic, highly exaggerated, and very, very sarcastic text-based adventure game called Next Dining: The Video Game 3. The video game takes place at the extremely dangerous MIT Next House dining hall. The chefs and dining hall employees are very evil and never act nice or help me. It is very difficult to get food without facing the wrath of the chefs. My goal is to acquire and eat five dishes in the dining hall. I can only food at the Tables and not at any other location, so only increment my meal counter if my location is Tables.",
"player": {
"location": "Entrance",
"meals": 0,
"health": 100,
"inventory": [],
"state": "Happy and unsuspecting of the doom ahead",
"history": []
},
"win": {
"property": "meals",
"value": 5
},
"locations": {
"Entrance": "The entrance to the dining hall, where you have to tap your ID card to enter",
"Stir-fry station": "A station where the chef will make you a bowl of stir-fried noodles after you wait in line for 10 minutes",
"Poki bowl station": "A station with poki bowls",
"Sushi station": "A station with California rolls and vegetarian rolls",
"Omelet station": "A station where the chef will make you an omelet",
"Tables": "Tables where you can sit and eat and nothing else, so you must go to other locations to first obtain food, and also, the tables have dead mice under them which can induce vomiting and health loss"
},
"npc": {
"Soup Nazi": {
"location": "Stir-fry station",
"description": "He is an extremely irritated chef who operates the stir-fry station and always adds way too much sauce to the point that it's a health hazard",
"state": "Cooking stir-fry angrily"
},
"Good Evening Lady": {
"location": "Entrance",
"description": "She guards the entrance and forces you to say Good Evening when you run into her, and if you don't, your health goes straight to 0",
"state": "Guarding the entrance"
},
"Halloween Lady": {
"location": "Tables",
"description": "A dining hall employee who roams around jumpscaring you randomly, which causes your health to plummet immediately to 0",
"state": "Roaming around randomly"
},
"Made2order": {
"location": "Poki bowl station",
"description": "He has a lot of piercings and sarcastically makes generic tasteless poki bowls",
"state": "Making poki bowls"
},
"Randy the Rando": {
"location": "Tables",
"description": "A short dining hall employee who doesn't do much",
"state": "Standing awkwardly at a table"
},
"Fred": {
"location": "Stir-fry station",
"description": "He operates the stir-fry station when Soup Nazi is on break and will insanely put anything in the stir-fry if you tell him to do it",
"state": "On break and scrolling on his phone"
},
"Sushi Stalker Lady": {
"location": "Sushi station",
"description": "She menacingly watches over the sushi station like a hawk and will death stare at you if you take more than 4 pieces of sushi",
"state": "Standing motionless over at thScout food options cautiously."e sushi station"
},
"Paco": {
"location": "Omelet station",
"description": "He makes horrendous omelets where one side is always overcooked and one side is always undercooked, and he only ever talks in Spanish",
"state": "Flipping omelets"
}
}
}