extern long conditions[];
extern const motion_t motions[];
extern const action_t actions[];
+extern const long travel[];
+extern const long tkey[];
#define NLOCATIONS {}
#define NOBJECTS {}
#define NTHRESHOLDS {}
#define NACTIONS {}
#define NTRAVEL {}
+#define NKEYS {}
enum arbitrary_messages_refs {{
{}
{}
}};
+{}
+
+{}
+
/* end */
"""
sys.stderr.write("%s is not a known word classifier\n" % attrs["type"])
sys.exit(1)
+def get_motions(motions):
+ template = """ {{
+ .words = {},
+ }},
+"""
+ mot_str = ""
+ for motion in motions:
+ contents = motion[1]
+ if contents["words"] == None:
+ mot_str += template.format("NULL")
+ continue
+ c_words = [make_c_string(s) for s in contents["words"]]
+ words_str = "(const char* []) {" + ", ".join(c_words) + "}"
+ mot_str += template.format(words_str)
+ return mot_str
+
+def get_actions(actions):
+ template = """ {{
+ .words = {},
+ .message = {},
+ }},
+"""
+ act_str = ""
+ for action in actions:
+ contents = action[1]
+
+ if contents["words"] == None:
+ words_str = "NULL"
+ else:
+ c_words = [make_c_string(s) for s in contents["words"]]
+ words_str = "(const char* []) {" + ", ".join(c_words) + "}"
+
+ if contents["message"] == None:
+ message = "NO_MESSAGE"
+ else:
+ message = contents["message"]
+
+ act_str += template.format(words_str, message)
+ act_str = act_str[:-1] # trim trailing newline
+ return act_str
+
+def bigdump(arr):
+ out = ""
+ for (i, entry) in enumerate(arr):
+ if i % 10 == 0:
+ if out and out[-1] == ' ':
+ out = out[:-1]
+ out += "\n "
+ out += str(arr[i]) + ", "
+ out = out[:-2] + "\n"
+ return out
+
def buildtravel(locs, objs, voc):
ltravel = []
verbmap = {}
else:
print(cond)
raise ValueError
- # Much more to be done here
+
for (i, (name, loc)) in enumerate(locs):
if "travel" in loc:
for rule in loc["travel"]:
if not rule["verbs"]:
tt.append(1)
ltravel.append(tuple(tt))
- return tuple(ltravel)
-
-def get_motions(motions):
- template = """ {{
- .words = {},
- }},
-"""
- mot_str = ""
- for motion in motions:
- contents = motion[1]
- if contents["words"] == None:
- mot_str += template.format("NULL")
- continue
- c_words = [make_c_string(s) for s in contents["words"]]
- words_str = "(const char* []) {" + ", ".join(c_words) + "}"
- mot_str += template.format(words_str)
- return mot_str
-
-def get_actions(actions):
- template = """ {{
- .words = {},
- .message = {},
- }},
-"""
- act_str = ""
- for action in actions:
- contents = action[1]
-
- if contents["words"] == None:
- words_str = "NULL"
- else:
- c_words = [make_c_string(s) for s in contents["words"]]
- words_str = "(const char* []) {" + ", ".join(c_words) + "}"
-
- if contents["message"] == None:
- message = "NO_MESSAGE"
- else:
- message = contents["message"]
-
- act_str += template.format(words_str, message)
- act_str = act_str[:-1] # trim trailing newline
- return act_str
-
-if __name__ == "__main__":
- with open(yaml_name, "r") as f:
- db = yaml.load(f)
-
- locnames = [x[0] for x in db["locations"]]
- msgnames = [el[0] for el in db["arbitrary_messages"]]
- objnames = [el[0] for el in db["objects"]]
-
- travel = buildtravel(db["locations"], db["objects"], db["vocabulary"])
# At this point the ltravel data is in the Section 3
# representation from the FORTRAN version. Next we perform the
# }
# TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
# }
+ travel = [0]
+ tkey = [0]
+ oldloc = 0
+ while ltravel:
+ rule = list(ltravel.pop(0))
+ loc = rule.pop(0)
+ newloc = rule.pop(0)
+ if loc != oldloc:
+ tkey.append(len(travel))
+ oldloc = loc
+ if travel:
+ travel[-1] *= -1
+ while rule:
+ travel.append(rule.pop(0) + newloc * 1000)
+ travel[-1] *= -1
+ return (travel, tkey)
+
+if __name__ == "__main__":
+ with open(yaml_name, "r") as f:
+ db = yaml.load(f)
+
+ locnames = [x[0] for x in db["locations"]]
+ msgnames = [el[0] for el in db["arbitrary_messages"]]
+ objnames = [el[0] for el in db["objects"]]
+
+ (travel, tkey) = buildtravel(db["locations"],
+ db["objects"],
+ db["vocabulary"])
c = c_template.format(
h_name,
get_condbits(db["locations"]),
get_motions(db["motions"]),
get_actions(db["actions"]),
+ "const long tkey[] = {%s};" % bigdump(tkey),
+ "const long travel[] = {%s};" % bigdump(travel),
)
h = h_template.format(
len(db["turn_thresholds"]),
len(db["actions"]),
len(travel),
+ len(tkey),
get_refs(db["arbitrary_messages"]),
get_refs(db["locations"]),
get_refs(db["objects"]),