这个可以用来制作rpg游戏中的小镇地图吗
似乎是需要用一些地理信息,从地理信息中作信息增强得到一些合理的额外信息來建模整个城市中的建筑物,想知道如果我们只有一些NPC的建筑物的文本描述和这些NPC的建筑物的坐标在这个基础上可以做类似的事情吗
Thank you for your interest! We are currently working on extending our CityGen with more features. And we will definitely take your suggestions into consideration, stay tuned!
我试着用如下基于随机和矩形密度分布的部分,把NPC们的房子选址问题转换成一个优化问题,因为我发现实际上LLM很难处理这种逻辑问题,但是下面的代码非常粗糙,我很好奇你们的工作能不能用在rpg游戏的地图自动生成上 import time import openai from fanyi import tupian from multiprocessing import Process from multiprocessing import JoinableQueue as Queue import json import random import matplotlib.pyplot as plt import matplotlib.font_manager as font_manager
设置支持中文的字体
plt.rcParams['font.sans-serif'] = ['SimHei'] # 例如使用黑体 plt.rcParams['axes.unicode_minus'] = False # 解决负号无法显示的问题
openai.log = "debug"
openai.api_key = openai.api_base =
locations_descriptions=[] didian_1 = ["小镇 小镇应该有其独特的特点和特色,如历史背景、建筑风格或有趣的当地传说。"] * 16 + ["城市 城市应该更加繁华和复杂,有城堡、市场、行会等,反映出一个繁忙和多元化的社会结构。"] * 13 + ["森林 有其独特的自然环境和可能居住的生物。"] * 2 + ["山脉 有其独特的自然环境和可能居住的生物。"] * 2 + ["湖泊 有其独特的自然环境和可能居住的生物。"] * 2 + ["荒野 有其独特的自然环境和可能居住的生物。"] * 3 + ["沙漠 有其独特的自然环境和可能居住的生物。"] * 1
for i in range(3):
didian = random.choice(didian_1) # 随机选择一个地点
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-1106",
messages=[
{"role": "system", "content": "You are a creative writer like Drew Hayes, specializing in writing various content related to medieval RPG"},
{"role": "user",
"content": f"为中世纪剑与魔法RPG游戏创建地点的详细描述,创建一个{didian}的详细描述,要求包括这个地点的具体名字 和地理地貌 大致地图(通过文字描述从鸟瞰角度来看的内部构造和外部结构)"
},
],
max_tokens=700,
)
character_details = response.choices[0].message.content
print(character_details)
location_description = response.choices[0].message.content
locations_descriptions.append({"type": didian, "description": location_description})
转换为JSON
locations_json = json.dumps(locations_descriptions, ensure_ascii=False, indent=4)
读取现有的JSON文件
json_file_path = r"J:\xxoo\fanyi\locations.json" # 确保这是现有文件的正确路径
try: with open(json_file_path, 'r', encoding='utf-8') as file: existing_data = json.load(file) except FileNotFoundError: existing_data = []
将新的描述添加到现有的数据中
existing_data.extend(locations_descriptions)
将更新后的数据写回文件
with open(json_file_path, 'w', encoding='utf-8') as file: json.dump(existing_data, file, ensure_ascii=False, indent=4)
print(f"JSON file saved at: {json_file_path}")
import matplotlib.pyplot as plt import matplotlib.patches as patches import random import numpy as np
def create_rotated_rect(center, width, height, angle): return patches.Rectangle(center, width, height, angle=angle, edgecolor='blue', facecolor='none', transform=plt.gca().transData)
def does_rect_overlap(rect, other_rects): rect_bbox = rect.get_bbox() for other in other_rects: if rect_bbox.overlaps(other.get_bbox()): return True return False
假设 characters 列表已经包含了角色信息和居所位置
characters = [{'name': f'NPC{i}', 'residence': {'location': (random.randint(0, 49), random.randint(0, 49))}} for i in range(50)]
fig, ax = plt.subplots(figsize=(10, 10)) existing_rects = []
for character in characters: loc = character['residence']['location'] name = character['name']
# 生成旋转矩形
width, height = random.uniform(1, 3), random.uniform(1, 3)
angle = random.uniform(0, 90)
rect = create_rotated_rect((loc[0], loc[1]), width, height, angle)
# 检查矩形是否与已有矩形重叠
if not does_rect_overlap(rect, existing_rects):
existing_rects.append(rect)
ax.add_patch(rect)
ax.text(loc[0], loc[1], name, fontsize=9, ha='center', va='center')
ax.set_xlim(0, 50) ax.set_ylim(0, 50) ax.set_aspect('equal', adjustable='box') ax.axis('off') plt.show()
方便从我的主页添加我的微信吗,我们可以进一步交流
你好,加了