return libpr
+def c_pointer_to_bytearray(ba):
+ """Return C char * pointer to ba."""
+ type = ctypes.c_char * len(ba)
+ return type.from_buffer(ba)
+
+
def strong_write(file, string):
"""Apply write(string), then flush()."""
file.write(string)
return True
return False
+ def set_cells_passable_on_memmap_to_65534_on_scoremap():
+ # OUTSOURCED TO libplomrogue.so:
+ # memmap = t["T_MEMMAP"]
+ # for i in [i for i in range(world_db["MAP_LENGTH"] ** 2)
+ # if ord_dot == memmap[i]]:
+ # set_map_score(i, 65534) # i.e. 65535-1
+ map = c_pointer_to_bytearray(t["T_MEMMAP"])
+ if libpr.set_cells_passable_on_memmap_to_65534_on_scoremap(map):
+ raise RuntimeError("No score map allocated for "
+ "set_cells_passable_on_memmap_to_65534_on_scoremap().")
+
def init_score_map():
test = libpr.init_score_map()
if test:
ord_dot = ord(".")
ord_v = ord("v")
ord_blank = ord(" ")
- for i in [i for i in range(world_db["MAP_LENGTH"] ** 2)
- if ord_dot == t["T_MEMMAP"][i]]:
- set_map_score(i, 65535 - 1)
+ set_cells_passable_on_memmap_to_65534_on_scoremap()
if "a" == filter:
for id in world_db["Things"]:
Thing = world_db["Things"][id]
dir_to_target = 0
return dir_to_target
- def FOO():
- libpr.dijkstra_map()
-
dir_to_target = False
mem_depth_c = b' '
run_i = 9 + 1 if "s" == filter else 1
init_score_map()
mem_depth_c = b'9' if b' ' == mem_depth_c \
else bytes([mem_depth_c[0] - 1])
- if FOO(): # libpr.dijkstra_map():
+ if libpr.dijkstra_map():
raise RuntimeError("No score map allocated for dijkstra_map().")
dir_to_target = get_dir_from_neighbors()
libpr.free_score_map()