git.fiddlerwoaroof.com
Ed L authored on 14/09/2014 00:15:11
Showing 14 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,58 @@
1
+import numpy as np
2
+
3
+class Traveller(object):
4
+	@property
5
+	def x(self): return self.pos[0]
6
+	@x.setter
7
+	def x(self, val): self.pos = val, self.pos[1]
8
+
9
+	@property
10
+	def y(self): return self.pos[1]
11
+	@y.setter
12
+	def y(self, val): self.pos = self.pos[0], val
13
+
14
+	def __init__(self, starting_cell):
15
+		self.pos = starting_cell
16
+		self.connections = []
17
+		self.visited = {self.pos}
18
+
19
+	def random_walk(self, array):
20
+		maxx, maxy = array.shape
21
+		cval = array[self.pos]
22
+
23
+		dx, dy = 0,0
24
+		r = np.random.random()
25
+		if r < 0.25: # x-1
26
+			dx = -1
27
+		elif r < 0.5: # x+1
28
+			dy = 1
29
+		elif r < 0.75: # y-1
30
+			dx = 1
31
+		else: # y+1
32
+			dy = -1
33
+
34
+		opos = self.pos
35
+		self.x += dx
36
+		self.y += dy
37
+
38
+		if self.x < 0: self.x = 0
39
+		elif self.x >= maxx: self.x = maxx-1
40
+		if self.y < 0: self.y = 0
41
+		elif self.y >= maxy: self.y = maxy-1
42
+
43
+		self.visited.add(self.pos)
44
+
45
+		nval = array[self.pos]
46
+
47
+		if cval != nval: 
48
+			array[self.pos] = cval
49
+			self.connections.append((opos, self.pos))
50
+			print cval, nval
51
+
52
+
53
+x,y = 24,36
54
+maze = np.array(range(1,x*y+1))
55
+maze.shape = x,y
56
+
57
+t = Traveller((x/2, y/2))
58
+
0 59
new file mode 100644
... ...
@@ -0,0 +1,1177 @@
1
+
2
+from ctypes import *
3
+from libtcodpy import Color
4
+
5
+# HACK for return types
6
+c_void = c_int
7
+
8
+def setup_protos(lib):
9
+    lib.TCOD_line_step.restype = c_bool
10
+    lib.TCOD_line_step.argtypes=[POINTER(c_int), POINTER(c_int)]
11
+
12
+    #_lib.TCOD_line.restype=c_bool 
13
+    #_lib.TCOD_line.argtypes=[c_int, c_int, c_int, c_int, TCOD_line_listener_t]
14
+
15
+    lib.TCOD_line_init_mt.restype=c_void 
16
+    lib.TCOD_line_init_mt.argtypes=[c_int, c_int, c_int, c_int, c_void_p]
17
+
18
+    lib.TCOD_line_step_mt.restype=c_bool 
19
+    lib.TCOD_line_step_mt.argtypes=[POINTER(c_int), POINTER(c_int), c_void_p]
20
+
21
+    #_lib.TCOD_line_mt.restype=c_bool 
22
+    #_lib.TCOD_line_mt.argtypes=[c_int, c_int, c_int, c_int, TCOD_line_listener_t , c_void_p]
23
+
24
+    lib.TCOD_bsp_new.restype=c_void_p
25
+    lib.TCOD_bsp_new.argtypes=[]
26
+
27
+    lib.TCOD_bsp_new_with_size.restype=c_void_p
28
+    lib.TCOD_bsp_new_with_size.argtypes=[c_int,c_int,c_int, c_int]
29
+
30
+    lib.TCOD_bsp_delete.restype=c_void 
31
+    lib.TCOD_bsp_delete.argtypes=[c_void_p]
32
+
33
+    lib.TCOD_bsp_left.restype=c_void_p
34
+    lib.TCOD_bsp_left.argtypes=[c_void_p]
35
+
36
+    lib.TCOD_bsp_right.restype=c_void_p
37
+    lib.TCOD_bsp_right.argtypes=[c_void_p]
38
+
39
+    lib.TCOD_bsp_father.restype=c_void_p
40
+    lib.TCOD_bsp_father.argtypes=[c_void_p]
41
+
42
+    lib.TCOD_bsp_is_leaf.restype=c_bool 
43
+    lib.TCOD_bsp_is_leaf.argtypes=[c_void_p]
44
+
45
+    #_lib.c_void_pre_order.restype=c_bool 
46
+    #_lib.c_void_pre_order.argtypes=[c_void_p, TCOD_bsp_callback_t , void_p]
47
+
48
+    #_lib.TCOD_bsp_traverse_in_order.restype=c_bool 
49
+    #_lib.TCOD_bsp_traverse_in_order.argtypes=[c_void_p, TCOD_bsp_callback_t , void_p]
50
+
51
+    #_lib.c_void_post_order.restype=c_bool 
52
+    #_lib.c_void_post_order.argtypes=[c_void_p, TCOD_bsp_callback_t , void_p]
53
+
54
+    #_lib.TCOD_bsp_traverse_level_order.restype=c_bool 
55
+    #_lib.TCOD_bsp_traverse_level_order.argtypes=[c_void_p, TCOD_bsp_callback_t , void_p]
56
+
57
+    #_lib.TCOD_bsp_traverse_inverted_level_order.restype=c_bool 
58
+    #_lib.TCOD_bsp_traverse_inverted_level_order.argtypes=[c_void_p, TCOD_bsp_callback_t , void_p]
59
+
60
+    lib.TCOD_bsp_contains.restype=c_bool 
61
+    lib.TCOD_bsp_contains.argtypes=[c_void_p, c_int, c_int]
62
+
63
+    lib.TCOD_bsp_find_node.restype=c_void_p
64
+    lib.TCOD_bsp_find_node.argtypes=[c_void_p, c_int, c_int]
65
+
66
+    lib.TCOD_bsp_resize.restype=c_void 
67
+    lib.TCOD_bsp_resize.argtypes=[c_void_p, c_int,c_int, c_int, c_int]
68
+
69
+    lib.TCOD_bsp_split_once.restype=c_void 
70
+    lib.TCOD_bsp_split_once.argtypes=[c_void_p, c_bool , c_int]
71
+
72
+    lib.TCOD_bsp_split_recursive.restype=c_void 
73
+    lib.TCOD_bsp_split_recursive.argtypes=[c_void_p, c_void_p , c_int, ]
74
+
75
+    lib.TCOD_bsp_remove_sons.restype=c_void
76
+    lib.TCOD_bsp_remove_sons.argtypes=[c_void_p]
77
+
78
+    lib.TCOD_color_RGB.restype=Color
79
+    lib.TCOD_color_RGB.argtypes=[c_byte , c_byte , c_byte ]
80
+
81
+    lib.TCOD_color_HSV.restype=Color
82
+    lib.TCOD_color_HSV.argtypes=[c_float , c_float , c_float ]
83
+
84
+    lib.TCOD_color_equals .restype=c_bool
85
+    lib.TCOD_color_equals .argtypes=[Color, Color]
86
+
87
+    lib.TCOD_color_add .restype=Color
88
+    lib.TCOD_color_add .argtypes=[Color, Color]
89
+
90
+    lib.TCOD_color_subtract .restype=Color
91
+    lib.TCOD_color_subtract .argtypes=[Color, Color]
92
+
93
+    lib.TCOD_color_multiply .restype=Color
94
+    lib.TCOD_color_multiply .argtypes=[Color , Color ]
95
+
96
+    lib.TCOD_color_multiply_scalar .restype=Color
97
+    lib.TCOD_color_multiply_scalar .argtypes=[Color , c_float ]
98
+
99
+#    lib.TCOD_color_lerp .restype=c_int
100
+#    lib.TCOD_color_lerp .argtypes=[c_int , c_int , c_float ]
101
+
102
+    lib.TCOD_color_set_HSV .restype=c_void
103
+    lib.TCOD_color_set_HSV .argtypes=[POINTER(Color),c_float , c_float , c_float ]
104
+
105
+    lib.TCOD_color_get_HSV .restype=c_void
106
+    lib.TCOD_color_get_HSV .argtypes=[Color ,POINTER(c_float) , POINTER(c_float) , POINTER(c_float) ]
107
+
108
+    lib.TCOD_color_get_hue .restype=c_float
109
+    lib.TCOD_color_get_hue .argtypes=[Color ]
110
+
111
+    lib.TCOD_color_set_hue .restype=c_void
112
+    lib.TCOD_color_set_hue .argtypes=[POINTER(Color), c_float ]
113
+
114
+    lib.TCOD_color_get_saturation .restype=c_float
115
+    lib.TCOD_color_get_saturation .argtypes=[Color ]
116
+
117
+    lib.TCOD_color_set_saturation .restype=c_void
118
+    lib.TCOD_color_set_saturation .argtypes=[POINTER(Color), c_float ]
119
+
120
+    lib.TCOD_color_get_value .restype=c_float
121
+    lib.TCOD_color_get_value .argtypes=[Color ]
122
+
123
+    lib.TCOD_color_set_value .restype=c_void
124
+    lib.TCOD_color_set_value .argtypes=[POINTER(Color), c_float ]
125
+
126
+    lib.TCOD_color_shift_hue .restype=c_void
127
+    lib.TCOD_color_shift_hue .argtypes=[POINTER(Color), c_float ]
128
+
129
+    lib.TCOD_color_scale_HSV .restype=c_void
130
+    lib.TCOD_color_scale_HSV .argtypes=[POINTER(Color), c_float , c_float ]
131
+
132
+    lib.TCOD_color_gen_map.restype=c_void
133
+    lib.TCOD_color_gen_map.argtypes=[POINTER(Color), c_int, POINTER(Color), POINTER(c_int)]
134
+
135
+    lib.TCOD_console_init_root.restype=c_void
136
+    lib.TCOD_console_init_root.argtypes=[c_int, c_int, c_char_p , c_bool , c_uint ]
137
+
138
+    lib.TCOD_console_set_window_title.restype=c_void
139
+    lib.TCOD_console_set_window_title.argtypes=[c_char_p]
140
+
141
+    lib.TCOD_console_set_fullscreen.restype=c_void
142
+    lib.TCOD_console_set_fullscreen.argtypes=[c_bool ]
143
+
144
+    lib.TCOD_console_is_fullscreen.restype=c_bool
145
+    lib.TCOD_console_is_fullscreen.argtypes=[]
146
+
147
+    lib.TCOD_console_is_window_closed.restype=c_bool
148
+    lib.TCOD_console_is_window_closed.argtypes=[]
149
+
150
+    lib.TCOD_console_set_custom_font.restype=c_void
151
+    lib.TCOD_console_set_custom_font.argtypes=[c_char_p, c_int,c_int, c_int]
152
+
153
+    lib.TCOD_console_map_ascii_code_to_font.restype=c_void
154
+    lib.TCOD_console_map_ascii_code_to_font.argtypes=[c_int, c_int, c_int]
155
+
156
+    lib.TCOD_console_map_ascii_codes_to_font.restype=c_void
157
+    lib.TCOD_console_map_ascii_codes_to_font.argtypes=[c_int, c_int, c_int, c_int]
158
+
159
+    lib.TCOD_console_map_string_to_font.restype=c_void
160
+    lib.TCOD_console_map_string_to_font.argtypes=[c_char_p, c_int, c_int]
161
+
162
+    lib.TCOD_console_set_dirty.restype=c_void
163
+    lib.TCOD_console_set_dirty.argtypes=[c_int, c_int, c_int, c_int]
164
+
165
+    lib.TCOD_console_set_default_background.restype=c_void
166
+    lib.TCOD_console_set_default_background.argtypes=[c_void_p ,Color ]
167
+
168
+    lib.TCOD_console_set_default_foreground.restype=c_void
169
+    lib.TCOD_console_set_default_foreground.argtypes=[c_void_p ,Color ]
170
+
171
+    lib.TCOD_console_clear.restype=c_void
172
+    lib.TCOD_console_clear.argtypes=[c_void_p ]
173
+
174
+    lib.TCOD_console_set_char_background.restype=c_void
175
+    lib.TCOD_console_set_char_background.argtypes=[c_void_p ,c_int, c_int, Color , c_int ]
176
+
177
+    lib.TCOD_console_set_char_foreground.restype=c_void
178
+    lib.TCOD_console_set_char_foreground.argtypes=[c_void_p ,c_int, c_int, Color ]
179
+
180
+    lib.TCOD_console_set_char.restype=c_void
181
+    lib.TCOD_console_set_char.argtypes=[c_void_p ,c_int, c_int, c_int]
182
+
183
+    lib.TCOD_console_put_char.restype=c_void
184
+    lib.TCOD_console_put_char.argtypes=[c_void_p ,c_int, c_int, c_int, c_int ]
185
+
186
+    lib.TCOD_console_put_char_ex.restype=c_void
187
+    lib.TCOD_console_put_char_ex.argtypes=[c_void_p ,c_int, c_int, c_int, Color, Color ]
188
+
189
+    lib.TCOD_console_set_background_flag.restype=c_void
190
+    lib.TCOD_console_set_background_flag.argtypes=[c_void_p ,c_int ]
191
+
192
+    lib.TCOD_console_get_background_flag.restype=c_int
193
+    lib.TCOD_console_get_background_flag.argtypes=[c_void_p ]
194
+
195
+    lib.TCOD_console_set_alignment.restype=c_void
196
+    lib.TCOD_console_set_alignment.argtypes=[c_void_p ,c_int ]
197
+
198
+    lib.TCOD_console_get_alignment.restype=c_int
199
+    lib.TCOD_console_get_alignment.argtypes=[c_void_p ]
200
+
201
+#    lib.TCOD_console_print.restype=c_void
202
+#    lib.TCOD_console_print.argtypes=[c_void_p ,c_int, c_int, c_char_p, ...]
203
+
204
+#    lib.TCOD_console_print_ex.restype=c_void
205
+#    lib.TCOD_console_print_ex.argtypes=[c_void_p ,c_int, c_int, c_int , c_int , c_char_p, ...]
206
+
207
+#    lib.TCOD_console_print_rect.restype=c_int
208
+#    lib.TCOD_console_print_rect.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_char_p, ...]
209
+
210
+#    lib.TCOD_console_print_rect_ex.restype=c_int
211
+#    lib.TCOD_console_print_rect_ex.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_int , c_int , c_char_p, ...]
212
+
213
+#    lib.TCOD_console_get_height_rect.restype=c_int
214
+#    lib.TCOD_console_get_height_rect.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_char_p, ...]
215
+
216
+    lib.TCOD_console_rect.restype=c_void
217
+    lib.TCOD_console_rect.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_bool , c_int ]
218
+
219
+    lib.TCOD_console_hline.restype=c_void
220
+    lib.TCOD_console_hline.argtypes=[c_void_p ,c_int,c_int, c_int, c_int ]
221
+
222
+    lib.TCOD_console_vline.restype=c_void
223
+    lib.TCOD_console_vline.argtypes=[c_void_p ,c_int,c_int, c_int, c_int ]
224
+
225
+#    lib.TCOD_console_print_frame.restype=c_void
226
+#    lib.TCOD_console_print_frame.argtypes=[c_void_p ,c_int,c_int,c_int,c_int, c_bool , c_int , c_char_p, ...]
227
+
228
+    lib.TCOD_console_map_string_to_font_utf.restype=c_void
229
+    lib.TCOD_console_map_string_to_font_utf.argtypes=[c_char_p, c_int, c_int]
230
+
231
+#    lib.TCOD_console_print_utf.restype=c_void
232
+#    lib.TCOD_console_print_utf.argtypes=[c_void_p ,c_int, c_int, wchar_t_p, ...]
233
+
234
+#    lib.TCOD_console_print_ex_utf.restype=c_void
235
+#    lib.TCOD_console_print_ex_utf.argtypes=[c_void_p ,c_int, c_int, c_int , c_int , wchar_t_p, ...]
236
+
237
+#    lib.TCOD_console_print_rect_utf.restype=c_int
238
+#    lib.TCOD_console_print_rect_utf.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, wchar_t_p, ...]
239
+
240
+#    lib.TCOD_console_print_rect_ex_utf.restype=c_int
241
+#    lib.TCOD_console_print_rect_ex_utf.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_int , c_int , wchar_t_p, ...]
242
+
243
+    lib.TCOD_console_get_height_rect_utf.restype=c_int
244
+#    lib.TCOD_console_get_height_rect_utf.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, wchar_t_p, ...]
245
+
246
+    lib.TCOD_console_get_default_background.restype=Color
247
+    lib.TCOD_console_get_default_background.argtypes=[c_void_p ]
248
+
249
+    lib.TCOD_console_get_default_foreground.restype=Color
250
+    lib.TCOD_console_get_default_foreground.argtypes=[c_void_p ]
251
+
252
+    lib.TCOD_console_get_char_background.restype=Color
253
+    lib.TCOD_console_get_char_background.argtypes=[c_void_p ,c_int, c_int]
254
+
255
+    lib.TCOD_console_get_char_foreground.restype=Color
256
+    lib.TCOD_console_get_char_foreground.argtypes=[c_void_p ,c_int, c_int]
257
+
258
+    lib.TCOD_console_get_char.restype=c_int
259
+    lib.TCOD_console_get_char.argtypes=[c_void_p ,c_int, c_int]
260
+
261
+    lib.TCOD_console_set_fade.restype=c_void
262
+    lib.TCOD_console_set_fade.argtypes=[c_byte , Color ]
263
+
264
+    lib.TCOD_console_get_fade.restype=c_byte
265
+    lib.TCOD_console_get_fade.argtypes=[]
266
+
267
+    lib.TCOD_console_get_fading_color.restype=Color
268
+    lib.TCOD_console_get_fading_color.argtypes=[]
269
+
270
+    lib.TCOD_console_flush.restype=c_void
271
+    lib.TCOD_console_flush.argtypes=[]
272
+
273
+    lib.TCOD_console_set_color_control.restype=c_void
274
+    lib.TCOD_console_set_color_control.argtypes=[c_int , Color , Color ]
275
+
276
+#    lib.TCOD_console_check_for_keypress.restype=TCOD_key_t
277
+#    lib.TCOD_console_check_for_keypress.argtypes=[c_int]
278
+
279
+#    lib.TCOD_console_wait_for_keypress.restype=TCOD_key_t
280
+#    lib.TCOD_console_wait_for_keypress.argtypes=[c_bool ]
281
+
282
+    lib.TCOD_console_set_keyboard_repeat.restype=c_void
283
+    lib.TCOD_console_set_keyboard_repeat.argtypes=[c_int, c_int]
284
+
285
+    lib.TCOD_console_disable_keyboard_repeat.restype=c_void
286
+    lib.TCOD_console_disable_keyboard_repeat.argtypes=[]
287
+
288
+    lib.TCOD_console_is_key_pressed.restype=c_bool
289
+    lib.TCOD_console_is_key_pressed.argtypes=[c_int ]
290
+
291
+    lib.TCOD_console_from_file.restype=c_void_p
292
+    lib.TCOD_console_from_file.argtypes=[c_char_p]
293
+
294
+    lib.TCOD_console_load_asc.restype=c_bool
295
+    lib.TCOD_console_load_asc.argtypes=[c_void_p , c_char_p]
296
+
297
+    lib.TCOD_console_load_apf.restype=c_bool
298
+    lib.TCOD_console_load_apf.argtypes=[c_void_p , c_char_p]
299
+
300
+    lib.TCOD_console_save_asc.restype=c_bool
301
+    lib.TCOD_console_save_asc.argtypes=[c_void_p , c_char_p]
302
+
303
+    lib.TCOD_console_save_apf.restype=c_bool
304
+    lib.TCOD_console_save_apf.argtypes=[c_void_p , c_char_p]
305
+
306
+    lib.TCOD_console_new.restype=c_void_p
307
+    lib.TCOD_console_new.argtypes=[c_int, c_int]
308
+
309
+    lib.TCOD_console_get_width.restype=c_int
310
+    lib.TCOD_console_get_width.argtypes=[c_void_p ]
311
+
312
+    lib.TCOD_console_get_height.restype=c_int
313
+    lib.TCOD_console_get_height.argtypes=[c_void_p ]
314
+
315
+    lib.TCOD_console_set_key_color.restype=c_void
316
+    lib.TCOD_console_set_key_color.argtypes=[c_void_p ,Color ]
317
+
318
+    lib.TCOD_console_blit.restype=c_void
319
+    lib.TCOD_console_blit.argtypes=[c_void_p ,c_int, c_int, c_int, c_int, c_void_p , c_int, c_int, c_float, c_float]
320
+
321
+    lib.TCOD_console_delete.restype=c_void
322
+    lib.TCOD_console_delete.argtypes=[c_void_p ]
323
+
324
+    lib.TCOD_console_credits.restype=c_void
325
+    lib.TCOD_console_credits.argtypes=[]
326
+
327
+    lib.TCOD_console_credits_reset.restype=c_void
328
+    lib.TCOD_console_credits_reset.argtypes=[]
329
+
330
+    lib.TCOD_console_credits_render.restype=c_bool
331
+    lib.TCOD_console_credits_render.argtypes=[c_int, c_int, c_bool ]
332
+
333
+    lib.TCOD_map_new.restype=c_void_p
334
+    lib.TCOD_map_new.argtypes=[c_int, c_int]
335
+
336
+    lib.TCOD_map_clear.restype=c_void
337
+    lib.TCOD_map_clear.argtypes=[c_void_p , c_bool , c_bool ]
338
+
339
+    lib.TCOD_map_copy.restype=c_void
340
+    lib.TCOD_map_copy.argtypes=[c_void_p , c_void_p ]
341
+
342
+    lib.TCOD_map_set_properties.restype=c_void
343
+    lib.TCOD_map_set_properties.argtypes=[c_void_p , c_int, c_int, c_bool, c_bool]
344
+
345
+    lib.TCOD_map_delete.restype=c_void
346
+    lib.TCOD_map_delete.argtypes=[c_void_p ]
347
+
348
+    lib.TCOD_map_compute_fov.restype=c_void
349
+    lib.TCOD_map_compute_fov.argtypes=[c_void_p , c_int, c_int, c_int, c_bool, c_int ]
350
+
351
+    lib.TCOD_map_is_in_fov.restype=c_bool
352
+    lib.TCOD_map_is_in_fov.argtypes=[c_void_p , c_int, c_int]
353
+
354
+    lib.TCOD_map_set_in_fov.restype=c_void
355
+    lib.TCOD_map_set_in_fov.argtypes=[c_void_p , c_int, c_int, c_bool ]
356
+
357
+    lib.TCOD_map_is_transparent.restype=c_bool
358
+    lib.TCOD_map_is_transparent.argtypes=[c_void_p , c_int, c_int]
359
+
360
+    lib.TCOD_map_is_walkable.restype=c_bool
361
+    lib.TCOD_map_is_walkable.argtypes=[c_void_p , c_int, c_int]
362
+
363
+    lib.TCOD_map_get_width.restype=c_int
364
+    lib.TCOD_map_get_width.argtypes=[c_void_p ]
365
+
366
+    lib.TCOD_map_get_height.restype=c_int
367
+    lib.TCOD_map_get_height.argtypes=[c_void_p ]
368
+
369
+    lib.TCOD_map_get_nb_cells.restype=c_int
370
+    lib.TCOD_map_get_nb_cells.argtypes=[c_void_p ]
371
+
372
+    lib.TCOD_heightmap_new.restype=c_void_p
373
+    lib.TCOD_heightmap_new.argtypes=[c_int,c_int]
374
+
375
+    lib.TCOD_heightmap_delete.restype=c_void
376
+    lib.TCOD_heightmap_delete.argtypes=[c_void_p]
377
+
378
+    lib.TCOD_heightmap_get_value.restype=c_float
379
+    lib.TCOD_heightmap_get_value.argtypes=[c_void_p, c_int, c_int]
380
+
381
+    lib.TCOD_heightmap_get_interpolated_value.restype=c_float
382
+    lib.TCOD_heightmap_get_interpolated_value.argtypes=[c_void_p, c_float , c_float ]
383
+
384
+    lib.TCOD_heightmap_set_value.restype=c_void
385
+    lib.TCOD_heightmap_set_value.argtypes=[c_void_p, c_int, c_int, c_float ]
386
+
387
+    lib.TCOD_heightmap_get_slope.restype=c_float
388
+    lib.TCOD_heightmap_get_slope.argtypes=[c_void_p, c_int, c_int]
389
+
390
+    lib.TCOD_heightmap_get_normal.restype=c_void
391
+    lib.TCOD_heightmap_get_normal.argtypes=[c_void_p, c_float , c_float , POINTER(c_float), c_float ]
392
+
393
+    lib.TCOD_heightmap_count_cells.restype=c_int
394
+    lib.TCOD_heightmap_count_cells.argtypes=[c_void_p, c_float , c_float ]
395
+
396
+    lib.TCOD_heightmap_has_land_on_border.restype=c_bool
397
+    lib.TCOD_heightmap_has_land_on_border.argtypes=[c_void_p, c_float ]
398
+
399
+    lib.TCOD_heightmap_get_minmax.restype=c_void
400
+    lib.TCOD_heightmap_get_minmax.argtypes=[c_void_p, POINTER(c_float), POINTER(c_float)]
401
+
402
+    lib.TCOD_heightmap_copy.restype=c_void
403
+    lib.TCOD_heightmap_copy.argtypes=[c_void_p,c_void_p]
404
+
405
+    lib.TCOD_heightmap_add.restype=c_void
406
+    lib.TCOD_heightmap_add.argtypes=[c_void_p, c_float ]
407
+
408
+    lib.TCOD_heightmap_scale.restype=c_void
409
+    lib.TCOD_heightmap_scale.argtypes=[c_void_p, c_float ]
410
+
411
+    lib.TCOD_heightmap_clamp.restype=c_void
412
+    lib.TCOD_heightmap_clamp.argtypes=[c_void_p, c_float , c_float ]
413
+
414
+    lib.TCOD_heightmap_normalize.restype=c_void
415
+    lib.TCOD_heightmap_normalize.argtypes=[c_void_p, c_float , c_float ]
416
+
417
+    lib.TCOD_heightmap_clear.restype=c_void
418
+    lib.TCOD_heightmap_clear.argtypes=[c_void_p]
419
+
420
+    lib.TCOD_heightmap_lerp_hm.restype=c_void
421
+    lib.TCOD_heightmap_lerp_hm.argtypes=[c_void_p, c_void_p, c_void_p, c_float ]
422
+
423
+    lib.TCOD_heightmap_add_hm.restype=c_void
424
+    lib.TCOD_heightmap_add_hm.argtypes=[c_void_p, c_void_p, c_void_p]
425
+
426
+    lib.TCOD_heightmap_multiply_hm.restype=c_void
427
+    lib.TCOD_heightmap_multiply_hm.argtypes=[c_void_p, c_void_p, c_void_p]
428
+
429
+    lib.TCOD_heightmap_add_hill.restype=c_void
430
+    lib.TCOD_heightmap_add_hill.argtypes=[c_void_p, c_float , c_float , c_float , c_float ]
431
+
432
+    lib.TCOD_heightmap_dig_hill.restype=c_void
433
+    lib.TCOD_heightmap_dig_hill.argtypes=[c_void_p, c_float , c_float , c_float , c_float ]
434
+
435
+    lib.TCOD_heightmap_dig_bezier.restype=c_void
436
+    lib.TCOD_heightmap_dig_bezier.argtypes=[c_void_p, POINTER(c_int), POINTER(c_int), c_float , c_float , c_float , c_float ]
437
+
438
+    lib.TCOD_heightmap_rain_erosion.restype=c_void
439
+    lib.TCOD_heightmap_rain_erosion.argtypes=[c_void_p, c_int,c_float ,c_float ,c_void_p ]
440
+
441
+
442
+    lib.TCOD_heightmap_kernel_transform.restype=c_void
443
+    lib.TCOD_heightmap_kernel_transform.argtypes=[c_void_p, c_int, POINTER(c_int), POINTER(c_int), POINTER(c_float), c_float ,c_float ]
444
+
445
+    lib.TCOD_heightmap_add_voronoi.restype=c_void
446
+    lib.TCOD_heightmap_add_voronoi.argtypes=[c_void_p, c_int, c_int, POINTER(c_float),c_void_p ]
447
+
448
+
449
+    lib.TCOD_heightmap_add_fbm.restype=c_void
450
+    lib.TCOD_heightmap_add_fbm.argtypes=[c_void_p, c_int ,c_float , c_float , c_float , c_float , c_float , c_float , c_float ]
451
+
452
+    lib.TCOD_heightmap_scale_fbm.restype=c_void
453
+    lib.TCOD_heightmap_scale_fbm.argtypes=[c_void_p, c_int ,c_float , c_float , c_float , c_float , c_float , c_float , c_float ]
454
+
455
+    lib.TCOD_heightmap_islandify.restype=c_void
456
+    lib.TCOD_heightmap_islandify.argtypes=[c_void_p, c_float ,c_void_p ]
457
+
458
+    lib.TCOD_image_new.restype=c_void_p
459
+    lib.TCOD_image_new.argtypes=[c_int, c_int]
460
+
461
+    lib.TCOD_image_from_console.restype=c_void_p
462
+    lib.TCOD_image_from_console.argtypes=[c_void_p ]
463
+
464
+    lib.TCOD_image_refresh_console.restype=c_void
465
+    lib.TCOD_image_refresh_console.argtypes=[c_void_p , c_void_p ]
466
+
467
+    lib.TCOD_image_load.restype=c_void_p
468
+    lib.TCOD_image_load.argtypes=[c_char_p]
469
+
470
+    lib.TCOD_image_clear.restype=c_void
471
+    lib.TCOD_image_clear.argtypes=[c_void_p , Color ]
472
+
473
+    lib.TCOD_image_invert.restype=c_void
474
+    lib.TCOD_image_invert.argtypes=[c_void_p ]
475
+
476
+    lib.TCOD_image_hflip.restype=c_void
477
+    lib.TCOD_image_hflip.argtypes=[c_void_p ]
478
+
479
+    lib.TCOD_image_rotate90.restype=c_void
480
+    lib.TCOD_image_rotate90.argtypes=[c_void_p , c_int]
481
+
482
+    lib.TCOD_image_vflip.restype=c_void
483
+    lib.TCOD_image_vflip.argtypes=[c_void_p ]
484
+
485
+    lib.TCOD_image_scale.restype=c_void
486
+    lib.TCOD_image_scale.argtypes=[c_void_p , c_int, c_int]
487
+
488
+    lib.TCOD_image_save.restype=c_void
489
+    lib.TCOD_image_save.argtypes=[c_void_p , c_char_p]
490
+
491
+    lib.TCOD_image_get_size.restype=c_void
492
+    lib.TCOD_image_get_size.argtypes=[c_void_p , POINTER(c_int),POINTER(c_int)]
493
+
494
+    lib.TCOD_image_get_pixel.restype=Color
495
+    lib.TCOD_image_get_pixel.argtypes=[c_void_p ,c_int, c_int]
496
+
497
+    lib.TCOD_image_get_alpha.restype=c_int
498
+    lib.TCOD_image_get_alpha.argtypes=[c_void_p ,c_int, c_int]
499
+
500
+    lib.TCOD_image_get_mipmap_pixel.restype=c_int
501
+    lib.TCOD_image_get_mipmap_pixel.argtypes=[c_void_p ,c_float,c_float, c_float, c_float]
502
+
503
+    lib.TCOD_image_put_pixel.restype=c_void
504
+    lib.TCOD_image_put_pixel.argtypes=[c_void_p ,c_int, c_int,Color ]
505
+
506
+    lib.TCOD_image_blit.restype=c_void
507
+    lib.TCOD_image_blit.argtypes=[c_void_p , c_void_p , c_float , c_float , ]
508
+
509
+    lib.TCOD_image_blit_rect.restype=c_void
510
+    lib.TCOD_image_blit_rect.argtypes=[c_void_p , c_void_p , c_int, c_int, c_int, c_int, ]
511
+
512
+    lib.TCOD_image_blit_2x.restype=c_void
513
+    lib.TCOD_image_blit_2x.argtypes=[c_void_p , c_void_p , c_int, c_int, c_int, c_int, c_int, c_int]
514
+
515
+    lib.TCOD_image_delete.restype=c_void
516
+    lib.TCOD_image_delete.argtypes=[c_void_p ]
517
+
518
+    lib.TCOD_image_set_key_color.restype=c_void
519
+    lib.TCOD_image_set_key_color.argtypes=[c_void_p , Color]
520
+
521
+    lib.TCOD_image_is_pixel_transparent.restype=c_bool
522
+    lib.TCOD_image_is_pixel_transparent.argtypes=[c_void_p , c_int, c_int]
523
+
524
+    lib.TCOD_lex_new_intern.restype=c_void_p
525
+    lib.TCOD_lex_new_intern.argtypes=[]
526
+
527
+    lib.TCOD_lex_new.restype=c_void_p
528
+    lib.TCOD_lex_new.argtypes=[POINTER(c_char_p), POINTER(c_char_p), c_char_p, ]
529
+
530
+    lib.TCOD_lex_delete.restype=c_void
531
+    lib.TCOD_lex_delete.argtypes=[c_void_p]
532
+
533
+    lib.TCOD_lex_set_data_buffer.restype=c_void
534
+    lib.TCOD_lex_set_data_buffer.argtypes=[c_void_p,c_char_p]
535
+
536
+    lib.TCOD_lex_set_data_file.restype=c_bool
537
+    lib.TCOD_lex_set_data_file.argtypes=[c_void_p,c_char_p]
538
+
539
+    lib.TCOD_lex_parse.restype=c_int
540
+    lib.TCOD_lex_parse.argtypes=[c_void_p]
541
+
542
+    lib.TCOD_lex_parse_until_token_type.restype=c_int
543
+    lib.TCOD_lex_parse_until_token_type.argtypes=[c_void_p,c_int]
544
+
545
+    lib.TCOD_lex_parse_until_token_value.restype=c_int
546
+    lib.TCOD_lex_parse_until_token_value.argtypes=[c_void_p,c_char_p]
547
+
548
+    lib.TCOD_lex_expect_token_type.restype=c_bool
549
+    lib.TCOD_lex_expect_token_type.argtypes=[c_void_p,c_int]
550
+
551
+    lib.TCOD_lex_expect_token_value.restype=c_bool
552
+    lib.TCOD_lex_expect_token_value.argtypes=[c_void_p,c_int,c_char_p]
553
+
554
+    lib.TCOD_lex_savepoint.restype=c_void
555
+    lib.TCOD_lex_savepoint.argtypes=[c_void_p,c_void_p]
556
+
557
+    lib.TCOD_lex_restore.restype=c_void
558
+    lib.TCOD_lex_restore.argtypes=[c_void_p,c_void_p]
559
+
560
+    lib.TCOD_lex_get_last_javadoc.restype=c_char_p
561
+    lib.TCOD_lex_get_last_javadoc.argtypes=[c_void_p]
562
+
563
+    lib.TCOD_lex_get_token_name.restype=c_char_p
564
+    lib.TCOD_lex_get_token_name.argtypes=[c_int]
565
+
566
+    lib.TCOD_lex_get_last_error.restype=c_char_p
567
+    lib.TCOD_lex_get_last_error.argtypes=[]
568
+
569
+    lib.TCOD_lex_hextoint.restype=c_int
570
+    lib.TCOD_lex_hextoint.argtypes=[c_char]
571
+
572
+    lib.TCOD_sys_get_surface.restype=c_void_p
573
+    lib.TCOD_sys_get_surface.argtypes=[c_int, c_int, c_bool ]
574
+
575
+    lib.TCOD_sys_load_image.restype=c_void_p
576
+    lib.TCOD_sys_load_image.argtypes=[c_char_p]
577
+
578
+    lib.TCOD_list_new.restype=c_void_p
579
+    lib.TCOD_list_new.argtypes=[]
580
+
581
+    lib.TCOD_list_allocate.restype=c_void_p
582
+    lib.TCOD_list_allocate.argtypes=[c_int]
583
+
584
+    lib.TCOD_list_duplicate.restype=c_void_p
585
+    lib.TCOD_list_duplicate.argtypes=[c_void_p ]
586
+
587
+    lib.TCOD_list_delete.restype=c_void
588
+    lib.TCOD_list_delete.argtypes=[c_void_p ]
589
+
590
+    lib.TCOD_list_push.restype=c_void
591
+    lib.TCOD_list_push.argtypes=[c_void_p ,c_void_p ]
592
+
593
+    lib.TCOD_list_pop.restype=c_void_p
594
+    lib.TCOD_list_pop.argtypes=[c_void_p ]
595
+
596
+    lib.TCOD_list_peek.restype=c_void_p
597
+    lib.TCOD_list_peek.argtypes=[c_void_p ]
598
+
599
+    lib.TCOD_list_add_all.restype=c_void
600
+    lib.TCOD_list_add_all.argtypes=[c_void_p , c_void_p ]
601
+
602
+    lib.TCOD_list_get.restype=c_void_p
603
+    lib.TCOD_list_get.argtypes=[c_void_p ,c_int]
604
+
605
+    lib.TCOD_list_set.restype=c_void
606
+    lib.TCOD_list_set.argtypes=[c_void_p ,c_void_p, c_int]
607
+
608
+    lib.TCOD_list_begin.restype=POINTER(c_void_p)
609
+    lib.TCOD_list_begin.argtypes=[c_void_p ]
610
+
611
+    lib.TCOD_list_end.restype=POINTER(c_void_p)
612
+    lib.TCOD_list_end.argtypes=[c_void_p ]
613
+
614
+    lib.TCOD_list_reverse.restype=c_void
615
+    lib.TCOD_list_reverse.argtypes=[c_void_p ]
616
+
617
+    lib.TCOD_list_remove_iterator.restype=POINTER(c_void_p)
618
+    lib.TCOD_list_remove_iterator.argtypes=[c_void_p , POINTER(c_void_p)]
619
+
620
+    lib.TCOD_list_remove.restype=c_void
621
+    lib.TCOD_list_remove.argtypes=[c_void_p ,c_void_p ]
622
+
623
+    lib.TCOD_list_remove_iterator_fast.restype=POINTER(c_void_p)
624
+    lib.TCOD_list_remove_iterator_fast.argtypes=[c_void_p , POINTER(c_void_p)]
625
+
626
+    lib.TCOD_list_remove_fast.restype=c_void
627
+    lib.TCOD_list_remove_fast.argtypes=[c_void_p ,c_void_p ]
628
+
629
+    lib.TCOD_list_contains.restype=c_bool
630
+    lib.TCOD_list_contains.argtypes=[c_void_p ,c_void_p ]
631
+
632
+    lib.TCOD_list_clear.restype=c_void
633
+    lib.TCOD_list_clear.argtypes=[c_void_p ]
634
+
635
+    lib.TCOD_list_clear_and_delete.restype=c_void
636
+    lib.TCOD_list_clear_and_delete.argtypes=[c_void_p ]
637
+
638
+    lib.TCOD_list_size.restype=c_int
639
+    lib.TCOD_list_size.argtypes=[c_void_p ]
640
+
641
+    lib.TCOD_list_insert_before.restype=POINTER(c_void_p)
642
+    lib.TCOD_list_insert_before.argtypes=[c_void_p ,c_void_p,c_int]
643
+
644
+    lib.TCOD_list_is_empty.restype=c_bool
645
+    lib.TCOD_list_is_empty.argtypes=[c_void_p ]
646
+
647
+    lib.TCOD_random_get_instance.restype=c_void_p
648
+    lib.TCOD_random_get_instance.argtypes=[]
649
+
650
+    lib.TCOD_random_new.restype=c_void_p
651
+    lib.TCOD_random_new.argtypes=[c_int ]
652
+
653
+    lib.TCOD_random_save.restype=c_void_p
654
+    lib.TCOD_random_save.argtypes=[c_void_p ]
655
+
656
+    lib.TCOD_random_restore.restype=c_void
657
+    lib.TCOD_random_restore.argtypes=[c_void_p , c_void_p ]
658
+
659
+    lib.TCOD_random_new_from_seed.restype=c_void_p
660
+    lib.TCOD_random_new_from_seed.argtypes=[c_int , c_int ]
661
+
662
+    lib.TCOD_random_delete.restype=c_void
663
+    lib.TCOD_random_delete.argtypes=[c_void_p ]
664
+
665
+    lib.TCOD_random_set_distribution .restype=c_void
666
+    lib.TCOD_random_set_distribution .argtypes=[c_void_p , c_int ]
667
+
668
+    lib.TCOD_random_get_int.restype=c_int
669
+    lib.TCOD_random_get_int.argtypes=[c_void_p , c_int, c_int]
670
+
671
+    lib.TCOD_random_get_float .restype=c_float
672
+    lib.TCOD_random_get_float .argtypes=[c_void_p , c_float , c_float ]
673
+
674
+    lib.TCOD_random_get_double .restype=c_double
675
+    lib.TCOD_random_get_double .argtypes=[c_void_p , c_double , c_double ]
676
+
677
+    lib.TCOD_random_get_int_mean .restype=c_int
678
+    lib.TCOD_random_get_int_mean .argtypes=[c_void_p , c_int, c_int, c_int]
679
+
680
+    lib.TCOD_random_get_float_mean .restype=c_float
681
+    lib.TCOD_random_get_float_mean .argtypes=[c_void_p , c_float , c_float , c_float ]
682
+
683
+    lib.TCOD_random_get_double_mean .restype=c_double
684
+    lib.TCOD_random_get_double_mean .argtypes=[c_void_p , c_double , c_double , c_double ]
685
+
686
+#    lib.TCOD_random_dice_new .restype=TCOD_dice_t
687
+#    lib.TCOD_random_dice_new .argtypes=[c_char_p ]
688
+
689
+#    lib.TCOD_random_dice_roll .restype=c_int
690
+#    lib.TCOD_random_dice_roll .argtypes=[c_void_p , TCOD_dice_t ]
691
+
692
+    lib.TCOD_random_dice_roll_s .restype=c_int
693
+    lib.TCOD_random_dice_roll_s .argtypes=[c_void_p , c_char_p ]
694
+
695
+    lib.TCOD_mouse_show_cursor.restype=c_void
696
+    lib.TCOD_mouse_show_cursor.argtypes=[c_bool ]
697
+
698
+#    lib.TCOD_mouse_get_status.restype=TCOD_mouse_t
699
+#    lib.TCOD_mouse_get_status.argtypes=[]
700
+
701
+    lib.TCOD_mouse_is_cursor_visible.restype=c_bool
702
+    lib.TCOD_mouse_is_cursor_visible.argtypes=[]
703
+
704
+    lib.TCOD_mouse_move.restype=c_void
705
+    lib.TCOD_mouse_move.argtypes=[c_int, c_int]
706
+
707
+    lib.TCOD_namegen_parse .restype=c_void
708
+    lib.TCOD_namegen_parse .argtypes=[c_char_p , c_void_p ]
709
+
710
+    lib.TCOD_namegen_generate .restype=c_char_p
711
+    lib.TCOD_namegen_generate .argtypes=[c_char_p , c_bool ]
712
+
713
+    lib.TCOD_namegen_generate_custom .restype=c_char_p
714
+    lib.TCOD_namegen_generate_custom .argtypes=[c_char_p , c_char_p , c_bool ]
715
+
716
+    lib.TCOD_namegen_get_sets .restype=c_void_p
717
+    lib.TCOD_namegen_get_sets .argtypes=[]
718
+
719
+    lib.TCOD_namegen_destroy .restype=c_void
720
+    lib.TCOD_namegen_destroy .argtypes=[]
721
+
722
+    lib.TCOD_noise_new.restype=c_void_p
723
+    lib.TCOD_noise_new.argtypes=[c_int, c_float , c_float , c_void_p ]
724
+
725
+    lib.TCOD_noise_set_type .restype=c_void
726
+    lib.TCOD_noise_set_type .argtypes=[c_void_p , c_int ]
727
+
728
+    lib.TCOD_noise_get_ex .restype=c_float
729
+    lib.TCOD_noise_get_ex .argtypes=[c_void_p , POINTER(c_float), c_int ]
730
+
731
+    lib.TCOD_noise_get_fbm_ex .restype=c_float
732
+    lib.TCOD_noise_get_fbm_ex .argtypes=[c_void_p , POINTER(c_float), c_float , c_int ]
733
+
734
+    lib.TCOD_noise_get_turbulence_ex .restype=c_float
735
+    lib.TCOD_noise_get_turbulence_ex .argtypes=[c_void_p , POINTER(c_float), c_float , c_int ]
736
+
737
+    lib.TCOD_noise_get .restype=c_float
738
+    lib.TCOD_noise_get .argtypes=[c_void_p , POINTER(c_float)]
739
+
740
+    lib.TCOD_noise_get_fbm .restype=c_float
741
+    lib.TCOD_noise_get_fbm .argtypes=[c_void_p , POINTER(c_float), c_float ]
742
+
743
+    lib.TCOD_noise_get_turbulence .restype=c_float
744
+    lib.TCOD_noise_get_turbulence .argtypes=[c_void_p , POINTER(c_float), c_float ]
745
+
746
+    lib.TCOD_noise_delete.restype=c_void
747
+    lib.TCOD_noise_delete.argtypes=[c_void_p ]
748
+
749
+    lib.TCOD_struct_get_name.restype=c_char_p
750
+    lib.TCOD_struct_get_name.argtypes=[c_void_p ]
751
+
752
+    lib.TCOD_struct_add_property.restype=c_void
753
+    lib.TCOD_struct_add_property.argtypes=[c_void_p , c_char_p,c_int , c_bool ]
754
+
755
+    lib.TCOD_struct_add_list_property.restype=c_void
756
+    lib.TCOD_struct_add_list_property.argtypes=[c_void_p , c_char_p,c_int , c_bool ]
757
+
758
+    lib.TCOD_struct_add_value_list.restype=c_void
759
+    lib.TCOD_struct_add_value_list.argtypes=[c_void_p ,c_char_p, POINTER(c_char_p), c_bool ]
760
+
761
+    lib.TCOD_struct_add_value_list_sized.restype=c_void
762
+    lib.TCOD_struct_add_value_list_sized.argtypes=[c_void_p ,c_char_p, POINTER(c_char_p), c_int, c_bool ]
763
+
764
+    lib.TCOD_struct_add_flag.restype=c_void
765
+    lib.TCOD_struct_add_flag.argtypes=[c_void_p ,c_char_p]
766
+
767
+    lib.TCOD_struct_add_structure.restype=c_void
768
+    lib.TCOD_struct_add_structure.argtypes=[c_void_p ,c_void_p]
769
+
770
+    lib.TCOD_struct_is_mandatory.restype=c_bool
771
+    lib.TCOD_struct_is_mandatory.argtypes=[c_void_p ,c_char_p]
772
+
773
+    lib.TCOD_struct_get_type.restype=c_int
774
+    lib.TCOD_struct_get_type.argtypes=[c_void_p , c_char_p]
775
+
776
+    lib.TCOD_parser_new.restype=c_void_p
777
+    lib.TCOD_parser_new.argtypes=[]
778
+
779
+    lib.TCOD_parser_new_struct.restype=c_void_p
780
+    lib.TCOD_parser_new_struct.argtypes=[c_void_p , c_char_p]
781
+
782
+#    lib.TCOD_parser_new_custom_type.restype=c_int
783
+#    lib.TCOD_parser_new_custom_type.argtypes=[c_void_p ,TCOD_parser_custom_t custom_type_]
784
+
785
+    lib.TCOD_parser_run.restype=c_void
786
+    lib.TCOD_parser_run.argtypes=[c_void_p , c_char_p, c_void_p]
787
+
788
+    lib.TCOD_parser_delete.restype=c_void
789
+    lib.TCOD_parser_delete.argtypes=[c_void_p ]
790
+
791
+    lib.TCOD_parser_error.restype=c_void
792
+#    lib.TCOD_parser_error.argtypes=[c_char_p, ...]
793
+
794
+    lib.TCOD_parser_get_bool_property.restype=c_bool
795
+    lib.TCOD_parser_get_bool_property.argtypes=[c_void_p , c_char_p]
796
+
797
+    lib.TCOD_parser_get_char_property.restype=c_int
798
+    lib.TCOD_parser_get_char_property.argtypes=[c_void_p , c_char_p]
799
+
800
+    lib.TCOD_parser_get_int_property.restype=c_int
801
+    lib.TCOD_parser_get_int_property.argtypes=[c_void_p , c_char_p]
802
+
803
+    lib.TCOD_parser_get_float_property.restype=c_float
804
+    lib.TCOD_parser_get_float_property.argtypes=[c_void_p , c_char_p]
805
+
806
+    lib.TCOD_parser_get_string_property.restype=c_char_p
807
+    lib.TCOD_parser_get_string_property.argtypes=[c_void_p , c_char_p]
808
+
809
+    lib.TCOD_parser_get_color_property.restype=c_int
810
+    lib.TCOD_parser_get_color_property.argtypes=[c_void_p , c_char_p]
811
+
812
+#    lib.TCOD_parser_property.restype=TCOD_dice_t
813
+#    lib.TCOD_parser_property.argtypes=[c_void_p , c_char_p]
814
+
815
+#    lib.TCOD_parser_py.restype=c_void
816
+#    lib.TCOD_parser_py.argtypes=[c_void_p , c_char_p, c_void_p]
817
+
818
+    lib.TCOD_parser_get_custom_property.restype=c_void_p
819
+    lib.TCOD_parser_get_custom_property.argtypes=[c_void_p , c_char_p]
820
+
821
+    lib.TCOD_parser_get_list_property.restype=c_void_p
822
+    lib.TCOD_parser_get_list_property.argtypes=[c_void_p , c_char_p, c_int ]
823
+
824
+#    lib.TCOD_parse_c_bool_value.restype=TCOD_value_t
825
+#    lib.TCOD_parse_c_bool_value.argtypes=[]
826
+
827
+#    lib.TCOD_parse_char_value.restype=TCOD_value_t
828
+#    lib.TCOD_parse_char_value.argtypes=[]
829
+
830
+#    lib.TCOD_parse_integer_value.restype=TCOD_value_t
831
+#    lib.TCOD_parse_integer_value.argtypes=[]
832
+
833
+#    lib.TCOD_parse_float_value.restype=TCOD_value_t
834
+#    lib.TCOD_parse_float_value.argtypes=[]
835
+
836
+#    lib.TCOD_parse_string_value.restype=TCOD_value_t
837
+#    lib.TCOD_parse_string_value.argtypes=[]
838
+
839
+#    lib.TCOD_parse_color_value.restype=TCOD_value_t
840
+#    lib.TCOD_parse_color_value.argtypes=[]
841
+
842
+#    lib.TCOD_parse_dice_value.restype=TCOD_value_t
843
+#    lib.TCOD_parse_dice_value.argtypes=[]
844
+
845
+#    lib.TCOD_parse_value_list_value.restype=TCOD_value_t
846
+#    lib.TCOD_parse_value_list_value.argtypes=[c_void_p,c_int]
847
+
848
+#    lib.TCOD_parse_property_value.restype=TCOD_value_t
849
+#    lib.TCOD_parse_property_value.argtypes=[c_void_p, c_void_p , c_char_p, c_bool ]
850
+
851
+    lib.TCOD_path_new_using_map.restype=c_void_p
852
+    lib.TCOD_path_new_using_map.argtypes=[c_void_p , c_float ]
853
+
854
+#    lib.TCOD_path_new_using_function.restype=c_void_p
855
+#    lib.TCOD_path_new_using_function.argtypes=[c_int, c_int, TCOD_path_func_t ,c_void_p, c_float ]
856
+
857
+    lib.TCOD_path_compute.restype=c_bool
858
+    lib.TCOD_path_compute.argtypes=[c_void_p , c_int,c_int, c_int, c_int]
859
+
860
+    lib.TCOD_path_walk.restype=c_bool
861
+    lib.TCOD_path_walk.argtypes=[c_void_p , POINTER(c_int), POINTER(c_int), c_bool]
862
+
863
+    lib.TCOD_path_is_empty.restype=c_bool
864
+    lib.TCOD_path_is_empty.argtypes=[c_void_p ]
865
+
866
+    lib.TCOD_path_size.restype=c_int
867
+    lib.TCOD_path_size.argtypes=[c_void_p ]
868
+
869
+    lib.TCOD_path_reverse.restype=c_void
870
+    lib.TCOD_path_reverse.argtypes=[c_void_p ]
871
+
872
+    lib.TCOD_path_get.restype=c_void
873
+    lib.TCOD_path_get.argtypes=[c_void_p , c_int, POINTER(c_int), POINTER(c_int)]
874
+
875
+    lib.TCOD_path_get_origin.restype=c_void
876
+    lib.TCOD_path_get_origin.argtypes=[c_void_p , POINTER(c_int), POINTER(c_int)]
877
+
878
+    lib.TCOD_path_get_destination.restype=c_void
879
+    lib.TCOD_path_get_destination.argtypes=[c_void_p , POINTER(c_int), POINTER(c_int)]
880
+
881
+    lib.TCOD_path_delete.restype=c_void
882
+    lib.TCOD_path_delete.argtypes=[c_void_p ]
883
+
884
+    lib.TCOD_dijkstra_new .restype=c_void_p
885
+    lib.TCOD_dijkstra_new .argtypes=[c_void_p , c_float ]
886
+
887
+#    lib.TCOD_dijkstra_new_using_function.restype=c_void_p
888
+#    lib.TCOD_dijkstra_new_using_function.argtypes=[c_int, c_int, TCOD_path_func_t ,c_void_p, c_float ]
889
+
890
+    lib.TCOD_dijkstra_compute .restype=c_void
891
+    lib.TCOD_dijkstra_compute .argtypes=[c_void_p , c_int, c_int]
892
+
893
+    lib.TCOD_dijkstra_get_distance .restype=c_float
894
+    lib.TCOD_dijkstra_get_distance .argtypes=[c_void_p , c_int, c_int]
895
+
896
+    lib.TCOD_dijkstra_path_set .restype=c_bool
897
+    lib.TCOD_dijkstra_path_set .argtypes=[c_void_p , c_int, c_int]
898
+
899
+    lib.TCOD_dijkstra_is_empty.restype=c_bool
900
+    lib.TCOD_dijkstra_is_empty.argtypes=[c_void_p ]
901
+
902
+    lib.TCOD_dijkstra_size.restype=c_int
903
+    lib.TCOD_dijkstra_size.argtypes=[c_void_p ]
904
+
905
+    lib.TCOD_dijkstra_reverse.restype=c_void
906
+    lib.TCOD_dijkstra_reverse.argtypes=[c_void_p ]
907
+
908
+    lib.TCOD_dijkstra_get.restype=c_void
909
+    lib.TCOD_dijkstra_get.argtypes=[c_void_p , c_int, POINTER(c_int), POINTER(c_int)]
910
+
911
+    lib.TCOD_dijkstra_path_walk .restype=c_bool
912
+    lib.TCOD_dijkstra_path_walk .argtypes=[c_void_p , POINTER(c_int), POINTER(c_int)]
913
+
914
+    lib.TCOD_dijkstra_delete .restype=c_void
915
+    lib.TCOD_dijkstra_delete .argtypes=[c_void_p ]
916
+
917
+    lib.TCOD_sys_elapsed_milli.restype=c_int
918
+    lib.TCOD_sys_elapsed_milli.argtypes=[]
919
+
920
+    lib.TCOD_sys_elapsed_seconds.restype=c_float
921
+    lib.TCOD_sys_elapsed_seconds.argtypes=[]
922
+
923
+    lib.TCOD_sys_sleep_milli.restype=c_void
924
+    lib.TCOD_sys_sleep_milli.argtypes=[c_int ]
925
+
926
+    lib.TCOD_sys_save_screenshot.restype=c_void
927
+    lib.TCOD_sys_save_screenshot.argtypes=[c_char_p]
928
+
929
+    lib.TCOD_sys_force_fullscreen_resolution.restype=c_void
930
+    lib.TCOD_sys_force_fullscreen_resolution.argtypes=[c_int, c_int]
931
+
932
+    lib.TCOD_sys_set_renderer.restype=c_void
933
+    lib.TCOD_sys_set_renderer.argtypes=[c_int ]
934
+
935
+    lib.TCOD_sys_get_renderer.restype=c_int
936
+    lib.TCOD_sys_get_renderer.argtypes=[]
937
+
938
+    lib.TCOD_sys_set_fps.restype=c_void
939
+    lib.TCOD_sys_set_fps.argtypes=[c_int]
940
+
941
+    lib.TCOD_sys_get_fps.restype=c_int
942
+    lib.TCOD_sys_get_fps.argtypes=[]
943
+
944
+    lib.TCOD_sys_get_last_frame_length.restype=c_float
945
+    lib.TCOD_sys_get_last_frame_length.argtypes=[]
946
+
947
+    lib.TCOD_sys_get_current_resolution.restype=c_void
948
+    lib.TCOD_sys_get_current_resolution.argtypes=[POINTER(c_int), POINTER(c_int)]
949
+
950
+    lib.TCOD_sys_get_fullscreen_offsets.restype=c_void
951
+    lib.TCOD_sys_get_fullscreen_offsets.argtypes=[POINTER(c_int), POINTER(c_int)]
952
+
953
+    lib.TCOD_sys_update_char.restype=c_void
954
+    lib.TCOD_sys_update_char.argtypes=[c_int, c_int, c_int, c_void_p , c_int, c_int]
955
+
956
+    lib.TCOD_sys_get_char_size.restype=c_void
957
+    lib.TCOD_sys_get_char_size.argtypes=[POINTER(c_int), POINTER(c_int)]
958
+
959
+    lib.TCOD_sys_wait_for_event.restype=c_int
960
+    lib.TCOD_sys_wait_for_event.argtypes=[c_int, c_void_p, c_void_p, c_bool ]
961
+
962
+    lib.TCOD_sys_check_for_event.restype=c_int
963
+    lib.TCOD_sys_check_for_event.argtypes=[c_int, c_void_p, c_void_p]
964
+
965
+    lib.TCOD_sys_create_directory.restype=c_bool
966
+    lib.TCOD_sys_create_directory.argtypes=[c_char_p]
967
+
968
+    lib.TCOD_sys_delete_file.restype=c_bool
969
+    lib.TCOD_sys_delete_file.argtypes=[c_char_p]
970
+
971
+    lib.TCOD_sys_delete_directory.restype=c_bool
972
+    lib.TCOD_sys_delete_directory.argtypes=[c_char_p]
973
+
974
+    lib.TCOD_sys_is_directory.restype=c_bool
975
+    lib.TCOD_sys_is_directory.argtypes=[c_char_p]
976
+
977
+    lib.TCOD_sys_get_directory_content.restype=c_void_p
978
+    lib.TCOD_sys_get_directory_content.argtypes=[c_char_p, c_char_p]
979
+
980
+    lib.TCOD_sys_file_exists.restype=c_bool
981
+#    lib.TCOD_sys_file_exists.argtypes=[c_char_p , ...]
982
+
983
+    lib.TCOD_sys_clipboard_set.restype=c_void
984
+    lib.TCOD_sys_clipboard_set.argtypes=[c_char_p]
985
+
986
+    lib.TCOD_sys_clipboard_get.restype=c_char_p
987
+    lib.TCOD_sys_clipboard_get.argtypes=[]
988
+
989
+    #_lib.TCOD_thread_new.restype=TCOD_thread_t
990
+    #_lib.TCOD_thread_new.argtypes=[c_int(*func)(void_p),c_void_p]
991
+
992
+    #_lib.TCOD_thread_delete.restype=c_void
993
+    #_lib.TCOD_thread_delete.argtypes=[TCOD_thread_t ]
994
+
995
+    lib.TCOD_sys_get_num_cores.restype=c_int
996
+    lib.TCOD_sys_get_num_cores.argtypes=[]
997
+
998
+    lib.TCOD_thread_wait.restype=c_void
999
+    lib.TCOD_thread_wait.argtypes=[c_void_p ]
1000
+
1001
+    lib.TCOD_mutex_new.restype=c_void_p
1002
+    lib.TCOD_mutex_new.argtypes=[]
1003
+
1004
+    lib.TCOD_mutex_in.restype=c_void
1005
+    lib.TCOD_mutex_in.argtypes=[c_void_p ]
1006
+
1007
+    lib.TCOD_mutex_out.restype=c_void
1008
+    lib.TCOD_mutex_out.argtypes=[c_void_p ]
1009
+
1010
+    lib.TCOD_mutex_delete.restype=c_void
1011
+    lib.TCOD_mutex_delete.argtypes=[c_void_p ]
1012
+
1013
+    lib.TCOD_semaphore_new.restype=c_void_p
1014
+    lib.TCOD_semaphore_new.argtypes=[c_int]
1015
+
1016
+    lib.TCOD_semaphore_lock.restype=c_void
1017
+    lib.TCOD_semaphore_lock.argtypes=[c_void_p ]
1018
+
1019
+    lib.TCOD_semaphore_unlock.restype=c_void
1020
+    lib.TCOD_semaphore_unlock.argtypes=[c_void_p ]
1021
+
1022
+    lib.TCOD_semaphore_delete.restype=c_void
1023
+    lib.TCOD_semaphore_delete.argtypes=[ c_void_p ]
1024
+
1025
+    lib.TCOD_condition_new.restype=c_void_p
1026
+    lib.TCOD_condition_new.argtypes=[]
1027
+
1028
+    lib.TCOD_condition_signal.restype=c_void
1029
+    lib.TCOD_condition_signal.argtypes=[c_void_p ]
1030
+
1031
+    lib.TCOD_condition_broadcast.restype=c_void
1032
+    lib.TCOD_condition_broadcast.argtypes=[c_void_p ]
1033
+
1034
+    lib.TCOD_condition_wait.restype=c_void
1035
+    lib.TCOD_condition_wait.argtypes=[c_void_p , c_void_p ]
1036
+
1037
+    lib.TCOD_condition_delete.restype=c_void
1038
+    lib.TCOD_condition_delete.argtypes=[ c_void_p ]
1039
+
1040
+    #_lib.TCOD_load_library.restype=TCOD_library_t
1041
+    #_lib.TCOD_load_library.argtypes=[c_char_p]
1042
+
1043
+    #_lib.TCOD_get_function_address.restype=c_void_p
1044
+    #_lib.TCOD_get_function_address.argtypes=[TCOD_library_t , c_char_pfunction_]
1045
+
1046
+    #_lib.TCOD_close_library.restype=c_void
1047
+    #_lib.TCOD_close_library.argtypes=[TCOD_library_]
1048
+
1049
+    #_lib.TCOD_sys_register_SDL_renderer.restype=c_void
1050
+    #_lib.TCOD_sys_register_SDL_renderer.argtypes=[SDL_renderer_t ]
1051
+
1052
+    lib.TCOD_tree_new.restype=c_void_p
1053
+    lib.TCOD_tree_new.argtypes=[]
1054
+
1055
+    lib.TCOD_tree_add_son.restype=c_void
1056
+    lib.TCOD_tree_add_son.argtypes=[c_void_p, c_void_p]
1057
+
1058
+    lib.TCOD_text_init.restype=c_void_p
1059
+    lib.TCOD_text_init.argtypes=[c_int, c_int, c_int, c_int, c_int]
1060
+
1061
+    lib.TCOD_text_set_properties.restype=c_void
1062
+    lib.TCOD_text_set_properties.argtypes=[c_void_p , c_int, c_int, c_char_p , c_int]
1063
+
1064
+    lib.TCOD_text_set_colors.restype=c_void
1065
+    lib.TCOD_text_set_colors.argtypes=[c_void_p , c_int , c_int , c_float]
1066
+
1067
+    lib.TCOD_text_update.restype=c_bool
1068
+    lib.TCOD_text_update.argtypes=[c_void_p , c_int ]
1069
+
1070
+    lib.TCOD_text_render.restype=c_void
1071
+    lib.TCOD_text_render.argtypes=[c_void_p , c_void_p ]
1072
+
1073
+    lib.TCOD_text_get.restype=c_char_p
1074
+    lib.TCOD_text_get.argtypes=[c_void_p ]
1075
+
1076
+    lib.TCOD_text_reset.restype=c_void
1077
+    lib.TCOD_text_reset.argtypes=[c_void_p ]
1078
+
1079
+    lib.TCOD_text_delete.restype=c_void
1080
+    lib.TCOD_text_delete.argtypes=[c_void_p ]
1081
+
1082
+    lib.TCOD_console_fill_background.restype=c_void
1083
+    lib.TCOD_console_fill_background.argtypes=[c_void_p , POINTER(c_int), POINTER(c_int), POINTER(c_int)]
1084
+
1085
+    lib.TCOD_console_fill_foreground.restype=c_void
1086
+    lib.TCOD_console_fill_foreground.argtypes=[c_void_p , POINTER(c_int), POINTER(c_int), POINTER(c_int)]
1087
+
1088
+    lib.TCOD_console_fill_char.restype=c_void
1089
+    lib.TCOD_console_fill_char.argtypes=[c_void_p , POINTER(c_int)]
1090
+
1091
+    lib.TCOD_console_double_hline.restype=c_void
1092
+    lib.TCOD_console_double_hline.argtypes=[c_void_p ,c_int,c_int, c_int]
1093
+
1094
+    lib.TCOD_console_double_vline.restype=c_void
1095
+    lib.TCOD_console_double_vline.argtypes=[c_void_p ,c_int,c_int]
1096
+
1097
+    lib.TCOD_console_print_double_frame.restype=c_void
1098
+    lib.TCOD_console_print_double_frame.argtypes=[c_void_p ,c_int,c_int]
1099
+
1100
+    lib.TCOD_console_print_return_string.restype=c_char_p
1101
+    lib.TCOD_console_print_return_string.argtypes=[c_void_p ,c_int]
1102
+
1103
+    lib.TCOD_image_set_key_color_wrapper.restype=c_void
1104
+    lib.TCOD_image_set_key_color_wrapper.argtypes=[c_void_p ]
1105
+
1106
+    lib.TCOD_mouse_get_status_wrapper.restype=c_void
1107
+    lib.TCOD_mouse_get_status_wrapper.argtypes=[c_void_p]
1108
+
1109
+    lib.TCOD_zip_new.restype=c_void_p
1110
+    lib.TCOD_zip_new.argtypes=[]
1111
+
1112
+    lib.TCOD_zip_delete.restype=c_void
1113
+    lib.TCOD_zip_delete.argtypes=[c_void_p ]
1114
+
1115
+    lib.TCOD_zip_put_char.restype=c_void
1116
+    lib.TCOD_zip_put_char.argtypes=[c_void_p , c_char ]
1117
+
1118
+    lib.TCOD_zip_put_int.restype=c_void
1119
+    lib.TCOD_zip_put_int.argtypes=[c_void_p , c_int]
1120
+
1121
+    lib.TCOD_zip_put_float.restype=c_void
1122
+    lib.TCOD_zip_put_float.argtypes=[c_void_p , c_float ]
1123
+
1124
+    lib.TCOD_zip_put_string.restype=c_void
1125
+    lib.TCOD_zip_put_string.argtypes=[c_void_p , c_char_p]
1126
+
1127
+    lib.TCOD_zip_put_color.restype=c_void
1128
+    lib.TCOD_zip_put_color.argtypes=[c_void_p , c_int ]
1129
+
1130
+    lib.TCOD_zip_put_image.restype=c_void
1131
+    lib.TCOD_zip_put_image.argtypes=[c_void_p , c_void_p ]
1132
+
1133
+    lib.TCOD_zip_put_console.restype=c_void
1134
+    lib.TCOD_zip_put_console.argtypes=[c_void_p , c_void_p ]
1135
+
1136
+    lib.TCOD_zip_put_data.restype=c_void
1137
+    lib.TCOD_zip_put_data.argtypes=[c_void_p , c_int,c_void_p]
1138
+
1139
+    lib.TCOD_zip_get_current_bytes.restype=c_int
1140
+    lib.TCOD_zip_get_current_bytes.argtypes=[c_void_p ]
1141
+
1142
+    lib.TCOD_zip_save_to_file.restype=c_int
1143
+    lib.TCOD_zip_save_to_file.argtypes=[c_void_p , c_char_p]
1144
+
1145
+    lib.TCOD_zip_load_from_file.restype=c_int
1146
+    lib.TCOD_zip_load_from_file.argtypes=[c_void_p , c_char_p]
1147
+
1148
+    lib.TCOD_zip_get_char.restype=c_char
1149
+    lib.TCOD_zip_get_char.argtypes=[c_void_p ]
1150
+
1151
+    lib.TCOD_zip_get_int.restype=c_int
1152
+    lib.TCOD_zip_get_int.argtypes=[c_void_p ]
1153
+
1154
+    lib.TCOD_zip_get_float.restype=c_float
1155
+    lib.TCOD_zip_get_float.argtypes=[c_void_p ]
1156
+
1157
+    lib.TCOD_zip_get_string.restype=c_char_p
1158
+    lib.TCOD_zip_get_string.argtypes=[c_void_p ]
1159
+
1160
+    lib.TCOD_zip_get_color.restype=c_int
1161
+    lib.TCOD_zip_get_color.argtypes=[c_void_p ]
1162
+
1163
+    lib.TCOD_zip_get_image.restype=c_void_p
1164
+    lib.TCOD_zip_get_image.argtypes=[c_void_p ]
1165
+
1166
+    lib.TCOD_zip_get_console.restype=c_void_p
1167
+    lib.TCOD_zip_get_console.argtypes=[c_void_p ]
1168
+
1169
+    lib.TCOD_zip_get_data.restype=c_int
1170
+    lib.TCOD_zip_get_data.argtypes=[c_void_p , c_int,c_void_p]
1171
+
1172
+    lib.TCOD_zip_get_remaining_bytes.restype=c_int
1173
+    lib.TCOD_zip_get_remaining_bytes.argtypes=[c_void_p ]
1174
+
1175
+    lib.TCOD_zip_skip_bytes.restype=c_void
1176
+    lib.TCOD_zip_skip_bytes.argtypes=[c_void_p ,c_int ]
1177
+
0 1178
new file mode 100644
... ...
@@ -0,0 +1,153 @@
1
+from __future__ import print_function
2
+import numpy as np
3
+
4
+class CoordPair(object):
5
+   def __init__(self, fst, snd=None):
6
+      if snd == None: fst, snd = fst
7
+      self.fst, self.snd = fst,snd
8
+
9
+   @property
10
+   def pair(self):
11
+      return self.fst, self.snd
12
+
13
+   def __len__(self): return 2
14
+   def __iter__(self): return iter(self.pair)
15
+   def __getitem__(self, idx):
16
+      if idx == 0: return self.fst
17
+      elif idx == 1: return self.snd
18
+      else: raise KeyError("Only two elements in a coordpair")
19
+
20
+   def transform(self, *transforms):
21
+      '''Note: mul _then_ add'''
22
+      f,s = self.pair
23
+      for transform in transforms:
24
+         x = transform.get('mul', (1,1))
25
+         if not hasattr(x, '__iter__'): x=(x,x)
26
+         f1,f2 = x
27
+         f *= f1
28
+         s *= f2
29
+         x = transform.get('add', (0,0))
30
+         if not hasattr(x, '__iter__'): x=(x,x)
31
+         f1,f2 = x
32
+         f += f1
33
+         s += f2
34
+      return f,s
35
+
36
+   def __ne__(self, other):
37
+      return not self.__eq__(other)
38
+   def __rne__(self, other):
39
+      return not self.__eq__(other)
40
+
41
+   def __eq__(self, other):
42
+      a,b = self
43
+      c,d = other
44
+      return a==c and b==d
45
+   def __req__(self, other):
46
+      return self == other
47
+
48
+   def __add__(self, other):
49
+      return self.__class__(self.transform({'add': other}))
50
+   def __radd__(self, other):
51
+      return self.__class__(self.transform({'add': other}))
52
+
53
+   def __mul__(self, other):
54
+      return self.__class__(self.transform({'mul': other}))
55
+   def __rmul__(self, other):
56
+      return self.__class__(self.transform({'mul': other}))
57
+
58
+
59
+   def __sub__(self, other):
60
+      a,b = other
61
+      return self.__class__(self.transform({'add': (-a,-b)}))
62
+   def __rsub__(self, other):
63
+      a,b = other
64
+      return self.__class__(self.transform({'add': (-a,-b)}))
65
+
66
+   def __div__(self, other):
67
+      return self.__class__(self.transform({'mul': 1.0/other}))
68
+   def __rdiv__(self, other):
69
+      return self.__class__(self.transform({'mul': 1.0/other}))
70
+
71
+   def __repr__(self):
72
+      return '%s(%s,%s)' % (self.__class__.__name__, self.fst, self.snd)
73
+
74
+class MazeDigger(object):
75
+   def __init__(self, traveller, size, multiplier=3):
76
+      self.t = traveller
77
+      self.size = CoordPair(*size)*multiplier
78
+      self.mult = multiplier
79
+      self.map = np.ones(self.size+1, int)*2
80
+
81
+   def clamp(self, start):
82
+      if start.fst < 0: start.fst = 0
83
+      elif start.fst >= self.size.fst: start.fst = self.size.fst-1
84
+      if start.snd < 0: start.snd = 0
85
+      elif start.snd >= self.size.snd: start.snd = self.size.snd-1
86
+      return start
87
+
88
+   def draw_line(self, fro, to):
89
+      (x1,y1),  (x2,y2) = fro, to
90
+      if x2<x1: x1,x2 = x2,x1
91
+      if y2<y1: y1,y2 = y2,y1
92
+      x1*=self.mult;x2*=self.mult
93
+      x2 += 1
94
+      y1*=self.mult;y2*=self.mult
95
+      y2 += 1
96
+      self.map[x1+1:x2+1,y1+1:y2+1] = 3
97
+
98
+   def make_map(self):
99
+      for x,y in self.t.visited:
100
+         self.map[x*self.mult:(x+1)*self.mult, y*self.mult:(y+1)*self.mult] = 0
101
+      for fro, to in self.t.connections:
102
+         self.draw_line(fro, to)
103
+      x,y = self.t.pos
104
+      #self.map[x*self.mult:(x+1)*self.mult, y*self.mult:(y+1)*self.mult] = 1
105
+      return self
106
+
107
+   def show_map(self):
108
+      nmap = np.rollaxis(self.map, 1)
109
+      for row in nmap:
110
+         for col in row:
111
+            if col == 3: print('.', end='')
112
+            if col == 2: print('#', end='')
113
+            if col == 1: print('o', end='')
114
+            if col == 0: print('x', end='')
115
+         print()
116
+
117
+   def tcod_show_map(self):
118
+      nmap = self.map.copy()
119
+      nmap = nmap.max() - nmap
120
+      omin = nmap.min()
121
+      nmap -= omin
122
+      omax = nmap.max()
123
+      nmap *= 255
124
+      nmap /= omax
125
+      nmap = np.rollaxis(nmap, 1)
126
+      tc.console_fill_background(0, nmap,nmap,nmap)
127
+
128
+
129
+if __name__ == '__main__':
130
+   import wilson as aldus
131
+   import time
132
+   import libtcodpy as tc
133
+
134
+   self = MazeDigger(aldus.t, (aldus.x,aldus.y))
135
+
136
+   tc.console_init_root(self.size.fst+1, self.size.snd+1, 'The Title', False, 2)
137
+   tc.sys_set_fps(30)
138
+
139
+   key, mouse = tc.Key(), tc.Mouse()
140
+
141
+   walk_result = False
142
+   while True:
143
+      tc.sys_check_for_event(tc.EVENT_KEY_PRESS|tc.EVENT_MOUSE|tc.KEY_PRESSED, key, mouse)
144
+      if key.c == ord('q'): break
145
+
146
+      if not walk_result:
147
+         walk_result = aldus.t.random_walk(aldus.maze)
148
+         self.make_map()
149
+
150
+         tc.sys_save_screenshot('tmp.png')
151
+         self.tcod_show_map()
152
+
153
+      tc.console_flush()
0 154
new file mode 100644
... ...
@@ -0,0 +1,101 @@
1
+from __future__ import print_function
2
+import numpy as np
3
+
4
+class Traveller(object):
5
+	@property
6
+	def x(self): return self.pos[0]
7
+	@x.setter
8
+	def x(self, val): self.pos = val, self.pos[1]
9
+
10
+	@property
11
+	def y(self): return self.pos[1]
12
+	@y.setter
13
+	def y(self, val): self.pos = self.pos[0], val
14
+
15
+	def __init__(self, starting_cell):
16
+		self.pos = (0,0)
17
+		self.connections = []
18
+		self.visited = set()
19
+		self.thresh = 0.5# np.random.normal(0.5, 0.15)
20
+		print(self.thresh)
21
+
22
+	def random_walk(self, array):
23
+		if self.x >= array.shape[0]:
24
+			return True
25
+		else:
26
+			row = array[self.x]
27
+			
28
+			for self.y in range(array.shape[1]-1):
29
+				if row[self.y] != row[self.y+1] and np.random.random() < self.thresh:
30
+					row[self.y+1] = row[self.y]
31
+					self.connections.append(((self.x, self.y), (self.x, self.y+1)))
32
+					#self.visited.add((self.x, self.y))
33
+
34
+			new = [0]*array.shape[0]
35
+			if self.x < array.shape[0]-2:
36
+				new, idxs = prop_down(array[self.x])
37
+				self.connections.extend(((self.x, y),(self.x+1,y)) for y in idxs)
38
+
39
+
40
+			first_virt = False
41
+			if self.x == array.shape[0]-1:
42
+				for idx in range(array.shape[1]-1):
43
+					if array[self.x-1][idx] != array[self.x-1][idx+1]:
44
+						self.connections.append(((self.x-1, idx), (self.x, idx)))
45
+						self.connections.append(((self.x-1, idx+1), (self.x, idx+1)))
46
+						self.connections.append(((self.x, idx), (self.x, idx+1)))
47
+						if not first_virt:
48
+							self.connections.append(((self.x, idx-1), (self.x, idx)))
49
+							first_virt = True
50
+					else:
51
+						self.connections.append(((self.x, idx-1), (self.x, idx)))
52
+				lrow = array[self.x-1]
53
+				if lrow[-2] == lrow[-1]:
54
+					self.connections.append(((self.x, array.shape[1]-2), (self.x, array.shape[1]-1)))
55
+
56
+
57
+
58
+
59
+			self.x += 1
60
+			if self.x < array.shape[0]-1:
61
+				array[self.x] = new
62
+
63
+import random
64
+
65
+def prop_down(row, early=False):
66
+	def collect(r):
67
+		out = [[(0,r[0])]]
68
+		for idx,x in enumerate(r[1:],1):
69
+			if x != out[-1][-1][1]:
70
+				out.append([])
71
+			out[-1].append((idx,x))
72
+		return [[x[0] for x in y] for y in out]
73
+	idxs = collect(row)
74
+	prop = map(random.choice, idxs)
75
+	new = [0]*len(row)
76
+	for x in prop: new[x] = row[x]
77
+	if not early:
78
+		unused = set(range(1,len(row)+1)) - set(new)
79
+		for idx,x in enumerate(new):
80
+			if x == 0:
81
+				new[idx] = unused.pop()
82
+	return new, prop
83
+
84
+x,y = 39,19
85
+maze = np.zeros((x,y), int)
86
+maze[0] = range(1,y+1)
87
+maze.shape = x,y
88
+
89
+t = Traveller((x/2, y/2))
90
+
91
+if __name__ == '__main__':
92
+	import display
93
+	import time
94
+	while True:
95
+		print('c')
96
+		self = display.MazeDigger(t, (x,y))
97
+		t.random_walk(maze)
98
+		self.make_map()
99
+		self.show_map()
100
+		time.sleep(0.4)
101
+		print()
0 102
new file mode 100755
1 103
Binary files /dev/null and b/libtcod.dylib differ
2 104
new file mode 100755
3 105
Binary files /dev/null and b/libtcodgui.dylib differ
4 106
new file mode 100644
... ...
@@ -0,0 +1,1973 @@
1
+#
2
+# libtcod 1.5.2 python wrapper
3
+# Copyright (c) 2008,2009,2010 Jice & Mingos
4
+# All rights reserved.
5
+#
6
+# Redistribution and use in source and binary forms, with or without
7
+# modification, are permitted provided that the following conditions are met:
8
+#     * Redistributions of source code must retain the above copyright
9
+#       notice, this list of conditions and the following disclaimer.
10
+#     * Redistributions in binary form must reproduce the above copyright
11
+#       notice, this list of conditions and the following disclaimer in the
12
+#       documentation and/or other materials provided with the distribution.
13
+#     * The name of Jice or Mingos may not be used to endorse or promote products
14
+#       derived from this software without specific prior written permission.
15
+#
16
+# THIS SOFTWARE IS PROVIDED BY JICE AND MINGOS ``AS IS'' AND ANY
17
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+# DISCLAIMED. IN NO EVENT SHALL JICE OR MINGOS BE LIABLE FOR ANY
20
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+#
27
+
28
+import sys
29
+import ctypes
30
+import struct
31
+from ctypes import *
32
+
33
+if not hasattr(ctypes, "c_bool"):   # for Python < 2.6
34
+    c_bool = c_uint8
35
+
36
+try:  #import NumPy if available
37
+    import numpy
38
+    numpy_available = True
39
+except ImportError:
40
+    numpy_available = False
41
+
42
+LINUX=False
43
+MAC=False
44
+MINGW=False
45
+MSVC=False
46
+if sys.platform.find('linux') != -1:
47
+    _lib = ctypes.cdll['./libtcod.so']
48
+    LINUX=True
49
+elif sys.platform.find('darwin') != -1:
50
+    _lib = ctypes.cdll['./libtcod.dylib']
51
+    MAC = True
52
+elif sys.platform.find('haiku') != -1:
53
+    _lib = ctypes.cdll['./libtcod.so']
54
+    HAIKU = True
55
+else:
56
+    try:
57
+        _lib = ctypes.cdll['./libtcod-mingw.dll']
58
+        MINGW=True
59
+    except WindowsError:
60
+        _lib = ctypes.cdll['./libtcod-VS.dll']
61
+        MSVC=True
62
+    # On Windows, ctypes doesn't work well with function returning structs,
63
+    # so we have to user the _wrapper functions instead
64
+    _lib.TCOD_color_multiply = _lib.TCOD_color_multiply_wrapper
65
+    _lib.TCOD_color_add = _lib.TCOD_color_add_wrapper
66
+    _lib.TCOD_color_multiply_scalar = _lib.TCOD_color_multiply_scalar_wrapper
67
+    _lib.TCOD_color_subtract = _lib.TCOD_color_subtract_wrapper
68
+    _lib.TCOD_color_lerp = _lib.TCOD_color_lerp_wrapper
69
+    _lib.TCOD_console_get_default_background = _lib.TCOD_console_get_default_background_wrapper
70
+    _lib.TCOD_console_get_default_foreground = _lib.TCOD_console_get_default_foreground_wrapper
71
+    _lib.TCOD_console_get_char_background = _lib.TCOD_console_get_char_background_wrapper
72
+    _lib.TCOD_console_get_char_foreground = _lib.TCOD_console_get_char_foreground_wrapper
73
+    _lib.TCOD_console_get_fading_color = _lib.TCOD_console_get_fading_color_wrapper
74
+    _lib.TCOD_image_get_pixel = _lib.TCOD_image_get_pixel_wrapper
75
+    _lib.TCOD_image_get_mipmap_pixel = _lib.TCOD_image_get_mipmap_pixel_wrapper
76
+    _lib.TCOD_parser_get_color_property = _lib.TCOD_parser_get_color_property_wrapper
77
+
78
+HEXVERSION = 0x010502
79
+STRVERSION = "1.5.2"
80
+TECHVERSION = 0x01050200
81
+
82
+############################
83
+# color module
84
+############################
85
+class Color(Structure):
86
+    _fields_ = [('r', c_uint8),
87
+                ('g', c_uint8),
88
+                ('b', c_uint8),
89
+                ]
90
+
91
+    def __eq__(self, c):
92
+        return _lib.TCOD_color_equals(self, c)
93
+
94
+    def __mul__(self, c):
95
+        if isinstance(c,Color):
96
+            return _lib.TCOD_color_multiply(self, c)
97
+        else:
98
+            return _lib.TCOD_color_multiply_scalar(self, c_float(c))
99
+
100
+    def __add__(self, c):
101
+        return _lib.TCOD_color_add(self, c)
102
+
103
+    def __sub__(self, c):
104
+        return _lib.TCOD_color_subtract(self, c)
105
+
106
+    def __repr__(self):
107
+        return "Color(%d,%d,%d)" % (self.r, self.g, self.b)
108
+
109
+    def __getitem__(self, i):
110
+        if type(i) == str:
111
+            return getattr(self, i)
112
+        else:
113
+            return getattr(self, "rgb"[i])
114
+
115
+    def __setitem__(self, i, c):
116
+        if type(i) == str:
117
+            setattr(self, i, c)
118
+        else:
119
+            setattr(self, "rgb"[i], c)
120
+
121
+    def __iter__(self):
122
+        yield self.r
123
+        yield self.g
124
+        yield self.b
125
+
126
+# Should be valid on any platform, check it!  Has to be done after Color is defined.
127
+if MAC:
128
+    from cprotos import setup_protos
129
+    setup_protos(_lib)
130
+
131
+_lib.TCOD_color_equals.restype = c_bool
132
+_lib.TCOD_color_multiply.restype = Color
133
+_lib.TCOD_color_multiply_scalar.restype = Color
134
+_lib.TCOD_color_add.restype = Color
135
+_lib.TCOD_color_subtract.restype = Color
136
+
137
+# default colors
138
+# grey levels
139
+black=Color(0,0,0)
140
+darkest_grey=Color(31,31,31)
141
+darker_grey=Color(63,63,63)
142
+dark_grey=Color(95,95,95)
143
+grey=Color(127,127,127)
144
+light_grey=Color(159,159,159)
145
+lighter_grey=Color(191,191,191)
146
+lightest_grey=Color(223,223,223)
147
+darkest_gray=Color(31,31,31)
148
+darker_gray=Color(63,63,63)
149
+dark_gray=Color(95,95,95)
150
+gray=Color(127,127,127)
151
+light_gray=Color(159,159,159)
152
+lighter_gray=Color(191,191,191)
153
+lightest_gray=Color(223,223,223)
154
+white=Color(255,255,255)
155
+
156
+# sepia
157
+darkest_sepia=Color(31,24,15)
158
+darker_sepia=Color(63,50,31)
159
+dark_sepia=Color(94,75,47)
160
+sepia=Color(127,101,63)
161
+light_sepia=Color(158,134,100)
162
+lighter_sepia=Color(191,171,143)
163
+lightest_sepia=Color(222,211,195)
164
+
165
+#standard colors
166
+red=Color(255,0,0)
167
+flame=Color(255,63,0)
168
+orange=Color(255,127,0)
169
+amber=Color(255,191,0)
170
+yellow=Color(255,255,0)
171
+lime=Color(191,255,0)
172
+chartreuse=Color(127,255,0)
173
+green=Color(0,255,0)
174
+sea=Color(0,255,127)
175
+turquoise=Color(0,255,191)
176
+cyan=Color(0,255,255)
177
+sky=Color(0,191,255)
178
+azure=Color(0,127,255)
179
+blue=Color(0,0,255)
180
+han=Color(63,0,255)
181
+violet=Color(127,0,255)
182
+purple=Color(191,0,255)
183
+fuchsia=Color(255,0,255)
184
+magenta=Color(255,0,191)
185
+pink=Color(255,0,127)
186
+crimson=Color(255,0,63)
187
+
188
+# dark colors
189
+dark_red=Color(191,0,0)
190
+dark_flame=Color(191,47,0)
191
+dark_orange=Color(191,95,0)
192
+dark_amber=Color(191,143,0)
193
+dark_yellow=Color(191,191,0)
194
+dark_lime=Color(143,191,0)
195
+dark_chartreuse=Color(95,191,0)
196
+dark_green=Color(0,191,0)
197
+dark_sea=Color(0,191,95)
198
+dark_turquoise=Color(0,191,143)
199
+dark_cyan=Color(0,191,191)
200
+dark_sky=Color(0,143,191)
201
+dark_azure=Color(0,95,191)
202
+dark_blue=Color(0,0,191)
203
+dark_han=Color(47,0,191)
204
+dark_violet=Color(95,0,191)
205
+dark_purple=Color(143,0,191)
206
+dark_fuchsia=Color(191,0,191)
207
+dark_magenta=Color(191,0,143)
208
+dark_pink=Color(191,0,95)
209
+dark_crimson=Color(191,0,47)
210
+
211
+# darker colors
212
+darker_red=Color(127,0,0)
213
+darker_flame=Color(127,31,0)
214
+darker_orange=Color(127,63,0)
215
+darker_amber=Color(127,95,0)
216
+darker_yellow=Color(127,127,0)
217
+darker_lime=Color(95,127,0)
218
+darker_chartreuse=Color(63,127,0)
219
+darker_green=Color(0,127,0)
220
+darker_sea=Color(0,127,63)
221
+darker_turquoise=Color(0,127,95)
222
+darker_cyan=Color(0,127,127)
223
+darker_sky=Color(0,95,127)
224
+darker_azure=Color(0,63,127)
225
+darker_blue=Color(0,0,127)
226
+darker_han=Color(31,0,127)
227
+darker_violet=Color(63,0,127)
228
+darker_purple=Color(95,0,127)
229
+darker_fuchsia=Color(127,0,127)
230
+darker_magenta=Color(127,0,95)
231
+darker_pink=Color(127,0,63)
232
+darker_crimson=Color(127,0,31)
233
+
234
+# darkest colors
235
+darkest_red=Color(63,0,0)
236
+darkest_flame=Color(63,15,0)
237
+darkest_orange=Color(63,31,0)
238
+darkest_amber=Color(63,47,0)
239
+darkest_yellow=Color(63,63,0)
240
+darkest_lime=Color(47,63,0)
241
+darkest_chartreuse=Color(31,63,0)
242
+darkest_green=Color(0,63,0)
243
+darkest_sea=Color(0,63,31)
244
+darkest_turquoise=Color(0,63,47)
245
+darkest_cyan=Color(0,63,63)
246
+darkest_sky=Color(0,47,63)
247
+darkest_azure=Color(0,31,63)
248
+darkest_blue=Color(0,0,63)
249
+darkest_han=Color(15,0,63)
250
+darkest_violet=Color(31,0,63)
251
+darkest_purple=Color(47,0,63)
252
+darkest_fuchsia=Color(63,0,63)
253
+darkest_magenta=Color(63,0,47)
254
+darkest_pink=Color(63,0,31)
255
+darkest_crimson=Color(63,0,15)
256
+
257
+# light colors
258
+light_red=Color(255,114,114)
259
+light_flame=Color(255,149,114)
260
+light_orange=Color(255,184,114)
261
+light_amber=Color(255,219,114)
262
+light_yellow=Color(255,255,114)
263
+light_lime=Color(219,255,114)
264
+light_chartreuse=Color(184,255,114)
265
+light_green=Color(114,255,114)
266
+light_sea=Color(114,255,184)
267
+light_turquoise=Color(114,255,219)
268
+light_cyan=Color(114,255,255)
269
+light_sky=Color(114,219,255)
270
+light_azure=Color(114,184,255)
271
+light_blue=Color(114,114,255)
272
+light_han=Color(149,114,255)
273
+light_violet=Color(184,114,255)
274
+light_purple=Color(219,114,255)
275
+light_fuchsia=Color(255,114,255)
276
+light_magenta=Color(255,114,219)
277
+light_pink=Color(255,114,184)
278
+light_crimson=Color(255,114,149)
279
+
280
+#lighter colors
281
+lighter_red=Color(255,165,165)
282
+lighter_flame=Color(255,188,165)
283
+lighter_orange=Color(255,210,165)
284
+lighter_amber=Color(255,232,165)
285
+lighter_yellow=Color(255,255,165)
286
+lighter_lime=Color(232,255,165)
287
+lighter_chartreuse=Color(210,255,165)
288
+lighter_green=Color(165,255,165)
289
+lighter_sea=Color(165,255,210)
290
+lighter_turquoise=Color(165,255,232)
291
+lighter_cyan=Color(165,255,255)
292
+lighter_sky=Color(165,232,255)
293
+lighter_azure=Color(165,210,255)
294
+lighter_blue=Color(165,165,255)
295
+lighter_han=Color(188,165,255)
296
+lighter_violet=Color(210,165,255)
297
+lighter_purple=Color(232,165,255)
298
+lighter_fuchsia=Color(255,165,255)
299
+lighter_magenta=Color(255,165,232)
300
+lighter_pink=Color(255,165,210)
301
+lighter_crimson=Color(255,165,188)
302
+
303
+# lightest colors
304
+lightest_red=Color(255,191,191)
305
+lightest_flame=Color(255,207,191)
306
+lightest_orange=Color(255,223,191)
307
+lightest_amber=Color(255,239,191)
308
+lightest_yellow=Color(255,255,191)
309
+lightest_lime=Color(239,255,191)
310
+lightest_chartreuse=Color(223,255,191)
311
+lightest_green=Color(191,255,191)
312
+lightest_sea=Color(191,255,223)
313
+lightest_turquoise=Color(191,255,239)
314
+lightest_cyan=Color(191,255,255)
315
+lightest_sky=Color(191,239,255)
316
+lightest_azure=Color(191,223,255)
317
+lightest_blue=Color(191,191,255)
318
+lightest_han=Color(207,191,255)
319
+lightest_violet=Color(223,191,255)
320
+lightest_purple=Color(239,191,255)
321
+lightest_fuchsia=Color(255,191,255)
322
+lightest_magenta=Color(255,191,239)
323
+lightest_pink=Color(255,191,223)
324
+lightest_crimson=Color(255,191,207)
325
+
326
+# desaturated colors
327
+desaturated_red=Color(127,63,63)
328
+desaturated_flame=Color(127,79,63)
329
+desaturated_orange=Color(127,95,63)
330
+desaturated_amber=Color(127,111,63)
331
+desaturated_yellow=Color(127,127,63)
332
+desaturated_lime=Color(111,127,63)
333
+desaturated_chartreuse=Color(95,127,63)
334
+desaturated_green=Color(63,127,63)
335
+desaturated_sea=Color(63,127,95)
336
+desaturated_turquoise=Color(63,127,111)
337
+desaturated_cyan=Color(63,127,127)
338
+desaturated_sky=Color(63,111,127)
339
+desaturated_azure=Color(63,95,127)
340
+desaturated_blue=Color(63,63,127)
341
+desaturated_han=Color(79,63,127)
342
+desaturated_violet=Color(95,63,127)
343
+desaturated_purple=Color(111,63,127)
344
+desaturated_fuchsia=Color(127,63,127)
345
+desaturated_magenta=Color(127,63,111)
346
+desaturated_pink=Color(127,63,95)
347
+desaturated_crimson=Color(127,63,79)
348
+
349
+# metallic
350
+brass=Color(191,151,96)
351
+copper=Color(197,136,124)
352
+gold=Color(229,191,0)
353
+silver=Color(203,203,203)
354
+
355
+# miscellaneous
356
+celadon=Color(172,255,175)
357
+peach=Color(255,159,127)
358
+
359
+# color functions
360
+_lib.TCOD_color_lerp.restype = Color
361
+def color_lerp(c1, c2, a):
362
+    return _lib.TCOD_color_lerp(c1, c2, c_float(a))
363
+
364
+def color_set_hsv(c, h, s, v):
365
+    _lib.TCOD_color_set_HSV(byref(c), c_float(h), c_float(s), c_float(v))
366
+
367
+def color_get_hsv(c):
368
+    h = c_float()
369
+    s = c_float()
370
+    v = c_float()
371
+    _lib.TCOD_color_get_HSV(c, byref(h), byref(s), byref(v))
372
+    return h.value, s.value, v.value
373
+
374
+def color_scale_HSV(c, scoef, vcoef) :
375
+    _lib.TCOD_color_scale_HSV(byref(c),c_float(scoef),c_float(vcoef))
376
+
377
+def color_gen_map(colors, indexes):
378
+    ccolors = (Color * len(colors))(*colors)
379
+    cindexes = (c_int * len(indexes))(*indexes)
380
+    cres = (Color * (max(indexes) + 1))()
381
+    _lib.TCOD_color_gen_map(cres, len(colors), ccolors, cindexes)
382
+    return cres
383
+
384
+############################
385
+# console module
386
+############################
387
+class Key(Structure):
388
+    _fields_=[('vk', c_int),
389
+              ('c', c_uint8),
390
+              ('pressed', c_bool),
391
+              ('lalt', c_bool),
392
+              ('lctrl', c_bool),
393
+              ('ralt', c_bool),
394
+              ('rctrl', c_bool),
395
+              ('shift', c_bool),
396
+              ]
397
+
398
+class ConsoleBuffer:
399
+    # simple console that allows direct (fast) access to cells. simplifies
400
+    # use of the "fill" functions.
401
+    def __init__(self, width, height, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
402
+        # initialize with given width and height. values to fill the buffer
403
+        # are optional, defaults to black with no characters.
404
+        n = width * height
405
+        self.width = width
406
+        self.height = height
407
+        self.clear(back_r, back_g, back_b, fore_r, fore_g, fore_b, char)
408
+
409
+    def clear(self, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
410
+        # clears the console. values to fill it with are optional, defaults
411
+        # to black with no characters.
412
+        n = self.width * self.height
413
+        self.back_r = [back_r] * n
414
+        self.back_g = [back_g] * n
415
+        self.back_b = [back_b] * n
416
+        self.fore_r = [fore_r] * n
417
+        self.fore_g = [fore_g] * n
418
+        self.fore_b = [fore_b] * n
419
+        self.char = [ord(char)] * n
420
+    
421
+    def copy(self):
422
+        # returns a copy of this ConsoleBuffer.
423
+        other = ConsoleBuffer(0, 0)
424
+        other.width = self.width
425
+        other.height = self.height
426
+        other.back_r = list(self.back_r)  # make explicit copies of all lists
427
+        other.back_g = list(self.back_g)
428
+        other.back_b = list(self.back_b)
429
+        other.fore_r = list(self.fore_r)
430
+        other.fore_g = list(self.fore_g)
431
+        other.fore_b = list(self.fore_b)
432
+        other.char = list(self.char)
433
+        return other
434
+    
435
+    def set_fore(self, x, y, r, g, b, char):
436
+        # set the character and foreground color of one cell.
437
+        i = self.width * y + x
438
+        self.fore_r[i] = r
439
+        self.fore_g[i] = g
440
+        self.fore_b[i] = b
441
+        self.char[i] = ord(char)
442
+    
443
+    def set_back(self, x, y, r, g, b):
444
+        # set the background color of one cell.
445
+        i = self.width * y + x
446
+        self.back_r[i] = r
447
+        self.back_g[i] = g
448
+        self.back_b[i] = b
449
+    
450
+    def set(self, x, y, back_r, back_g, back_b, fore_r, fore_g, fore_b, char):
451
+        # set the background color, foreground color and character of one cell.
452
+        i = self.width * y + x
453
+        self.back_r[i] = back_r
454
+        self.back_g[i] = back_g
455
+        self.back_b[i] = back_b
456
+        self.fore_r[i] = fore_r
457
+        self.fore_g[i] = fore_g
458
+        self.fore_b[i] = fore_b
459
+        self.char[i] = ord(char)
460
+    
461
+    def blit(self, dest, fill_fore=True, fill_back=True):
462
+        # use libtcod's "fill" functions to write the buffer to a console.
463
+        if (console_get_width(dest) != self.width or
464
+            console_get_height(dest) != self.height):
465
+            raise ValueError('ConsoleBuffer.blit: Destination console has an incorrect size.')
466
+
467
+        s = struct.Struct('%di' % len(self.back_r))
468
+
469
+        if fill_back:
470
+            _lib.TCOD_console_fill_background(dest, (c_int * len(self.back_r))(*self.back_r), (c_int * len(self.back_g))(*self.back_g), (c_int * len(self.back_b))(*self.back_b))
471
+
472
+        if fill_fore:
473
+            _lib.TCOD_console_fill_foreground(dest, (c_int * len(self.fore_r))(*self.fore_r), (c_int * len(self.fore_g))(*self.fore_g), (c_int * len(self.fore_b))(*self.fore_b))
474
+            _lib.TCOD_console_fill_char(dest, (c_int * len(self.char))(*self.char))
475
+
476
+_lib.TCOD_console_credits_render.restype = c_bool
477
+_lib.TCOD_console_is_fullscreen.restype = c_bool
478
+_lib.TCOD_console_is_window_closed.restype = c_bool
479
+_lib.TCOD_console_has_mouse_focus.restype = c_bool
480
+_lib.TCOD_console_is_active.restype = c_bool
481
+_lib.TCOD_console_get_default_background.restype = Color
482
+_lib.TCOD_console_get_default_foreground.restype = Color
483
+_lib.TCOD_console_get_char_background.restype = Color
484
+_lib.TCOD_console_get_char_foreground.restype = Color
485
+_lib.TCOD_console_get_fading_color.restype = Color
486
+_lib.TCOD_console_is_key_pressed.restype = c_bool
487
+
488
+# background rendering modes
489
+BKGND_NONE = 0
490
+BKGND_SET = 1
491
+BKGND_MULTIPLY = 2
492
+BKGND_LIGHTEN = 3
493
+BKGND_DARKEN = 4
494
+BKGND_SCREEN = 5
495
+BKGND_COLOR_DODGE = 6
496
+BKGND_COLOR_BURN = 7
497
+BKGND_ADD = 8
498
+BKGND_ADDA = 9
499
+BKGND_BURN = 10
500
+BKGND_OVERLAY = 11
501
+BKGND_ALPH = 12
502
+BKGND_DEFAULT=13
503
+
504
+def BKGND_ALPHA(a):
505
+    return BKGND_ALPH | (int(a * 255) << 8)
506
+
507
+def BKGND_ADDALPHA(a):
508
+    return BKGND_ADDA | (int(a * 255) << 8)
509
+
510
+# non blocking key events types
511
+KEY_PRESSED = 1
512
+KEY_RELEASED = 2
513
+# key codes
514
+KEY_NONE = 0
515
+KEY_ESCAPE = 1
516
+KEY_BACKSPACE = 2
517
+KEY_TAB = 3
518
+KEY_ENTER = 4
519
+KEY_SHIFT = 5
520
+KEY_CONTROL = 6
521
+KEY_ALT = 7
522
+KEY_PAUSE = 8
523
+KEY_CAPSLOCK = 9
524
+KEY_PAGEUP = 10
525
+KEY_PAGEDOWN = 11
526
+KEY_END = 12
527
+KEY_HOME = 13
528
+KEY_UP = 14
529
+KEY_LEFT = 15
530
+KEY_RIGHT = 16
531
+KEY_DOWN = 17
532
+KEY_PRINTSCREEN = 18
533
+KEY_INSERT = 19
534
+KEY_DELETE = 20
535
+KEY_LWIN = 21
536
+KEY_RWIN = 22
537
+KEY_APPS = 23
538
+KEY_0 = 24
539
+KEY_1 = 25
540
+KEY_2 = 26
541
+KEY_3 = 27
542
+KEY_4 = 28
543
+KEY_5 = 29
544
+KEY_6 = 30
545
+KEY_7 = 31
546
+KEY_8 = 32
547
+KEY_9 = 33
548
+KEY_KP0 = 34
549
+KEY_KP1 = 35
550
+KEY_KP2 = 36
551
+KEY_KP3 = 37
552
+KEY_KP4 = 38
553
+KEY_KP5 = 39
554
+KEY_KP6 = 40
555
+KEY_KP7 = 41
556
+KEY_KP8 = 42
557
+KEY_KP9 = 43
558
+KEY_KPADD = 44
559
+KEY_KPSUB = 45
560
+KEY_KPDIV = 46
561
+KEY_KPMUL = 47
562
+KEY_KPDEC = 48
563
+KEY_KPENTER = 49
564
+KEY_F1 = 50
565
+KEY_F2 = 51
566
+KEY_F3 = 52
567
+KEY_F4 = 53
568
+KEY_F5 = 54
569
+KEY_F6 = 55
570
+KEY_F7 = 56
571
+KEY_F8 = 57
572
+KEY_F9 = 58
573
+KEY_F10 = 59
574
+KEY_F11 = 60
575
+KEY_F12 = 61
576
+KEY_NUMLOCK = 62
577
+KEY_SCROLLLOCK = 63
578
+KEY_SPACE = 64
579
+KEY_CHAR = 65
580
+# special chars
581
+# single walls
582
+CHAR_HLINE = 196
583
+CHAR_VLINE = 179
584
+CHAR_NE = 191
585
+CHAR_NW = 218
586
+CHAR_SE = 217
587
+CHAR_SW = 192
588
+CHAR_TEEW = 180
589
+CHAR_TEEE = 195
590
+CHAR_TEEN = 193
591
+CHAR_TEES = 194
592
+CHAR_CROSS = 197
593
+# double walls
594
+CHAR_DHLINE = 205
595
+CHAR_DVLINE = 186
596
+CHAR_DNE = 187
597
+CHAR_DNW = 201
598
+CHAR_DSE = 188
599
+CHAR_DSW = 200
600
+CHAR_DTEEW = 185
601
+CHAR_DTEEE = 204
602
+CHAR_DTEEN = 202
603
+CHAR_DTEES = 203
604
+CHAR_DCROSS = 206
605
+# blocks
606
+CHAR_BLOCK1 = 176
607
+CHAR_BLOCK2 = 177
608
+CHAR_BLOCK3 = 178
609
+# arrows
610
+CHAR_ARROW_N = 24
611
+CHAR_ARROW_S = 25
612
+CHAR_ARROW_E = 26
613
+CHAR_ARROW_W = 27
614
+# arrows without tail
615
+CHAR_ARROW2_N = 30
616
+CHAR_ARROW2_S = 31
617
+CHAR_ARROW2_E = 16
618
+CHAR_ARROW2_W = 17
619
+# double arrows
620
+CHAR_DARROW_H = 29
621
+CHAR_DARROW_V = 18
622
+# GUI stuff
623
+CHAR_CHECKBOX_UNSET = 224
624
+CHAR_CHECKBOX_SET = 225
625
+CHAR_RADIO_UNSET = 9
626
+CHAR_RADIO_SET = 10
627
+# sub-pixel resolution kit
628
+CHAR_SUBP_NW = 226
629
+CHAR_SUBP_NE = 227
630
+CHAR_SUBP_N = 228
631
+CHAR_SUBP_SE = 229
632
+CHAR_SUBP_DIAG = 230
633
+CHAR_SUBP_E = 231
634
+CHAR_SUBP_SW = 232
635
+# misc characters
636
+CHAR_BULLET = 7
637
+CHAR_BULLET_INV = 8
638
+CHAR_BULLET_SQUARE = 254
639
+CHAR_CENT = 189
640
+CHAR_CLUB = 5
641
+CHAR_COPYRIGHT = 184
642
+CHAR_CURRENCY = 207
643
+CHAR_DIAMOND = 4
644
+CHAR_DIVISION = 246
645
+CHAR_EXCLAM_DOUBLE = 19
646
+CHAR_FEMALE = 12
647
+CHAR_FUNCTION = 159
648
+CHAR_GRADE = 248
649
+CHAR_HALF = 171
650
+CHAR_HEART = 3
651
+CHAR_LIGHT = 15
652
+CHAR_MALE = 11
653
+CHAR_MULTIPLICATION = 158
654
+CHAR_NOTE = 13
655
+CHAR_NOTE_DOUBLE = 14
656
+CHAR_ONE_QUARTER = 172
657
+CHAR_PILCROW = 20
658
+CHAR_POUND = 156
659
+CHAR_POW1 = 251
660
+CHAR_POW2 = 253
661
+CHAR_POW3 = 252
662
+CHAR_RESERVED = 169
663
+CHAR_SECTION = 21
664
+CHAR_SMILIE = 1
665
+CHAR_SMILIE_INV = 2
666
+CHAR_SPADE = 6
667
+CHAR_THREE_QUARTERS = 243
668
+CHAR_UMLAUT = 249
669
+CHAR_YEN = 190
670
+# font flags
671
+FONT_LAYOUT_ASCII_INCOL = 1
672
+FONT_LAYOUT_ASCII_INROW = 2
673
+FONT_TYPE_GREYSCALE = 4
674
+FONT_TYPE_GRAYSCALE = 4
675
+FONT_LAYOUT_TCOD = 8
676
+# color control codes
677
+COLCTRL_1=1
678
+COLCTRL_2=2
679
+COLCTRL_3=3
680
+COLCTRL_4=4
681
+COLCTRL_5=5
682
+COLCTRL_NUMBER=5
683
+COLCTRL_FORE_RGB=6
684
+COLCTRL_BACK_RGB=7
685
+COLCTRL_STOP=8
686
+# renderers
687
+RENDERER_GLSL=0
688
+RENDERER_OPENGL=1
689
+RENDERER_SDL=2
690
+NB_RENDERERS=3
691
+# alignment
692
+LEFT=0
693
+RIGHT=1
694
+CENTER=2
695
+# initializing the console
696
+def console_init_root(w, h, title, fullscreen=False, renderer=RENDERER_SDL):
697
+    _lib.TCOD_console_init_root(w, h, c_char_p(title), fullscreen, renderer)
698
+
699
+def console_get_width(con):
700
+    return _lib.TCOD_console_get_width(con)
701
+
702
+def console_get_height(con):
703
+    return _lib.TCOD_console_get_height(con)
704
+
705
+def console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL, nb_char_horiz=0, nb_char_vertic=0):
706
+    _lib.TCOD_console_set_custom_font(c_char_p(fontFile), flags, nb_char_horiz, nb_char_vertic)
707
+
708
+def console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY):
709
+    if type(asciiCode) == str or type(asciiCode) == bytes:
710
+        _lib.TCOD_console_map_ascii_code_to_font(ord(asciiCode), fontCharX,
711
+                                                 fontCharY)
712
+    else:
713
+        _lib.TCOD_console_map_ascii_code_to_font(asciiCode, fontCharX,
714
+                                                 fontCharY)
715
+
716
+def console_map_ascii_codes_to_font(firstAsciiCode, nbCodes, fontCharX,
717
+                                    fontCharY):
718
+    if type(firstAsciiCode) == str or type(firstAsciiCode) == bytes:
719
+        _lib.TCOD_console_map_ascii_codes_to_font(ord(firstAsciiCode), nbCodes,
720
+                                                  fontCharX, fontCharY)
721
+    else:
722
+        _lib.TCOD_console_map_ascii_codes_to_font(firstAsciiCode, nbCodes,
723
+                                                  fontCharX, fontCharY)
724
+
725
+def console_map_string_to_font(s, fontCharX, fontCharY):
726
+    if type(s) == bytes:
727
+        _lib.TCOD_console_map_string_to_font(s, fontCharX, fontCharY)
728
+    else:
729
+        _lib.TCOD_console_map_string_to_font_utf(s, fontCharX, fontCharY)
730
+
731
+def console_is_fullscreen():
732
+    return _lib.TCOD_console_is_fullscreen()
733
+
734
+def console_set_fullscreen(fullscreen):
735
+    _lib.TCOD_console_set_fullscreen(c_int(fullscreen))
736
+
737
+def console_is_window_closed():
738
+    return _lib.TCOD_console_is_window_closed()
739
+
740
+def console_has_mouse_focus():
741
+    return _lib.TCOD_console_has_mouse_focus()
742
+
743
+def console_is_active():
744
+    return _lib.TCOD_console_is_active()
745
+
746
+def console_set_window_title(title):
747
+    _lib.TCOD_console_set_window_title(c_char_p(title))
748
+
749
+def console_credits():
750
+    _lib.TCOD_console_credits()
751
+
752
+def console_credits_reset():
753
+    _lib.TCOD_console_credits_reset()
754
+
755
+def console_credits_render(x, y, alpha):
756
+    return _lib.TCOD_console_credits_render(x, y, c_int(alpha))
757
+
758
+def console_flush():
759
+    _lib.TCOD_console_flush()
760
+
761
+# drawing on a console
762
+def console_set_default_background(con, col):
763
+    _lib.TCOD_console_set_default_background(con, col)
764
+
765
+def console_set_default_foreground(con, col):
766
+    _lib.TCOD_console_set_default_foreground(con, col)
767
+
768
+def console_clear(con):
769
+    return _lib.TCOD_console_clear(con)
770
+
771
+def console_put_char(con, x, y, c, flag=BKGND_DEFAULT):
772
+    if type(c) == str or type(c) == bytes:
773
+        _lib.TCOD_console_put_char(con, x, y, ord(c), flag)
774
+    else:
775
+        _lib.TCOD_console_put_char(con, x, y, c, flag)
776
+
777
+def console_put_char_ex(con, x, y, c, fore, back):
778
+    if type(c) == str or type(c) == bytes:
779
+        _lib.TCOD_console_put_char_ex(con, x, y, ord(c), fore, back)
780
+    else:
781
+        _lib.TCOD_console_put_char_ex(con, x, y, c, fore, back)
782
+
783
+def console_set_char_background(con, x, y, col, flag=BKGND_SET):
784
+    _lib.TCOD_console_set_char_background(con, x, y, col, flag)
785
+
786
+def console_set_char_foreground(con, x, y, col):
787
+    _lib.TCOD_console_set_char_foreground(con, x, y, col)
788
+
789
+def console_set_char(con, x, y, c):
790
+    if type(c) == str or type(c) == bytes:
791
+        _lib.TCOD_console_set_char(con, x, y, ord(c))
792
+    else:
793
+        _lib.TCOD_console_set_char(con, x, y, c)
794
+
795
+def console_set_background_flag(con, flag):
796
+    _lib.TCOD_console_set_background_flag(con, c_int(flag))
797
+
798
+def console_get_background_flag(con):
799
+    return _lib.TCOD_console_get_background_flag(con)
800
+
801
+def console_set_alignment(con, alignment):
802
+    _lib.TCOD_console_set_alignment(con, c_int(alignment))
803
+
804
+def console_get_alignment(con):
805
+    return _lib.TCOD_console_get_alignment(con)
806
+
807
+def console_print(con, x, y, fmt):
808
+    if type(fmt) == bytes:
809
+        _lib.TCOD_console_print(c_void_p(con), x, y, c_char_p(fmt))
810
+    else:
811
+        _lib.TCOD_console_print_utf(c_void_p(con), x, y, fmt)
812
+
813
+def console_print_ex(con, x, y, flag, alignment, fmt):
814
+    if type(fmt) == bytes:
815
+        _lib.TCOD_console_print_ex(c_void_p(con), x, y, flag, alignment, c_char_p(fmt))
816
+    else:
817
+        _lib.TCOD_console_print_ex_utf(c_void_p(con), x, y, flag, alignment, fmt)
818
+
819
+def console_print_rect(con, x, y, w, h, fmt):
820
+    if type(fmt) == bytes:
821
+        return _lib.TCOD_console_print_rect(c_void_p(con), x, y, w, h, c_char_p(fmt))
822
+    else:
823
+        return _lib.TCOD_console_print_rect_utf(c_void_p(con), x, y, w, h, fmt)
824
+
825
+def console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt):
826
+    if type(fmt) == bytes:
827
+        return _lib.TCOD_console_print_rect_ex(c_void_p(con), x, y, w, h, flag, alignment, c_char_p(fmt))
828
+    else:
829
+        return _lib.TCOD_console_print_rect_ex_utf(c_void_p(con), x, y, w, h, flag, alignment, fmt)
830
+
831
+def console_get_height_rect(con, x, y, w, h, fmt):
832
+    if type(fmt) == bytes:
833
+        return _lib.TCOD_console_get_height_rect(c_void_p(con), x, y, w, h, c_char_p(fmt))
834
+    else:
835
+        return _lib.TCOD_console_get_height_rect_utf(c_void_p(con), x, y, w, h, fmt)
836
+
837
+def console_rect(con, x, y, w, h, clr, flag=BKGND_DEFAULT):
838
+    _lib.TCOD_console_rect(con, x, y, w, h, c_int(clr), flag)
839
+
840
+def console_hline(con, x, y, l, flag=BKGND_DEFAULT):
841
+    _lib.TCOD_console_hline( con, x, y, l, flag)
842
+
843
+def console_vline(con, x, y, l, flag=BKGND_DEFAULT):
844
+    _lib.TCOD_console_vline( con, x, y, l, flag)
845
+
846
+def console_print_frame(con, x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=0):
847
+    _lib.TCOD_console_print_frame(c_void_p(con), x, y, w, h, c_int(clear), flag, c_char_p(fmt))
848
+
849
+def console_set_color_control(con,fore,back) :
850
+    _lib.TCOD_console_set_color_control(con,fore,back)
851
+
852
+def console_get_default_background(con):
853
+    return _lib.TCOD_console_get_default_background(con)
854
+
855
+def console_get_default_foreground(con):
856
+    return _lib.TCOD_console_get_default_foreground(con)
857
+
858
+def console_get_char_background(con, x, y):
859
+    return _lib.TCOD_console_get_char_background(con, x, y)
860
+
861
+def console_get_char_foreground(con, x, y):
862
+    return _lib.TCOD_console_get_char_foreground(con, x, y)
863
+
864
+def console_get_char(con, x, y):
865
+    return _lib.TCOD_console_get_char(con, x, y)
866
+
867
+def console_set_fade(fade, fadingColor):
868
+    _lib.TCOD_console_set_fade(fade, fadingColor)
869
+    ##_lib.TCOD_console_set_fade_wrapper(fade, fadingColor)
870
+
871
+def console_get_fade():
872
+    return _lib.TCOD_console_get_fade().value
873
+
874
+def console_get_fading_color():
875
+    return _lib.TCOD_console_get_fading_color()
876
+
877
+# handling keyboard input
878
+def console_wait_for_keypress(flush):
879
+    k=Key()
880
+    _lib.TCOD_console_wait_for_keypress_wrapper(byref(k),c_bool(flush))
881
+    return k
882
+
883
+def console_check_for_keypress(flags=KEY_RELEASED):
884
+    k=Key()
885
+    _lib.TCOD_console_check_for_keypress_wrapper(byref(k),c_int(flags))
886
+    return k
887
+
888
+def console_is_key_pressed(key):
889
+    return _lib.TCOD_console_is_key_pressed(key)
890
+
891
+def console_set_keyboard_repeat(initial_delay, interval):
892
+    _lib.TCOD_console_set_keyboard_repeat(initial_delay, interval)
893
+
894
+def console_disable_keyboard_repeat():
895
+    _lib.TCOD_console_disable_keyboard_repeat()
896
+
897
+# using offscreen consoles
898
+def console_new(w, h):
899
+    return _lib.TCOD_console_new(w, h)
900
+def console_from_file(filename):
901
+    return _lib.TCOD_console_from_file(filename)
902
+def console_get_width(con):
903
+    return _lib.TCOD_console_get_width(con)
904
+
905
+def console_get_height(con):
906
+    return _lib.TCOD_console_get_height(con)
907
+
908
+def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
909
+    _lib.TCOD_console_blit(src, x, y, w, h, dst, xdst, ydst, c_float(ffade), c_float(bfade))
910
+
911
+def console_set_key_color(con, col):
912
+    _lib.TCOD_console_set_key_color(con, col)
913
+
914
+def console_delete(con):
915
+    _lib.TCOD_console_delete(con)
916
+
917
+# fast color filling
918
+def console_fill_foreground(con,r,g,b) :
919
+    if len(r) != len(g) or len(r) != len(b):
920
+        raise TypeError('R, G and B must all have the same size.')
921
+
922
+    if (numpy_available and isinstance(r, numpy.ndarray) and
923
+        isinstance(g, numpy.ndarray) and isinstance(b, numpy.ndarray)):
924
+        #numpy arrays, use numpy's ctypes functions
925
+        r = numpy.ascontiguousarray(r, dtype=numpy.int32)
926
+        g = numpy.ascontiguousarray(g, dtype=numpy.int32)
927
+        b = numpy.ascontiguousarray(b, dtype=numpy.int32)
928
+        cr = r.ctypes.data_as(POINTER(c_int))
929
+        cg = g.ctypes.data_as(POINTER(c_int))
930
+        cb = b.ctypes.data_as(POINTER(c_int))
931
+    else:
932
+        # otherwise convert using ctypes arrays
933
+        cr = (c_int * len(r))(*r)
934
+        cg = (c_int * len(g))(*g)
935
+        cb = (c_int * len(b))(*b)
936
+
937
+    _lib.TCOD_console_fill_foreground(con, cr, cg, cb)
938
+
939
+def console_fill_background(con,r,g,b) :
940
+    if len(r) != len(g) or len(r) != len(b):
941
+        raise TypeError('R, G and B must all have the same size.')
942
+
943
+    if (numpy_available and isinstance(r, numpy.ndarray) and
944
+        isinstance(g, numpy.ndarray) and isinstance(b, numpy.ndarray)):
945
+        #numpy arrays, use numpy's ctypes functions
946
+        r = numpy.ascontiguousarray(r, dtype=numpy.int32)
947
+        g = numpy.ascontiguousarray(g, dtype=numpy.int32)
948
+        b = numpy.ascontiguousarray(b, dtype=numpy.int32)
949
+        cr = r.ctypes.data_as(POINTER(c_int))
950
+        cg = g.ctypes.data_as(POINTER(c_int))
951
+        cb = b.ctypes.data_as(POINTER(c_int))
952
+    else:
953
+        # otherwise convert using ctypes arrays
954
+        cr = (c_int * len(r))(*r)
955
+        cg = (c_int * len(g))(*g)
956
+        cb = (c_int * len(b))(*b)
957
+
958
+    _lib.TCOD_console_fill_background(con, cr, cg, cb)
959
+
960
+def console_fill_char(con,arr) :
961
+    if (numpy_available and isinstance(arr, numpy.ndarray) ):
962
+        #numpy arrays, use numpy's ctypes functions
963
+        arr = numpy.ascontiguousarray(arr, dtype=numpy.int32)
964
+        carr = arr.ctypes.data_as(POINTER(c_int))
965
+    else:
966
+        #otherwise convert using the struct module
967
+        carr = struct.pack('%di' % len(arr), *arr)
968
+
969
+    _lib.TCOD_console_fill_char(con, carr)
970
+        
971
+def console_load_asc(con, filename) :
972
+    _lib.TCOD_console_load_asc(con,filename)
973
+def console_save_asc(con, filename) :
974
+    _lib.TCOD_console_save_asc(con,filename)
975
+def console_load_apf(con, filename) :
976
+    _lib.TCOD_console_load_apf(con,filename)
977
+def console_save_apf(con, filename) :
978
+    _lib.TCOD_console_save_apf(con,filename)
979
+
980
+############################
981
+# sys module
982
+############################
983
+_lib.TCOD_sys_get_last_frame_length.restype = c_float
984
+_lib.TCOD_sys_elapsed_seconds.restype = c_float
985
+
986
+# high precision time functions
987
+def sys_set_fps(fps):
988
+    _lib.TCOD_sys_set_fps(fps)
989
+
990
+def sys_get_fps():
991
+    return _lib.TCOD_sys_get_fps()
992
+
993
+def sys_get_last_frame_length():
994
+    return _lib.TCOD_sys_get_last_frame_length()
995
+
996
+def sys_sleep_milli(val):
997
+    _lib.TCOD_sys_sleep_milli(c_uint(val))
998
+
999
+def sys_elapsed_milli():
1000
+    return _lib.TCOD_sys_elapsed_milli()
1001
+
1002
+def sys_elapsed_seconds():
1003
+    return _lib.TCOD_sys_elapsed_seconds()
1004
+
1005
+def sys_set_renderer(renderer):
1006
+    _lib.TCOD_sys_set_renderer(renderer)
1007
+
1008
+def sys_get_renderer():
1009
+    return _lib.TCOD_sys_get_renderer()
1010
+
1011
+# easy screenshots
1012
+def sys_save_screenshot(name=0):
1013
+    _lib.TCOD_sys_save_screenshot(c_char_p(name))
1014
+
1015
+# custom fullscreen resolution
1016
+def sys_force_fullscreen_resolution(width, height):
1017
+    _lib.TCOD_sys_force_fullscreen_resolution(width, height)
1018
+
1019
+def sys_get_current_resolution():
1020
+    w = c_int()
1021
+    h = c_int()
1022
+    _lib.TCOD_sys_get_current_resolution(byref(w), byref(h))
1023
+    return w.value, h.value
1024
+
1025
+def sys_get_char_size():
1026
+    w = c_int()
1027
+    h = c_int()
1028
+    _lib.TCOD_sys_get_char_size(byref(w), byref(h))
1029
+    return w.value, h.value
1030
+
1031
+# update font bitmap
1032
+def sys_update_char(asciiCode, fontx, fonty, img, x, y) :
1033
+    _lib.TCOD_sys_update_char(c_int(asciiCode),c_int(fontx),c_int(fonty),img,c_int(x),c_int(y))
1034
+
1035
+# custom SDL post renderer
1036
+SDL_RENDERER_FUNC = CFUNCTYPE(None, c_void_p)
1037
+def sys_register_SDL_renderer(callback):
1038
+    global sdl_renderer_func
1039
+    sdl_renderer_func = SDL_RENDERER_FUNC(callback)
1040
+    _lib.TCOD_sys_register_SDL_renderer(sdl_renderer_func)
1041
+
1042
+# events
1043
+EVENT_NONE=0
1044
+EVENT_KEY_PRESS=1
1045
+EVENT_KEY_RELEASE=2
1046
+EVENT_KEY=EVENT_KEY_PRESS|EVENT_KEY_RELEASE
1047
+EVENT_MOUSE_MOVE=4
1048
+EVENT_MOUSE_PRESS=8
1049
+EVENT_MOUSE_RELEASE=16
1050
+EVENT_MOUSE=EVENT_MOUSE_MOVE|EVENT_MOUSE_PRESS|EVENT_MOUSE_RELEASE
1051
+EVENT_ANY=EVENT_KEY|EVENT_MOUSE
1052
+def sys_check_for_event(mask,k,m) :
1053
+    return _lib.TCOD_sys_check_for_event(c_int(mask),byref(k),byref(m))
1054
+
1055
+def sys_wait_for_event(mask,k,m,flush) :
1056
+    return _lib.TCOD_sys_wait_for_event(c_int(mask),byref(k),byref(m),c_bool(flush))
1057
+
1058
+############################
1059
+# line module
1060
+############################
1061
+_lib.TCOD_line_step.restype = c_bool
1062
+_lib.TCOD_line.restype=c_bool
1063
+_lib.TCOD_line_step_mt.restype = c_bool
1064
+
1065
+def line_init(xo, yo, xd, yd):
1066
+    _lib.TCOD_line_init(xo, yo, xd, yd)
1067
+
1068
+def line_step():
1069
+    x = c_int()
1070
+    y = c_int()
1071
+    ret = _lib.TCOD_line_step(byref(x), byref(y))
1072
+    if not ret:
1073
+        return x.value, y.value
1074
+    return None,None
1075
+
1076
+def line(xo,yo,xd,yd,py_callback) :
1077
+    LINE_CBK_FUNC=CFUNCTYPE(c_bool,c_int,c_int)
1078
+    c_callback=LINE_CBK_FUNC(py_callback)
1079
+    return _lib.TCOD_line(xo,yo,xd,yd,c_callback)
1080
+
1081
+def line_iter(xo, yo, xd, yd):
1082
+    data = (c_int * 9)()        # struct TCOD_bresenham_data_t
1083
+    _lib.TCOD_line_init_mt(xo, yo, xd, yd, data)
1084
+    x = c_int(xo)
1085
+    y = c_int(yo)
1086
+    done = False
1087
+    while not done:
1088
+        yield x.value, y.value
1089
+        done = _lib.TCOD_line_step_mt(byref(x), byref(y), data)
1090
+
1091
+############################
1092
+# image module
1093
+############################
1094
+_lib.TCOD_image_is_pixel_transparent.restype = c_bool
1095
+_lib.TCOD_image_get_pixel.restype = Color
1096
+_lib.TCOD_image_get_mipmap_pixel.restype = Color
1097
+
1098
+def image_new(width, height):
1099
+    return _lib.TCOD_image_new(width, height)
1100
+
1101
+def image_clear(image,col) :
1102
+    _lib.TCOD_image_clear(image,col)
1103
+
1104
+def image_invert(image) :
1105
+    _lib.TCOD_image_invert(image)
1106
+
1107
+def image_hflip(image) :
1108
+    _lib.TCOD_image_hflip(image)
1109
+
1110
+def image_rotate90(image, num=1) :
1111
+    _lib.TCOD_image_rotate90(image,num)
1112
+
1113
+def image_vflip(image) :
1114
+    _lib.TCOD_image_vflip(image)
1115
+
1116
+def image_scale(image, neww, newh) :
1117
+    _lib.TCOD_image_scale(image,c_int(neww),c_int(newh))
1118
+
1119
+def image_set_key_color(image,col) :
1120
+    _lib.TCOD_image_set_key_color(image,col)
1121
+
1122
+def image_get_alpha(image,x,y) :
1123
+    return _lib.TCOD_image_get_alpha(image,c_int(x),c_int(y))
1124
+
1125
+def image_is_pixel_transparent(image,x,y) :
1126
+    return _lib.TCOD_image_is_pixel_transparent(image,c_int(x),c_int(y))
1127
+
1128
+def image_load(filename):
1129
+    return _lib.TCOD_image_load(c_char_p(filename))
1130
+
1131
+def image_from_console(console):
1132
+    return _lib.TCOD_image_from_console(console)
1133
+
1134
+def image_refresh_console(image, console):
1135
+    _lib.TCOD_image_refresh_console(image, console)
1136
+
1137
+def image_get_size(image):
1138
+    w=c_int()
1139
+    h=c_int()
1140
+    _lib.TCOD_image_get_size(image, byref(w), byref(h))
1141
+    return w.value, h.value
1142
+
1143
+def image_get_pixel(image, x, y):
1144
+    return _lib.TCOD_image_get_pixel(image, x, y)
1145
+
1146
+def image_get_mipmap_pixel(image, x0, y0, x1, y1):
1147
+    return _lib.TCOD_image_get_mipmap_pixel(image, c_float(x0), c_float(y0),
1148
+                                            c_float(x1), c_float(y1))
1149
+def image_put_pixel(image, x, y, col):
1150
+    _lib.TCOD_image_put_pixel(image, x, y, col)
1151
+    ##_lib.TCOD_image_put_pixel_wrapper(image, x, y, col)
1152
+
1153
+def image_blit(image, console, x, y, bkgnd_flag, scalex, scaley, angle):
1154
+    _lib.TCOD_image_blit(image, console, c_float(x), c_float(y), bkgnd_flag,
1155
+                         c_float(scalex), c_float(scaley), c_float(angle))
1156
+
1157
+def image_blit_rect(image, console, x, y, w, h, bkgnd_flag):
1158
+    _lib.TCOD_image_blit_rect(image, console, x, y, w, h, bkgnd_flag)
1159
+
1160
+def image_blit_2x(image, console, dx, dy, sx=0, sy=0, w=-1, h=-1):
1161
+    _lib.TCOD_image_blit_2x(image, console, dx,dy,sx,sy,w,h)
1162
+
1163
+def image_save(image, filename):
1164
+    _lib.TCOD_image_save(image, c_char_p(filename))
1165
+
1166
+def image_delete(image):
1167
+    _lib.TCOD_image_delete(image)
1168
+
1169
+############################
1170
+# mouse module
1171
+############################
1172
+class Mouse(Structure):
1173
+    _fields_=[('x', c_int),
1174
+              ('y', c_int),
1175
+              ('dx', c_int),
1176
+              ('dy', c_int),
1177
+              ('cx', c_int),
1178
+              ('cy', c_int),
1179
+              ('dcx', c_int),
1180
+              ('dcy', c_int),
1181
+              ('lbutton', c_bool),
1182
+              ('rbutton', c_bool),
1183
+              ('mbutton', c_bool),
1184
+              ('lbutton_pressed', c_bool),
1185
+              ('rbutton_pressed', c_bool),
1186
+              ('mbutton_pressed', c_bool),
1187
+              ('wheel_up', c_bool),
1188
+              ('wheel_down', c_bool),
1189
+              ]
1190
+
1191
+_lib.TCOD_mouse_is_cursor_visible.restype = c_bool
1192
+
1193
+def mouse_show_cursor(visible):
1194
+    _lib.TCOD_mouse_show_cursor(c_int(visible))
1195
+
1196
+def mouse_is_cursor_visible():
1197
+    return _lib.TCOD_mouse_is_cursor_visible()
1198
+
1199
+def mouse_move(x, y):
1200
+    _lib.TCOD_mouse_move(x, y)
1201
+
1202
+def mouse_get_status():
1203
+    mouse=Mouse()
1204
+    _lib.TCOD_mouse_get_status_wrapper(byref(mouse))
1205
+    return mouse
1206
+
1207
+############################
1208
+# parser module
1209
+############################
1210
+_lib.TCOD_struct_get_name.restype = c_char_p
1211
+_lib.TCOD_struct_is_mandatory.restype = c_bool
1212
+_lib.TCOD_parser_has_property.restype = c_bool
1213
+_lib.TCOD_parser_get_bool_property.restype = c_bool
1214
+_lib.TCOD_parser_get_float_property.restype = c_float
1215
+_lib.TCOD_parser_get_string_property.restype = c_char_p
1216
+_lib.TCOD_parser_get_color_property.restype = Color
1217
+
1218
+class Dice(Structure):
1219
+    _fields_=[('nb_dices', c_int),
1220
+              ('nb_faces', c_int),
1221
+              ('multiplier', c_float),
1222
+              ('addsub', c_float),
1223
+              ]
1224
+
1225
+    def __repr__(self):
1226
+        return "Dice(%d, %d, %s, %s)" % (self.nb_dices, self.nb_faces,
1227
+                                      self.multiplier, self.addsub)
1228
+
1229
+class _CValue(Union):
1230
+    _fields_=[('c',c_uint8),
1231
+              ('i',c_int),
1232
+              ('f',c_float),
1233
+              ('s',c_char_p),
1234
+              # JBR03192012 See http://bugs.python.org/issue14354 for why these are not defined as their actual types
1235
+              ('col',c_uint8 * 3),
1236
+              ('dice',c_int * 4),
1237
+              ('custom',c_void_p),
1238
+              ]
1239
+
1240
+_CFUNC_NEW_STRUCT = CFUNCTYPE(c_uint, c_void_p, c_char_p)
1241
+_CFUNC_NEW_FLAG = CFUNCTYPE(c_uint, c_char_p)
1242
+_CFUNC_NEW_PROPERTY = CFUNCTYPE(c_uint, c_char_p, c_int, _CValue)
1243
+
1244
+class _CParserListener(Structure):
1245
+    _fields_=[('new_struct', _CFUNC_NEW_STRUCT),
1246
+              ('new_flag',_CFUNC_NEW_FLAG),
1247
+              ('new_property',_CFUNC_NEW_PROPERTY),
1248
+              ('end_struct',_CFUNC_NEW_STRUCT),
1249
+              ('error',_CFUNC_NEW_FLAG),
1250
+              ]
1251
+
1252
+# property types
1253
+TYPE_NONE = 0
1254
+TYPE_BOOL = 1
1255
+TYPE_CHAR = 2
1256
+TYPE_INT = 3
1257
+TYPE_FLOAT = 4
1258
+TYPE_STRING = 5
1259
+TYPE_COLOR = 6
1260
+TYPE_DICE = 7
1261
+TYPE_VALUELIST00 = 8
1262
+TYPE_VALUELIST01 = 9
1263
+TYPE_VALUELIST02 = 10
1264
+TYPE_VALUELIST03 = 11
1265
+TYPE_VALUELIST04 = 12
1266
+TYPE_VALUELIST05 = 13
1267
+TYPE_VALUELIST06 = 14
1268
+TYPE_VALUELIST07 = 15
1269
+TYPE_VALUELIST08 = 16
1270
+TYPE_VALUELIST09 = 17
1271
+TYPE_VALUELIST10 = 18
1272
+TYPE_VALUELIST11 = 19
1273
+TYPE_VALUELIST12 = 20
1274
+TYPE_VALUELIST13 = 21
1275
+TYPE_VALUELIST14 = 22
1276
+TYPE_VALUELIST15 = 23
1277
+TYPE_LIST = 1024
1278
+
1279
+def _convert_TCODList(clist, typ):
1280
+    res = list()
1281
+    for i in range(_lib.TCOD_list_size(clist)):
1282
+        elt = _lib.TCOD_list_get(clist, i)
1283
+        elt = cast(elt, c_void_p)
1284
+        if typ == TYPE_BOOL:
1285
+            elt = c_bool.from_buffer(elt).value
1286
+        elif typ == TYPE_CHAR:
1287
+            elt = c_char.from_buffer(elt).value
1288
+        elif typ == TYPE_INT:
1289
+            elt = c_int.from_buffer(elt).value
1290
+        elif typ == TYPE_FLOAT:
1291
+            elt = c_float.from_buffer(elt).value
1292
+        elif typ == TYPE_STRING or TYPE_VALUELIST15 >= typ >= TYPE_VALUELIST00:
1293
+            elt = cast(elt, c_char_p).value
1294
+        elif typ == TYPE_COLOR:
1295
+            elt = Color.from_buffer_copy(elt)
1296
+        elif typ == TYPE_DICE:
1297
+            # doesn't work
1298
+            elt = Dice.from_buffer_copy(elt)
1299
+        res.append(elt)
1300
+    return res
1301
+
1302
+def parser_new():
1303
+    return _lib.TCOD_parser_new()
1304
+
1305
+def parser_new_struct(parser, name):
1306
+    return _lib.TCOD_parser_new_struct(parser, name)
1307
+
1308
+def struct_add_flag(struct, name):
1309
+    _lib.TCOD_struct_add_flag(struct, name)
1310
+
1311
+def struct_add_property(struct, name, typ, mandatory):
1312
+    _lib.TCOD_struct_add_property(struct, name, typ, c_bool(mandatory))
1313
+
1314
+def struct_add_value_list(struct, name, value_list, mandatory):
1315
+    CARRAY = c_char_p * (len(value_list) + 1)
1316
+    cvalue_list = CARRAY()
1317
+    for i in range(len(value_list)):
1318
+        cvalue_list[i] = cast(value_list[i], c_char_p)
1319
+    cvalue_list[len(value_list)] = 0
1320
+    _lib.TCOD_struct_add_value_list(struct, name, cvalue_list, c_bool(mandatory))
1321
+
1322
+def struct_add_list_property(struct, name, typ, mandatory):
1323
+    _lib.TCOD_struct_add_list_property(struct, name, typ, c_bool(mandatory))
1324
+
1325
+def struct_add_structure(struct, sub_struct):
1326
+    _lib.TCOD_struct_add_structure(struct, sub_struct)
1327
+
1328
+def struct_get_name(struct):
1329
+    return _lib.TCOD_struct_get_name(struct)
1330
+
1331
+def struct_is_mandatory(struct, name):
1332
+    return _lib.TCOD_struct_is_mandatory(struct, name)
1333
+
1334
+def struct_get_type(struct, name):
1335
+    return _lib.TCOD_struct_get_type(struct, name)
1336
+
1337
+def parser_run(parser, filename, listener=0):
1338
+    if listener != 0:
1339
+        clistener=_CParserListener()
1340
+        def value_converter(name, typ, value):
1341
+            if typ == TYPE_BOOL:
1342
+                return listener.new_property(name, typ, value.c == 1)
1343
+            elif typ == TYPE_CHAR:
1344
+                return listener.new_property(name, typ, '%c' % (value.c & 0xFF))
1345
+            elif typ == TYPE_INT:
1346
+                return listener.new_property(name, typ, value.i)
1347
+            elif typ == TYPE_FLOAT:
1348
+                return listener.new_property(name, typ, value.f)
1349
+            elif typ == TYPE_STRING or \
1350
+                 TYPE_VALUELIST15 >= typ >= TYPE_VALUELIST00:
1351
+                 return listener.new_property(name, typ, value.s)
1352
+            elif typ == TYPE_COLOR:
1353
+                col = cast(value.col, POINTER(Color)).contents
1354
+                return listener.new_property(name, typ, col)
1355
+            elif typ == TYPE_DICE:
1356
+                dice = cast(value.dice, POINTER(Dice)).contents
1357
+                return listener.new_property(name, typ, dice)
1358
+            elif typ & TYPE_LIST:
1359
+                return listener.new_property(name, typ,
1360
+                                        _convert_TCODList(value.custom, typ & 0xFF))
1361
+            return True
1362
+        clistener.new_struct = _CFUNC_NEW_STRUCT(listener.new_struct)
1363
+        clistener.new_flag = _CFUNC_NEW_FLAG(listener.new_flag)
1364
+        clistener.new_property = _CFUNC_NEW_PROPERTY(value_converter)
1365
+        clistener.end_struct = _CFUNC_NEW_STRUCT(listener.end_struct)
1366
+        clistener.error = _CFUNC_NEW_FLAG(listener.error)
1367
+        _lib.TCOD_parser_run(parser, c_char_p(filename), byref(clistener))
1368
+    else:
1369
+        _lib.TCOD_parser_run(parser, c_char_p(filename), 0)
1370
+
1371
+def parser_delete(parser):
1372
+    _lib.TCOD_parser_delete(parser)
1373
+
1374
+def parser_has_property(parser, name):
1375
+    return _lib.TCOD_parser_has_property(parser, c_char_p(name))
1376
+
1377
+def parser_get_bool_property(parser, name):
1378
+    return _lib.TCOD_parser_get_bool_property(parser, c_char_p(name))
1379
+
1380
+def parser_get_int_property(parser, name):
1381
+    return _lib.TCOD_parser_get_int_property(parser, c_char_p(name))
1382
+
1383
+def parser_get_char_property(parser, name):
1384
+    return '%c' % _lib.TCOD_parser_get_char_property(parser, c_char_p(name))
1385
+
1386
+def parser_get_float_property(parser, name):
1387
+    return _lib.TCOD_parser_get_float_property(parser, c_char_p(name))
1388
+
1389
+def parser_get_string_property(parser, name):
1390
+    return _lib.TCOD_parser_get_string_property(parser, c_char_p(name))
1391
+
1392
+def parser_get_color_property(parser, name):
1393
+    return _lib.TCOD_parser_get_color_property(parser, c_char_p(name))
1394
+
1395
+def parser_get_dice_property(parser, name):
1396
+    d = Dice()
1397
+    _lib.TCOD_parser_get_dice_property_py(c_void_p(parser), c_char_p(name), byref(d))
1398
+    return d
1399
+
1400
+def parser_get_list_property(parser, name, typ):
1401
+    clist = _lib.TCOD_parser_get_list_property(parser, c_char_p(name), c_int(typ))
1402
+    return _convert_TCODList(clist, typ)
1403
+
1404
+############################
1405
+# random module
1406
+############################
1407
+_lib.TCOD_random_get_float.restype = c_float
1408
+_lib.TCOD_random_get_double.restype = c_double
1409
+
1410
+RNG_MT = 0
1411
+RNG_CMWC = 1
1412
+
1413
+DISTRIBUTION_LINEAR = 0
1414
+DISTRIBUTION_GAUSSIAN = 1
1415
+DISTRIBUTION_GAUSSIAN_RANGE = 2
1416
+DISTRIBUTION_GAUSSIAN_INVERSE = 3
1417
+DISTRIBUTION_GAUSSIAN_RANGE_INVERSE = 4
1418
+
1419
+def random_get_instance():
1420
+    return _lib.TCOD_random_get_instance()
1421
+
1422
+def random_new(algo=RNG_CMWC):
1423
+    return _lib.TCOD_random_new(algo)
1424
+
1425
+def random_new_from_seed(seed, algo=RNG_CMWC):
1426
+    return _lib.TCOD_random_new_from_seed(algo,c_uint(seed))
1427
+
1428
+def random_set_distribution(rnd, dist) :
1429
+	_lib.TCOD_random_set_distribution(rnd, dist)
1430
+
1431
+def random_get_int(rnd, mi, ma):
1432
+    return _lib.TCOD_random_get_int(rnd, mi, ma)
1433
+
1434
+def random_get_float(rnd, mi, ma):
1435
+    return _lib.TCOD_random_get_float(rnd, c_float(mi), c_float(ma))
1436
+
1437
+def random_get_double(rnd, mi, ma):
1438
+    return _lib.TCOD_random_get_double(rnd, c_double(mi), c_double(ma))
1439
+
1440
+def random_get_int_mean(rnd, mi, ma, mean):
1441
+    return _lib.TCOD_random_get_int_mean(rnd, mi, ma, mean)
1442
+
1443
+def random_get_float_mean(rnd, mi, ma, mean):
1444
+    return _lib.TCOD_random_get_float_mean(rnd, c_float(mi), c_float(ma), c_float(mean))
1445
+
1446
+def random_get_double_mean(rnd, mi, ma, mean):
1447
+    return _lib.TCOD_random_get_double_mean(rnd, c_double(mi), c_double(ma), c_double(mean))
1448
+
1449
+def random_save(rnd):
1450
+    return _lib.TCOD_random_save(rnd)
1451
+
1452
+def random_restore(rnd, backup):
1453
+    _lib.TCOD_random_restore(rnd, backup)
1454
+
1455
+def random_delete(rnd):
1456
+    _lib.TCOD_random_delete(rnd)
1457
+
1458
+############################
1459
+# noise module
1460
+############################
1461
+_lib.TCOD_noise_get.restype = c_float
1462
+_lib.TCOD_noise_get_ex.restype = c_float
1463
+_lib.TCOD_noise_get_fbm.restype = c_float
1464
+_lib.TCOD_noise_get_fbm_ex.restype = c_float
1465
+_lib.TCOD_noise_get_turbulence.restype = c_float
1466
+_lib.TCOD_noise_get_turbulence_ex.restype = c_float
1467
+
1468
+NOISE_DEFAULT_HURST = 0.5
1469
+NOISE_DEFAULT_LACUNARITY = 2.0
1470
+
1471
+NOISE_DEFAULT = 0
1472
+NOISE_PERLIN = 1
1473
+NOISE_SIMPLEX = 2
1474
+NOISE_WAVELET = 4
1475
+
1476
+_NOISE_PACKER_FUNC = (None,
1477
+                      (c_float * 1),
1478
+                      (c_float * 2),
1479
+                      (c_float * 3),
1480
+                      (c_float * 4),
1481
+                      )
1482
+
1483
+def noise_new(dim, h=NOISE_DEFAULT_HURST, l=NOISE_DEFAULT_LACUNARITY, random=0):
1484
+    return _lib.TCOD_noise_new(dim, c_float(h), c_float(l), random)
1485
+
1486
+def noise_set_type(n, typ) :
1487
+    _lib.TCOD_noise_set_type(n,typ)
1488
+
1489
+def noise_get(n, f, typ=NOISE_DEFAULT):
1490
+    return _lib.TCOD_noise_get_ex(n, _NOISE_PACKER_FUNC[len(f)](*f), typ)
1491
+
1492
+def noise_get_fbm(n, f, oc, typ=NOISE_DEFAULT):
1493
+    return _lib.TCOD_noise_get_fbm_ex(n, _NOISE_PACKER_FUNC[len(f)](*f), c_float(oc), typ)
1494
+
1495
+def noise_get_turbulence(n, f, oc, typ=NOISE_DEFAULT):
1496
+    return _lib.TCOD_noise_get_turbulence_ex(n, _NOISE_PACKER_FUNC[len(f)](*f), c_float(oc), typ)
1497
+
1498
+def noise_delete(n):
1499
+    _lib.TCOD_noise_delete(n)
1500
+
1501
+############################
1502
+# fov module
1503
+############################
1504
+_lib.TCOD_map_is_in_fov.restype = c_bool
1505
+_lib.TCOD_map_is_transparent.restype = c_bool
1506
+_lib.TCOD_map_is_walkable.restype = c_bool
1507
+
1508
+FOV_BASIC = 0
1509
+FOV_DIAMOND = 1
1510
+FOV_SHADOW = 2
1511
+FOV_PERMISSIVE_0 = 3
1512
+FOV_PERMISSIVE_1 = 4
1513
+FOV_PERMISSIVE_2 = 5
1514
+FOV_PERMISSIVE_3 = 6
1515
+FOV_PERMISSIVE_4 = 7
1516
+FOV_PERMISSIVE_5 = 8
1517
+FOV_PERMISSIVE_6 = 9
1518
+FOV_PERMISSIVE_7 = 10
1519
+FOV_PERMISSIVE_8 = 11
1520
+FOV_RESTRICTIVE = 12
1521
+NB_FOV_ALGORITHMS = 13
1522
+
1523
+def FOV_PERMISSIVE(p) :
1524
+    return FOV_PERMISSIVE_0+p
1525
+
1526
+def map_new(w, h):
1527
+    return _lib.TCOD_map_new(w, h)
1528
+
1529
+def map_copy(source, dest):
1530
+    return _lib.TCOD_map_copy(source, dest)
1531
+
1532
+def map_set_properties(m, x, y, isTrans, isWalk):
1533
+    _lib.TCOD_map_set_properties(m, x, y, c_int(isTrans), c_int(isWalk))
1534
+
1535
+def map_clear(m,walkable=False,transparent=False):
1536
+    _lib.TCOD_map_clear(m,c_int(walkable),c_int(transparent))
1537
+
1538
+def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
1539
+    _lib.TCOD_map_compute_fov(m, x, y, c_int(radius), c_bool(light_walls), c_int(algo))
1540
+
1541
+def map_is_in_fov(m, x, y):
1542
+    return _lib.TCOD_map_is_in_fov(m, x, y)
1543
+
1544
+def map_is_transparent(m, x, y):
1545
+    return _lib.TCOD_map_is_transparent(m, x, y)
1546
+
1547
+def map_is_walkable(m, x, y):
1548
+    return _lib.TCOD_map_is_walkable(m, x, y)
1549
+
1550
+def map_delete(m):
1551
+    return _lib.TCOD_map_delete(m)
1552
+
1553
+def map_get_width(map):
1554
+    return _lib.TCOD_map_get_width(map)
1555
+
1556
+def map_get_height(map):
1557
+    return _lib.TCOD_map_get_height(map)
1558
+
1559
+############################
1560
+# pathfinding module
1561
+############################
1562
+_lib.TCOD_path_compute.restype = c_bool
1563
+_lib.TCOD_path_is_empty.restype = c_bool
1564
+_lib.TCOD_path_walk.restype = c_bool
1565
+
1566
+PATH_CBK_FUNC = CFUNCTYPE(c_float, c_int, c_int, c_int, c_int, py_object)
1567
+
1568
+def path_new_using_map(m, dcost=1.41):
1569
+    return (_lib.TCOD_path_new_using_map(c_void_p(m), c_float(dcost)), None)
1570
+
1571
+def path_new_using_function(w, h, func, userdata=0, dcost=1.41):
1572
+    cbk_func = PATH_CBK_FUNC(func)
1573
+    return (_lib.TCOD_path_new_using_function(w, h, cbk_func,
1574
+            py_object(userdata), c_float(dcost)), cbk_func)
1575
+
1576
+def path_compute(p, ox, oy, dx, dy):
1577
+    return _lib.TCOD_path_compute(p[0], ox, oy, dx, dy)
1578
+
1579
+def path_get_origin(p):
1580
+    x = c_int()
1581
+    y = c_int()
1582
+    _lib.TCOD_path_get_origin(p[0], byref(x), byref(y))
1583
+    return x.value, y.value
1584
+
1585
+def path_get_destination(p):
1586
+    x = c_int()
1587
+    y = c_int()
1588
+    _lib.TCOD_path_get_destination(p[0], byref(x), byref(y))
1589
+    return x.value, y.value
1590
+
1591
+def path_size(p):
1592
+    return _lib.TCOD_path_size(p[0])
1593
+
1594
+def path_reverse(p):
1595
+    _lib.TCOD_path_reverse(p[0])  
1596
+
1597
+def path_get(p, idx):
1598
+    x = c_int()
1599
+    y = c_int()
1600
+    _lib.TCOD_path_get(p[0], idx, byref(x), byref(y))
1601
+    return x.value, y.value
1602
+
1603
+def path_is_empty(p):
1604
+    return _lib.TCOD_path_is_empty(p[0])
1605
+
1606
+def path_walk(p, recompute):
1607
+    x = c_int()
1608
+    y = c_int()
1609
+    if _lib.TCOD_path_walk(p[0], byref(x), byref(y), c_int(recompute)):
1610
+        return x.value, y.value
1611
+    return None,None
1612
+
1613
+def path_delete(p):
1614
+    _lib.TCOD_path_delete(p[0])
1615
+
1616
+_lib.TCOD_dijkstra_path_set.restype = c_bool
1617
+_lib.TCOD_dijkstra_is_empty.restype = c_bool
1618
+_lib.TCOD_dijkstra_path_walk.restype = c_bool
1619
+_lib.TCOD_dijkstra_get_distance.restype = c_float
1620
+
1621
+def dijkstra_new(m, dcost=1.41):
1622
+    return (_lib.TCOD_dijkstra_new(c_void_p(m), c_float(dcost)), None)
1623
+
1624
+def dijkstra_new_using_function(w, h, func, userdata=0, dcost=1.41):
1625
+    cbk_func = PATH_CBK_FUNC(func)
1626
+    return (_lib.TCOD_path_dijkstra_using_function(w, h, cbk_func,
1627
+            py_object(userdata), c_float(dcost)), cbk_func)
1628
+
1629
+def dijkstra_compute(p, ox, oy):
1630
+    _lib.TCOD_dijkstra_compute(p[0], c_int(ox), c_int(oy))
1631
+
1632
+def dijkstra_path_set(p, x, y):
1633
+    return _lib.TCOD_dijkstra_path_set(p[0], c_int(x), c_int(y))
1634
+
1635
+def dijkstra_get_distance(p, x, y):
1636
+    return _lib.TCOD_dijkstra_get_distance(p[0], c_int(x), c_int(y))
1637
+
1638
+def dijkstra_size(p):
1639
+    return _lib.TCOD_dijkstra_size(p[0])
1640
+
1641
+def dijkstra_reverse(p):
1642
+    _lib.TCOD_dijkstra_reverse(p[0])
1643
+
1644
+def dijkstra_get(p, idx):
1645
+    x = c_int()
1646
+    y = c_int()
1647
+    _lib.TCOD_dijkstra_get(p[0], c_int(idx), byref(x), byref(y))
1648
+    return x.value, y.value
1649
+
1650
+def dijkstra_is_empty(p):
1651
+    return _lib.TCOD_dijkstra_is_empty(p[0])
1652
+
1653
+def dijkstra_path_walk(p):
1654
+    x = c_int()
1655
+    y = c_int()
1656
+    if _lib.TCOD_dijkstra_path_walk(p[0], byref(x), byref(y)):
1657
+        return x.value, y.value
1658
+    return None,None
1659
+
1660
+def dijkstra_delete(p):
1661
+    _lib.TCOD_dijkstra_delete(p[0])
1662
+
1663
+############################
1664
+# bsp module
1665
+############################
1666
+class _CBsp(Structure):
1667
+    _fields_ = [('next', c_void_p),
1668
+                ('father', c_void_p),
1669
+                ('son', c_void_p),
1670
+                ('x', c_int),
1671
+                ('y', c_int),
1672
+                ('w', c_int),
1673
+                ('h', c_int),
1674
+                ('position', c_int),
1675
+                ('level', c_uint8),
1676
+                ('horizontal', c_bool),
1677
+                ]
1678
+
1679
+_lib.TCOD_bsp_new_with_size.restype = POINTER(_CBsp)
1680
+_lib.TCOD_bsp_left.restype = POINTER(_CBsp)
1681
+_lib.TCOD_bsp_right.restype = POINTER(_CBsp)
1682
+_lib.TCOD_bsp_father.restype = POINTER(_CBsp)
1683
+_lib.TCOD_bsp_is_leaf.restype = c_bool
1684
+_lib.TCOD_bsp_contains.restype = c_bool
1685
+_lib.TCOD_bsp_find_node.restype = POINTER(_CBsp)
1686
+
1687
+BSP_CBK_FUNC = CFUNCTYPE(c_int, c_void_p, c_void_p)
1688
+
1689
+# python class encapsulating the _CBsp pointer
1690
+class Bsp(object):
1691
+    def __init__(self, cnode):
1692
+        pcbsp = cast(cnode, POINTER(_CBsp))
1693
+        self.p = pcbsp
1694
+
1695
+    def getx(self):
1696
+        return self.p.contents.x
1697
+    def setx(self, value):
1698
+        self.p.contents.x = value
1699
+    x = property(getx, setx)
1700
+
1701
+    def gety(self):
1702
+        return self.p.contents.y
1703
+    def sety(self, value):
1704
+        self.p.contents.y = value
1705
+    y = property(gety, sety)
1706
+
1707
+    def getw(self):
1708
+        return self.p.contents.w
1709
+    def setw(self, value):
1710
+        self.p.contents.w = value
1711
+    w = property(getw, setw)
1712
+
1713
+    def geth(self):
1714
+        return self.p.contents.h
1715
+    def seth(self, value):
1716
+        self.p.contents.h = value
1717
+    h = property(geth, seth)
1718
+
1719
+    def getpos(self):
1720
+        return self.p.contents.position
1721
+    def setpos(self, value):
1722
+        self.p.contents.position = value
1723
+    position = property(getpos, setpos)
1724
+
1725
+    def gethor(self):
1726
+        return self.p.contents.horizontal
1727
+    def sethor(self,value):
1728
+        self.p.contents.horizontal = value
1729
+    horizontal = property(gethor, sethor)
1730
+
1731
+    def getlev(self):
1732
+        return self.p.contents.level
1733
+    def setlev(self,value):
1734
+        self.p.contents.level = value
1735
+    level = property(getlev, setlev)
1736
+
1737
+
1738
+def bsp_new_with_size(x, y, w, h):
1739
+    return Bsp(_lib.TCOD_bsp_new_with_size(x, y, w, h))
1740
+
1741
+def bsp_split_once(node, horizontal, position):
1742
+    _lib.TCOD_bsp_split_once(node.p, c_int(horizontal), position)
1743
+
1744
+def bsp_split_recursive(node, randomizer, nb, minHSize, minVSize, maxHRatio,
1745
+                        maxVRatio):
1746
+    _lib.TCOD_bsp_split_recursive(node.p, randomizer, nb, minHSize, minVSize,
1747
+                                  c_float(maxHRatio), c_float(maxVRatio))
1748
+
1749
+def bsp_resize(node, x, y, w, h):
1750
+    _lib.TCOD_bsp_resize(node.p, x, y, w, h)
1751
+
1752
+def bsp_left(node):
1753
+    return Bsp(_lib.TCOD_bsp_left(node.p))
1754
+
1755
+def bsp_right(node):
1756
+    return Bsp(_lib.TCOD_bsp_right(node.p))
1757
+
1758
+def bsp_father(node):
1759
+    return Bsp(_lib.TCOD_bsp_father(node.p))
1760
+
1761
+def bsp_is_leaf(node):
1762
+    return _lib.TCOD_bsp_is_leaf(node.p)
1763
+
1764
+def bsp_contains(node, cx, cy):
1765
+    return _lib.TCOD_bsp_contains(node.p, cx, cy)
1766
+
1767
+def bsp_find_node(node, cx, cy):
1768
+    return Bsp(_lib.TCOD_bsp_find_node(node.p, cx, cy))
1769
+
1770
+def _bsp_traverse(node, callback, userData, func):
1771
+    # convert the c node into a python node
1772
+    #before passing it to the actual callback
1773
+    def node_converter(cnode, data):
1774
+        node = Bsp(cnode)
1775
+        return callback(node, data)
1776
+    cbk_func = BSP_CBK_FUNC(node_converter)
1777
+    func(node.p, cbk_func, userData)
1778
+
1779
+def bsp_traverse_pre_order(node, callback, userData=0):
1780
+    _bsp_traverse(node, callback, userData, _lib.TCOD_bsp_traverse_pre_order)
1781
+
1782
+def bsp_traverse_in_order(node, callback, userData=0):
1783
+    _bsp_traverse(node, callback, userData, _lib.TCOD_bsp_traverse_in_order)
1784
+
1785
+def bsp_traverse_post_order(node, callback, userData=0):
1786
+    _bsp_traverse(node, callback, userData, _lib.TCOD_bsp_traverse_post_order)
1787
+
1788
+def bsp_traverse_level_order(node, callback, userData=0):
1789
+    _bsp_traverse(node, callback, userData, _lib.TCOD_bsp_traverse_level_order)
1790
+
1791
+def bsp_traverse_inverted_level_order(node, callback, userData=0):
1792
+    _bsp_traverse(node, callback, userData,
1793
+                  _lib.TCOD_bsp_traverse_inverted_level_order)
1794
+
1795
+def bsp_remove_sons(node):
1796
+    _lib.TCOD_bsp_remove_sons(node.p)
1797
+
1798
+def bsp_delete(node):
1799
+    _lib.TCOD_bsp_delete(node.p)
1800
+
1801
+############################
1802
+# heightmap module
1803
+############################
1804
+class _CHeightMap(Structure):
1805
+    _fields_=[('w', c_int),
1806
+              ('h', c_int),
1807
+              ('values', POINTER(c_float)),
1808
+              ]
1809
+
1810
+_lib.TCOD_heightmap_new.restype = POINTER(_CHeightMap)
1811
+_lib.TCOD_heightmap_get_value.restype = c_float
1812
+_lib.TCOD_heightmap_has_land_on_border.restype = c_bool
1813
+
1814
+class HeightMap(object):
1815
+    def __init__(self, chm):
1816
+        pchm = cast(chm, POINTER(_CHeightMap))
1817
+        self.p = pchm
1818
+
1819
+    def getw(self):
1820
+        return self.p.contents.w
1821
+    def setw(self, value):
1822
+        self.p.contents.w = value
1823
+    w = property(getw, setw)
1824
+
1825
+    def geth(self):
1826
+        return self.p.contents.h
1827
+    def seth(self, value):
1828
+        self.p.contents.h = value
1829
+    h = property(geth, seth)
1830
+
1831
+def heightmap_new(w, h):
1832
+    phm = _lib.TCOD_heightmap_new(w, h)
1833
+    return HeightMap(phm)
1834
+
1835
+def heightmap_set_value(hm, x, y, value):
1836
+    _lib.TCOD_heightmap_set_value(hm.p, x, y, c_float(value))
1837
+
1838
+def heightmap_add(hm, value):
1839
+    _lib.TCOD_heightmap_add(hm.p, c_float(value))
1840
+
1841
+def heightmap_scale(hm, value):
1842
+    _lib.TCOD_heightmap_scale(hm.p, c_float(value))
1843
+
1844
+def heightmap_clear(hm):
1845
+    _lib.TCOD_heightmap_clear(hm.p)
1846
+
1847
+def heightmap_clamp(hm, mi, ma):
1848
+    _lib.TCOD_heightmap_clamp(hm.p, c_float(mi),c_float(ma))
1849
+
1850
+def heightmap_copy(hm1, hm2):
1851
+    _lib.TCOD_heightmap_copy(hm1.p, hm2.p)
1852
+
1853
+def heightmap_normalize(hm,  mi=0.0, ma=1.0):
1854
+    _lib.TCOD_heightmap_normalize(hm.p, c_float(mi), c_float(ma))
1855
+
1856
+def heightmap_lerp_hm(hm1, hm2, hm3, coef):
1857
+    _lib.TCOD_heightmap_lerp_hm(hm1.p, hm2.p, hm3.p, c_float(coef))
1858
+
1859
+def heightmap_add_hm(hm1, hm2, hm3):
1860
+    _lib.TCOD_heightmap_add_hm(hm1.p, hm2.p, hm3.p)
1861
+
1862
+def heightmap_multiply_hm(hm1, hm2, hm3):
1863
+    _lib.TCOD_heightmap_multiply_hm(hm1.p, hm2.p, hm3.p)
1864
+
1865
+def heightmap_add_hill(hm, x, y, radius, height):
1866
+    _lib.TCOD_heightmap_add_hill(hm.p, c_float( x), c_float( y),
1867
+                                 c_float( radius), c_float( height))
1868
+
1869
+def heightmap_dig_hill(hm, x, y, radius, height):
1870
+    _lib.TCOD_heightmap_dig_hill(hm.p, c_float( x), c_float( y),
1871
+                                 c_float( radius), c_float( height))
1872
+
1873
+def heightmap_mid_point_displacement(hm, rng, roughness):
1874
+    _lib.TCOD_heightmap_mid_point_displacement(hm.p, rng, c_float(roughness))
1875
+
1876
+def heightmap_rain_erosion(hm, nbDrops, erosionCoef, sedimentationCoef, rnd=0):
1877
+    _lib.TCOD_heightmap_rain_erosion(hm.p, nbDrops, c_float( erosionCoef),
1878
+                                     c_float( sedimentationCoef), rnd)
1879
+
1880
+def heightmap_kernel_transform(hm, kernelsize, dx, dy, weight, minLevel,
1881
+                               maxLevel):
1882
+    FARRAY = c_float * kernelsize
1883
+    IARRAY = c_int * kernelsize
1884
+    cdx = IARRAY(*dx)
1885
+    cdy = IARRAY(*dy)
1886
+    cweight = FARRAY(*weight)
1887
+    _lib.TCOD_heightmap_kernel_transform(hm.p, kernelsize, cdx, cdy, cweight,
1888
+                                         c_float(minLevel), c_float(maxLevel))
1889
+
1890
+def heightmap_add_voronoi(hm, nbPoints, nbCoef, coef, rnd=0):
1891
+    FARRAY = c_float * nbCoef
1892
+    ccoef = FARRAY(*coef)
1893
+    _lib.TCOD_heightmap_add_voronoi(hm.p, nbPoints, nbCoef, ccoef, rnd)
1894
+
1895
+def heightmap_add_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta, scale):
1896
+    _lib.TCOD_heightmap_add_fbm(hm.p, noise, c_float(mulx), c_float(muly),
1897
+                                c_float(addx), c_float(addy),
1898
+                                c_float(octaves), c_float(delta),
1899
+                                c_float(scale))
1900
+def heightmap_scale_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta,
1901
+                        scale):
1902
+    _lib.TCOD_heightmap_scale_fbm(hm.p, noise, c_float(mulx), c_float(muly),
1903
+                                  c_float(addx), c_float(addy),
1904
+                                  c_float(octaves), c_float(delta),
1905
+                                  c_float(scale))
1906
+def heightmap_dig_bezier(hm, px, py, startRadius, startDepth, endRadius,
1907
+                         endDepth):
1908
+    IARRAY = c_int * 4
1909
+    cpx = IARRAY(*px)
1910
+    cpy = IARRAY(*py)
1911
+    _lib.TCOD_heightmap_dig_bezier(hm.p, cpx, cpy, c_float(startRadius),
1912
+                                   c_float(startDepth), c_float(endRadius),
1913
+                                   c_float(endDepth))
1914
+
1915
+def heightmap_get_value(hm, x, y):
1916
+    return _lib.TCOD_heightmap_get_value(hm.p, x, y)
1917
+
1918
+def heightmap_get_interpolated_value(hm, x, y):
1919
+    return _lib.TCOD_heightmap_get_interpolated_value(hm.p, c_float(x),
1920
+                                                     c_float(y))
1921
+
1922
+def heightmap_get_slope(hm, x, y):
1923
+    return _lib.TCOD_heightmap_get_slope(hm.p, x, y)
1924
+
1925
+def heightmap_get_normal(hm, x, y, waterLevel):
1926
+    FARRAY = c_float * 3
1927
+    cn = FARRAY()
1928
+    _lib.TCOD_heightmap_get_normal(hm.p, c_float(x), c_float(y), cn,
1929
+                                   c_float(waterLevel))
1930
+    return cn[0], cn[1], cn[2]
1931
+
1932
+def heightmap_count_cells(hm, mi, ma):
1933
+    return _lib.TCOD_heightmap_count_cells(hm.p, c_float(mi), c_float(ma))
1934
+
1935
+def heightmap_has_land_on_border(hm, waterlevel):
1936
+    return _lib.TCOD_heightmap_has_land_on_border(hm.p, c_float(waterlevel))
1937
+
1938
+def heightmap_get_minmax(hm):
1939
+    mi = c_float()
1940
+    ma = c_float()
1941
+    _lib.TCOD_heightmap_get_minmax(hm.p, byref(mi), byref(ma))
1942
+    return mi.value, ma.value
1943
+
1944
+def heightmap_delete(hm):
1945
+    _lib.TCOD_heightmap_delete(hm.p)
1946
+
1947
+
1948
+############################
1949
+# name generator module
1950
+############################
1951
+_lib.TCOD_namegen_generate.restype = c_char_p
1952
+_lib.TCOD_namegen_generate_custom.restype = c_char_p
1953
+
1954
+def namegen_parse(filename,random=0) :
1955
+    _lib.TCOD_namegen_parse(filename,random)
1956
+
1957
+def namegen_generate(name) :
1958
+    return _lib.TCOD_namegen_generate(name, 0)
1959
+
1960
+def namegen_generate_custom(name, rule) :
1961
+    return _lib.TCOD_namegen_generate(name, rule, 0)
1962
+
1963
+def namegen_get_sets():
1964
+    nb=_lib.TCOD_namegen_get_nb_sets_wrapper()
1965
+    SARRAY = c_char_p * nb;
1966
+    setsa = SARRAY()
1967
+    _lib.TCOD_namegen_get_sets_wrapper(setsa)
1968
+    return list(setsa)
1969
+
1970
+def namegen_destroy() :
1971
+    _lib.TCOD_namegen_destroy()
1972
+
1973
+
0 1974
new file mode 100755
1 1975
Binary files /dev/null and b/libtcodxx.dylib differ
2 1976
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+(0,0),(0,1)
2
+(0,0),(1,0)
3
+
4
+(0,1),(0,2)
5
+(0,1),(1,1)
6
+
7
+(0,2),(1,2)
8
+
9
+
10
+(1,0),(1,1)
11
+(1,0),(2,1)
12
+
13
+(1,1),(1,2)
14
+(1,1),(2,1)
15
+
16
+(1,2),(2,2)
17
+
18
+
19
+(2,0),(2,1)
20
+
21
+(2,1),(2,2)
22
+
23
+
0 24
new file mode 100644
... ...
@@ -0,0 +1,119 @@
1
+from __future__ import print_function
2
+import bisect
3
+import collections
4
+from util import CoordPair
5
+
6
+class RoomTree(object):
7
+	def __init__(self):
8
+		self.rooms = []
9
+	def add_room(self, room):
10
+		def dist(pos):
11
+			return (pos[0]**2 + pos[1]**2)**0.5
12
+		bisect.insort(self.rooms, (dist(room.pos),room))
13
+
14
+class RoomGrid(object):
15
+	def __init__(self, size):
16
+		self.grid = [[None for __ in range(size[1])] for ___ in range(size[0])]
17
+		self.size = size
18
+	
19
+UP,DOWN,LEFT,RIGHT = range(4)
20
+opposite = {UP:DOWN,LEFT:RIGHT,DOWN:UP,RIGHT:LEFT}
21
+strings = {UP:'up',DOWN:'down',LEFT:'left',RIGHT:'right'}
22
+# 4y    g  h  i
23
+# 3y    a  b  c
24
+# 2y    d  e  f
25
+# 1y
26
+# 0y
27
+#    0x 1x 2x 3x 4x
28
+# (x,y)
29
+
30
+class Room(object):
31
+	@property
32
+	def sw(self):
33
+		return self.pos
34
+	@property
35
+	def se(self):
36
+		return self.pos[0]+self.size[0]-1, self.pos[1]
37
+	@property
38
+	def ne(self):
39
+		return self.pos[0]+self.size[0]-1, self.pos[1]+self.size[1]-1
40
+	@property
41
+	def nw(self):
42
+		return self.pos[0], self.pos[1]+self.size[1]-1
43
+	@property
44
+	def corners(self):
45
+		'SW, SE, NE, NW'
46
+		return self.sw, self.se, self.ne, self.nw
47
+
48
+	@property
49
+	def rect(self):
50
+		return self.pos, self.size
51
+
52
+	def __init__(self, pos, size):
53
+		self.pos = pos
54
+		self.size = size
55
+		self.neighbours = [None,None,None,None] # u,d,l,r
56
+
57
+	def add_neighbour(self, other):
58
+		sx,sy = self.pos
59
+		ox,oy = other.pos
60
+		
61
+		direction = None
62
+		cont = False
63
+		if sx > other.se[0]+1:
64
+			direction = LEFT
65
+			cont = True
66
+		elif sx < ox - 1:
67
+			direction = RIGHT
68
+			cont = True
69
+
70
+		if cont == False:
71
+			if sy > other.nw[1]+1:
72
+				direction = DOWN
73
+				cont = True
74
+			elif sy < oy-1:
75
+				direction = UP
76
+				cont = True
77
+			else:
78
+				raise ValueError('overlapping rooms')
79
+
80
+		neighbour = self.neighbours[direction]
81
+		if neighbour is None:
82
+			other.neighbours[opposite[direction]] = self	
83
+			self.neighbours[direction] = other
84
+		else:
85
+			neighbour.add_neighbour(other)
86
+
87
+	def __repr__(self):
88
+		return '%s(%r,%r)' % (self.__class__.__name__, self.pos, self.size)
89
+
90
+	def print(self, ind=0, prefix='', visited=None):
91
+		if visited is None: visited = set()
92
+		visited.add(self)
93
+		print('\t'*ind, prefix, ': ', self,sep='')
94
+		for idx,x in enumerate(self.neighbours):
95
+			if x is not None and x not in visited:
96
+				x.print(ind=ind+1, prefix=strings[idx], visited=visited)
97
+
98
+
99
+if __name__ == '__main__':
100
+	x = Room((0,0), (3,3))
101
+	y = Room((4,0), (3,3))
102
+	x.add_neighbour(y)
103
+	y = Room((-4,0), (3,3))
104
+	x.add_neighbour(y)
105
+	y = Room((0,4), (3,3))
106
+	x.add_neighbour(y)
107
+	y = Room((0,-4), (3,3))
108
+	x.add_neighbour(y)
109
+	y = Room((-4,4), (3,3))
110
+	x.add_neighbour(y)
111
+	y = Room((-4,-4), (3,3))
112
+	x.add_neighbour(y)
113
+	y = Room((4,4), (3,3))
114
+	x.add_neighbour(y)
115
+	y = Room((4,-4), (3,3))
116
+	x.add_neighbour(y)
117
+	x.print()
118
+	print()
119
+	y.print()
0 120
new file mode 100644
1 121
Binary files /dev/null and b/terminal.png differ
2 122
new file mode 100644
3 123
Binary files /dev/null and b/tmp.png differ
4 124
new file mode 100644
... ...
@@ -0,0 +1,69 @@
1
+class CoordPair(object):
2
+	def __init__(self, fst, snd=None):
3
+		if snd == None: fst, snd = fst
4
+		self.fst, self.snd = fst,snd
5
+
6
+	@property
7
+	def pair(self):
8
+		return self.fst, self.snd
9
+
10
+	def __len__(self): return 2
11
+	def __iter__(self): return iter(self.pair)
12
+	def __getitem__(self, idx):
13
+		if idx == 0: return self.fst
14
+		elif idx == 1: return self.snd
15
+		else: raise KeyError("Only two elements in a coordpair")
16
+
17
+	def transform(self, *transforms):
18
+		'''Note: mul _then_ add'''
19
+		f,s = self.pair
20
+		for transform in transforms:
21
+			x = transform.get('mul', (1,1))
22
+			if not hasattr(x, '__iter__'): x=(x,x)
23
+			f1,f2 = x
24
+			f *= f1
25
+			s *= f2
26
+			x = transform.get('add', (0,0))
27
+			if not hasattr(x, '__iter__'): x=(x,x)
28
+			f1,f2 = x
29
+			f += f1
30
+			s += f2
31
+		return f,s
32
+
33
+	def __ne__(self, other):
34
+		return not self.__eq__(other)
35
+	def __rne__(self, other):
36
+		return not self.__eq__(other)
37
+
38
+	def __eq__(self, other):
39
+		a,b = self
40
+		c,d = other
41
+		return a==c and b==d
42
+	def __req__(self, other):
43
+		return self == other
44
+
45
+	def __add__(self, other):
46
+		return self.__class__(self.transform({'add': other}))
47
+	def __radd__(self, other):
48
+		return self.__class__(self.transform({'add': other}))
49
+
50
+	def __mul__(self, other):
51
+		return self.__class__(self.transform({'mul': other}))
52
+	def __rmul__(self, other):
53
+		return self.__class__(self.transform({'mul': other}))
54
+
55
+
56
+	def __sub__(self, other):
57
+		a,b = other
58
+		return self.__class__(self.transform({'add': (-a,-b)}))
59
+	def __rsub__(self, other):
60
+		a,b = other
61
+		return self.__class__(self.transform({'add': (-a,-b)}))
62
+
63
+	def __div__(self, other):
64
+		return self.__class__(self.transform({'mul': 1.0/other}))
65
+	def __rdiv__(self, other):
66
+		return self.__class__(self.transform({'mul': 1.0/other}))
67
+
68
+	def __repr__(self):
69
+		return '%s(%s,%s)' % (self.__class__.__name__, self.fst, self.snd)
0 70
new file mode 100644
... ...
@@ -0,0 +1,92 @@
1
+import numpy as np
2
+
3
+class Traveller(object):
4
+	@property
5
+	def x(self): return self.pos[0]
6
+	@x.setter
7
+	def x(self, val): self.pos = val, self.pos[1]
8
+
9
+	@property
10
+	def y(self): return self.pos[1]
11
+	@y.setter
12
+	def y(self, val): self.pos = self.pos[0], val
13
+
14
+	def __init__(self, starting_cell):
15
+		self.pos = starting_cell
16
+		self.connections = []
17
+		self.visited = {self.pos}
18
+
19
+	def random_walk(self, array):
20
+		if len(self.visited) == array.size: return
21
+		steps = []
22
+		maxx, maxy = array.shape
23
+
24
+		sx,sy = None,None
25
+		while (sx,sy) == (None,None) or (sx,sy) in self.visited:
26
+			sx = np.random.random_integers(0,maxx-1)
27
+			sy = np.random.random_integers(0,maxy-1)
28
+
29
+		steps.append((sx,sy))
30
+
31
+		while True:
32
+			dx, dy = 0,0
33
+			r = np.random.random()
34
+			if r < 0.25: # x-1
35
+				dx = -1
36
+			elif r < 0.5: # x+1
37
+				dy = 1
38
+			elif r < 0.75: # y-1
39
+				dx = 1
40
+			else: # y+1
41
+				dy = -1
42
+
43
+			opos = self.pos
44
+			sx += dx
45
+			sy += dy
46
+
47
+			if sx < 0: sx = 0
48
+			elif sx >= maxx: sx = maxx-1
49
+			if sy < 0: sy = 0
50
+			elif sy >= maxy: sy = maxy-1
51
+
52
+			steps.append((sx,sy))
53
+			if (sx,sy) in self.visited:
54
+				met = set()
55
+				path = []
56
+				for x in steps:
57
+					if x in met:
58
+						path = path[:path.index(x)+1]
59
+						met = set(path)
60
+					else:
61
+						path.append(x)
62
+						met.add(x)
63
+				steps = deloop(path)
64
+				break
65
+
66
+		self.connections.extend(zip(steps, steps[1:]))
67
+		self.visited.update(steps)
68
+
69
+
70
+def deloop(path):
71
+	result = []
72
+	idx = 0
73
+	while idx < len(path):
74
+		x = path[idx]
75
+		result.append(x)
76
+		try:
77
+			next_x = path[idx+1:].index(x)
78
+			idx = next_x + idx+1
79
+		except ValueError:
80
+			idx += 1
81
+	return(result)
82
+
83
+
84
+
85
+
86
+
87
+x,y = 49,29
88
+maze = np.array(range(1,x*y+1))
89
+maze.shape = x,y
90
+
91
+t = Traveller((x/2, y/2))
92
+