-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneration_tools.py
More file actions
38 lines (30 loc) · 1.53 KB
/
Copy pathgeneration_tools.py
File metadata and controls
38 lines (30 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Extracts elements the player can interact with from a text
def extract_elements(description, element_name):
start_index = description.find(f"{element_name} = [")
end_index = description.find("]", start_index)
if start_index != -1 and end_index != -1:
elements_str = description[start_index + len(f"{element_name} = ["):end_index]
elements = [elem.strip("'\" ") for elem in elements_str.split(",")]
return elements
else:
return []
if start_index != -1 and end_index != -1:
elements_str = description[start_index + len(f"{element_name} = ["):end_index]
elements = [elem.strip("'\" ") for elem in elements_str.split(",")]
return elements
else:
return []
# Extracts actions and their associated characteristics from a text
def extract_actions_and_characteristics(description):
start_index = description.find("actions = [")
end_index = description.find("]", start_index)
actions_with_characteristics = []
if start_index != -1 and end_index != -1:
actions_str = description[start_index + len("actions = ["):end_index]
actions_list = [action.strip("'\" ") for action in actions_str.split(",")]
for action in actions_list:
if "(" in action and ")" in action:
action_text, characteristic = action.rsplit("(", 1)
characteristic = characteristic.rstrip(")")
actions_with_characteristics.append((action_text.strip(), characteristic.strip()))
return actions_with_characteristics