liquidwar7core 0.2.0

Liquidwar7 core logic library, low-level things which are game-engine agnostic.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
// Copyright (C) 2025 Christian Mauduit <ufoot@ufoot.org>

use crate::quad_mesh::QuadMesh;
use crate::{GameHandler, World};

/// Width of the default battlefield (192 columns)
pub const SIMULATION_BATTLEFIELD_WIDTH: usize = 192;

/// Height of the default battlefield (108 rows)
pub const SIMULATION_BATTLEFIELD_HEIGHT: usize = 108;

/// Number of user-defined layers in the text maze (3)
pub const SIMULATION_TEXT_LAYERS: usize = 3;

/// Depth of the default battlefield (3 user-defined layers + 1 ground = 4)
pub const SIMULATION_BATTLEFIELD_DEPTH: usize = 4;

/// Returns the hardcoded maze map as a string.
/// The maze is 192 columns * 108 rows * 3 layers deep (from simulation-{0,1,2}.png)
/// '#' represents walls, ' ' represents walkable areas.
/// Layers are separated by lines of '-' characters.
/// Features the original Liquid War game (by Thom-Thom) on the left and a maze on the right.
pub fn default_simulation_maze() -> &'static str {
    concat!(
"                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "    ####################################################################################################                                                                                        \n",
        "    ##                                                                                                 #                                                                                        \n",
        "    #                                                                                                  #                                                                                        \n",
        "    #                                    ##                               ####         ##              #                                                                                        \n",
        "    #                                 ######              #####################     ######      ###    #                                                                                        \n",
        "    #                                ######             ######################     ########    #####   #                                                                                        \n",
        "    #                                ####             ####################        ##########   #####   #                                                                                        \n",
        "    #                               ###              #####                       ####     ###  ####    #                                                                                        \n",
        "    #                              ###              ####                        ####      ###  ####    #                                                                                        \n",
        "    #                             ###               ###               ###      ####       ###  ####    #                                                                                        \n",
        "    #                            ####               ###              ######   ####        ###  ####    #                 ##################################################                     \n",
        "    #                            ###     ####      ###             ##############         ###  ###     #                 #                                                #                     \n",
        "    #                           ###      #####     ###            ##### ########          ###  ##     ##                 #                                                #                     \n",
        "    #                           ###      #####     ###           ####      ####           ###  #   #####                 #                                                #                     \n",
        "    #                          ###      ######     ####         ###                       ###     ######                 #                                                #                     \n",
        "    #                          ###      ######      ###         ###                        ###   #######                 #                                                #                     \n",
        "    #                         ###       ######      ####         #                         ###  ########                 #     ######     #######     ###############     #                     \n",
        "    #                         ###        #####       ######                                 #   ########                 #     #    #     #     #                   #     #                     \n",
        "    #                        ###         #####        #####                    #####           ####  ###                 #     #    #     #     #                   #                           \n",
        "    #                        ###         #####         #####                 #########         ###     #                 #     #    #     #     #                   #                           \n",
        "    #                       ####         #####          #####               ###########       ####     #                 #          #     #                         #                           \n",
        "    #                       ###        # #####           #####             #############     ####      #                 #          #     #                         #                           \n",
        "    #                        #        ########             #####           #############      ##       #                 #          #     #                         #                           \n",
        "    #                                ########               #####         ####        ###              #                 #          #     #                         #                           \n",
        "    #                               ########            #    #####        ###          ##              #                 #          #     #           #     #       #                           \n",
        "    #                               ########           ###    #####       ##            #          #####                 #          #     #     #     #     #       #                           \n",
        "    #                              ########    #        #      ###        #             #      #########                 #          #     #     #     #     #       #                           \n",
        "    #                              ### ####   ###                                       #     ##########                 #          #     #     #     #     #       #     #                     \n",
        "    #                              ###  ###   #####                                          #######   #      ######     #          #     #     #     #     #       #     #                     \n",
        "    ######     #                   ###  ###   ######                                        ####       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #######   ###    #             ###  ###    #######                                     ###         #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    ########  ####  ###            ####  ###    #######                     ########      ####     #   #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #    ####  #### ###             ###  ####    ######                    ##########     ###     ###  #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #     ###   ###  #              ####  ####    ####               #      ##########    ###     ###  #      #    #     #          #     #     #     #     #       #     #                     \n",
        "          ###   ###                  ####  ####     ##              ###            ####   ####    #### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "          ###  ####                   ###  #####                   ####             ###    ###     ### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "          ###  ###                     #     ####       #          ####             ####   ####    ### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "         ###  ####          #                          ###          ##               ###    ####   ### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "        ####   ##          ##          #                #                             ###    ####  ### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "        ###               ###         ###                                              ###    #### ### #      #    #     #          #     #     #     #     #       #     #                     \n",
        "         #               ###           #                                               ###     ##  ### #      #    #     #          #     #     #     #             #     #                     \n",
        "                       ####                                                 #          ###         ### #      #    #     ######     #     #     #     #             #     #                     \n",
        "               ##     ##                                                   ###         ###         ### #      #    #     #          #     #     #     #             #     #                     \n",
        "              #### ####                                      #              #          ###        #### #      #    #     #          #     #     #     #             #     #                     \n",
        "            #########                                       ###                        ###        ###  #      #    #     #          #     #     #     #             #     #                     \n",
        "           ########                 ########            #    #                    ##   ###        ###  #      #    #     #          #     #     #     #             #     #                     \n",
        "         ######                 ###########            ###                       ###   ###   ##    #   #      #    #     #          #     #     #     #     #             #                     \n",
        "    #   #####                      #######              #                         #    ###  ####       #      #    #     #          #     #     #     #     #             #                     \n",
        "    #  #####                        #####                                              ###   ###       #      #    #     #          #     #     #     #     #             #                     \n",
        "    # ####                           ####          #                  #                ###   ###       #      #    #     #          #     #     #     #     #             #                     \n",
        "    #####                            ####    #    ##                 ##                ###   ###       #      #    #     ######     #     #     #     #######             #                     \n",
        "    ####                             #####  ###  #####               ###              ####   ###       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    ###                  ###        #######  #  #######      #       ###               ##    ###       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #                    ####      #########   ######       ###      ####                    ###       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #         #         ######   ###################         #       #####                   ###       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #        ###          ##########         ######                   #####                 ####       #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #       ####           ###### #            ####                   ########              ###        #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #       ###             ####                ###                   ###########           ###        #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #       ###             ####  #              ###          #        ###################  ###        #      #    #     #          #     #     #     #             #     #                     \n",
        "    #       ###             ###  ###           #  ###        ###        ################    ###        #      #    #     #          #     #     #     #             #     #                     \n",
        "    #       ###            ###    ###         ###  ######     #            ########         ###        #      #    #     #          #     #     #     #             #     #                     \n",
        "    #        ###          ###     ####         #    #####   ##                             ###         #      #    #     #          #     #     #     #             #     #                     \n",
        "    #        ###        ####     ####                ###    ###                            ###         #      #    #     #          #     #     #     #             #     #                     \n",
        "    #         ####      ####      #                  ####   ##                            ###          #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #         ####       ##                            #   ###   ###                     ####          #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #         ####       ##                                 #   ####       #####      ######           #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #         ####                                    #          #    #####################            #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #          #                                     ###             #####################             #      #    #     #          #     #           #     #       #     #                     \n",
        "    #                                               ###      #        #####    #######                 #      #    #     #          #     #           #     #       #     #                     \n",
        "    #                                              ####     ###                                        #      #    #     #          #     #           #     #       #     #                     \n",
        "    #                                  ######      ###     ####                                        #      #    #     #          #     #           #     #       #     #                     \n",
        "    #                                 ########    ###  #    ####                           ##          #      #    #     #          #     #           #     #       #     #                     \n",
        "    #                    #             ######      #  ###     #                          #####         #      #    #     #          #     #     #     #     #       #     #                     \n",
        "    #                   ###                            #     #     #         #        #######          #      #    #     ######     #     #     #                   #     #                     \n",
        "    #           ##       ###                                ###   ##       ####      #######           #      #    #     #          #     #     #                   #     #                     \n",
        "    #          ###       ###                                 #    ##    #######    #######             #      #    #     #          #     #     #                   #     #                     \n",
        "    #           #        ####                                    #############    #####                #      ######     #          #     #     #                   #     #                     \n",
        "    #                     ###                                   ###########        ###                 #                 #          #     #     #           #########     #                     \n",
        "    #                     ####               #                 ##########                              #                 #          #           #     #                   #                     \n",
        "    #                      ####             ###               #######                                  #                 #          #           #     #                   #                     \n",
        "    #                       ###              #               #######                                   #                 #          #           #     #                   #                     \n",
        "    #                       ####                            ########                                   #                 #          #           #     #                   #                     \n",
        "    #                        ####                         ################                             #                 ######     #           #     #                   #                     \n",
        "    #                         ###       ##               ##################                            #                 #          #############     #####################                     \n",
        "    #                         ####       ########     ############# ######                             #                 #                                                #                     \n",
        "    #                          ##         ########################                                     #                 #                                                                      \n",
        "    #                                      ########################                                    #                 #                                                                      \n",
        "    #                                         ################  #####                                  #                 #                                                                      \n",
        "    #                                       ###############       ####                                 #                 #                                                #                     \n",
        "    #                                    ########  ###  ####       ###                                 #                 ##################################################                     \n",
        "    #                                   #######   ###    ######     #                                  #                                                                                        \n",
        "    #                                  ######     ###      #####                                       #                                                                                        \n",
        "    #                                   ##       ###        ###                                        #                                                                                        \n",
        "    #                                            ###         #                                         #                                                                                        \n",
        "    #                                            ###                                                   #                                                                                        \n",
        "    #                                             #                                                    #                                                                                        \n",
        "    #                                                                                                  #                                                                                        \n",
        "    #                                                                                                  #                                                                                        \n",
        "    ##                                                                                                ##                                                                                        \n",
        "    ####################################################################################################                                                                                        \n",
        "                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "                                                                                                                                                                                                \n",
        "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################        ##################     ###########################       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #     ######     #######     ###############     #       ##############\n",
        "#################################################################################################################        #     #    #     #     #                   #     #       ##############\n",
        "#################################################################################################################        #     #    #     #     #                   #     #       ##############\n",
        "#################################################################################################################        #     #    #     #     #                   #     #       ##############\n",
        "#################################################################################################################        #          #     #                         #     #       ##############\n",
        "##########################################################################################################################          #     #                         #     #       ##############\n",
        "##########################################################################################################################          #     #                         #     #       ##############\n",
        "##########################################################################################################################          #     #                         #     #       ##############\n",
        "##########################################################################################################################          #     #           #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #             #     #       ##############\n",
        "###############################################################################################################################     #     #     #     #             #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #             #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #             #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #             #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #             #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #             #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #             #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #             #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #             #       ##############\n",
        "###############################################################################################################################     #     #     #     #######             #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #             #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #             #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #             #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #             #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #             #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #     #     #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #           #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #           #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #           #     #       #     #       ##############\n",
        "#################################################################################################     ####################          #     #           #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #           #     #       #     #       ##############\n",
        "##########################################################################################################################          #     #     #     #     #       #     #       ##############\n",
        "###############################################################################################################################     #     #     #                   #     #       ##############\n",
        "##########################################################################################################################          #     #     #                   #     #       ##############\n",
        "##########################################################################################################################          #     #     #                   #     #       ##############\n",
        "##########################################################################################################################          #     #     #                   #     #       ##############\n",
        "##########################################################################################################################          #     #     #           #########     #       ##############\n",
        "##########################################################################################################################          #           #     #                   #       ##############\n",
        "##########################################################################################################################          #           #     #                   #       ##############\n",
        "##########################################################################################################################          #           #     #                   #       ##############\n",
        "##########################################################################################################################          #           #     #                   #       ##############\n",
        "###############################################################################################################################     #           #     #                   #       ##############\n",
        "##########################################################################################################################          #############     #####################       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #                                                #       ##############\n",
        "#################################################################################################################        #########              ###########################       ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "#################################################################################################################                                                                 ##############\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "#################################################################################################                                 ##############################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "################################################################################################################################################################################################\n",
        "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
    )
}

/// Creates a default simulation with the hardcoded maze.
///
/// Returns a GameHandler wrapping a World with a battlefield of 192x108 cells.
/// The maze is based on the simulation.png image (original Liquid War by Thom-Thom + maze).
///
/// # Panics
///
/// Panics if the hardcoded maze exceeds dimension limits (should never happen).
pub fn create_default_simulation() -> GameHandler<World> {
    let maze = default_simulation_maze();
    let gradient_mesh = QuadMesh::from_text(maze)
        .expect("Default simulation maze exceeds dimension limits");
    let world = World::new(gradient_mesh);
    GameHandler::new(world)
}

/// Creates a simulation from a vector of image file paths.
///
/// Each image represents one layer (z-level) in the battlefield.
/// Bright pixels become walkable areas, dark pixels become walls.
/// The images should be in order from z=0 (bottom) to z=depth-1 (top).
///
/// Requires the `image` feature.
///
/// # Arguments
///
/// * `paths` - Vector of image file paths, one per layer
///
/// # Example
///
/// ```no_run
/// use liquidwar7core::create_simulation_from_paths;
///
/// let paths = vec!["layer0.png", "layer1.png", "layer2.png"];
/// let handler = create_simulation_from_paths(&paths).unwrap();
/// ```
#[cfg(feature = "image")]
pub fn create_simulation_from_paths<P: AsRef<std::path::Path>>(
    paths: &[P],
) -> Result<GameHandler<World>, crate::quad_mesh::QuadMeshError> {
    let gradient_mesh = QuadMesh::from_paths(paths)?;
    let world = World::new(gradient_mesh);
    Ok(GameHandler::new(world))
}

/// Creates a simulation from a slice of DynamicImages.
///
/// Each image represents one layer (z-level) in the battlefield.
/// Bright pixels become walkable areas, dark pixels become walls.
/// All images must have the same dimensions.
///
/// Requires the `image` feature.
///
/// # Arguments
///
/// * `images` - Slice of images, one per layer
///
/// # Example
///
/// ```no_run
/// use liquidwar7core::create_simulation_from_images;
///
/// let layer0 = image::open("layer0.png").unwrap();
/// let layer1 = image::open("layer1.png").unwrap();
/// let handler = create_simulation_from_images(&[layer0, layer1]).unwrap();
/// ```
#[cfg(feature = "image")]
pub fn create_simulation_from_images(
    images: &[image::DynamicImage],
) -> Result<GameHandler<World>, crate::quad_mesh::QuadMeshError> {
    let gradient_mesh = QuadMesh::from_images(images)?;
    let world = World::new(gradient_mesh);
    Ok(GameHandler::new(world))
}

#[cfg(test)]
mod tests {
    use super::*;

    fn is_sep_line(line: &str) -> bool {
        if line.is_empty() {
            return false;
        }
        let mut has_sep = false;
        for c in line.chars() {
            if c == '-' || c == '_' || c == '=' {
                has_sep = true;
            } else if c != ' ' {
                return false;
            }
        }
        has_sep
    }

    #[test]
    fn test_maze_dimensions() {
        let maze = default_simulation_maze();

        // Split into layers
        let mut layers: Vec<Vec<&str>> = Vec::new();
        let mut current: Vec<&str> = Vec::new();
        for line in maze.lines() {
            if is_sep_line(line) {
                if !current.is_empty() {
                    layers.push(current);
                    current = Vec::new();
                }
            } else {
                current.push(line);
            }
        }
        if !current.is_empty() {
            layers.push(current);
        }

        assert_eq!(
            layers.len(),
            SIMULATION_TEXT_LAYERS,
            "Maze text should have {} layers",
            SIMULATION_TEXT_LAYERS
        );

        for (layer_idx, layer) in layers.iter().enumerate() {
            assert_eq!(
                layer.len(),
                SIMULATION_BATTLEFIELD_HEIGHT,
                "Layer {} should have {} rows, got {}",
                layer_idx,
                SIMULATION_BATTLEFIELD_HEIGHT,
                layer.len()
            );

            for (row_idx, line) in layer.iter().enumerate() {
                assert_eq!(
                    line.len(),
                    SIMULATION_BATTLEFIELD_WIDTH,
                    "Layer {} row {} should have {} columns, got {}",
                    layer_idx,
                    row_idx,
                    SIMULATION_BATTLEFIELD_WIDTH,
                    line.len()
                );
            }
        }
    }

    #[test]
    fn test_create_default_simulation() {
        let handler = create_default_simulation();
        let world = handler.state();

        // World should have places (one per cell in the mesh)
        assert!(world.place_count() > 0, "World should have places");

        // The mesh should have walkable cells (walls are not in the mesh)
        let mesh = world.mesh();
        let cell_count = mesh.cell_count();
        let total_volume = mesh.total_volume();
        let walkable_coords = mesh.walkable_coords();
        let (width, height, depth) = mesh.dimensions();

        println!(
            "Compaction: {}x{}x{}={} coords, {} walkable, {} cells (ratio: {:.1}x)",
            width,
            height,
            depth,
            total_volume,
            walkable_coords,
            cell_count,
            walkable_coords as f32 / cell_count as f32
        );

        assert_eq!(depth, SIMULATION_BATTLEFIELD_DEPTH, "Mesh should have {} layers", SIMULATION_BATTLEFIELD_DEPTH);

        assert!(
            cell_count < total_volume,
            "Mesh should have fewer cells than total coordinate space"
        );
        assert!(cell_count > 0, "Mesh should have some cells");
    }

    #[test]
    fn test_maze_has_content() {
        let maze = default_simulation_maze();

        // Count walls and floors
        let wall_count = maze.chars().filter(|&c| c == '#').count();
        let floor_count = maze.chars().filter(|&c| c == ' ').count();

        // Should have significant content (not empty or all walls)
        assert!(wall_count > 1000, "Maze should have walls");
        assert!(floor_count > 1000, "Maze should have walkable areas");
    }

    #[test]
    #[cfg(feature = "image")]
    fn test_create_simulation_from_images() {
        // Load simulation images from the media folder
        let base_path = env!("CARGO_MANIFEST_DIR");
        let paths = vec![
            format!("{}/../../media/simulation-0.png", base_path),
            format!("{}/../../media/simulation-1.png", base_path),
            format!("{}/../../media/simulation-2.png", base_path),
        ];

        let handler = create_simulation_from_paths(&paths).expect("Failed to load images");
        let world = handler.state();

        // World should have places
        assert!(world.place_count() > 0, "World should have places");

        // The mesh should have expected dimensions
        let mesh = world.mesh();
        let (width, height, depth) = mesh.dimensions();

        assert_eq!(width, SIMULATION_BATTLEFIELD_WIDTH, "Width should match");
        assert_eq!(height, SIMULATION_BATTLEFIELD_HEIGHT, "Height should match");
        assert_eq!(depth, SIMULATION_BATTLEFIELD_DEPTH, "Depth should match (3 layers + 1 ground)");

        let walkable_coords = mesh.walkable_coords();
        println!(
            "Image-based simulation: {}x{}x{}, {} walkable coords, {} cells",
            width,
            height,
            depth,
            walkable_coords,
            mesh.cell_count()
        );

        // Should have significant walkable area
        assert!(walkable_coords > 1000, "Should have walkable area");
    }

    #[test]
    #[cfg(feature = "image")]
    fn test_generate_ascii_from_images() {
        use shortestpath::mesh_source::{repr_source_3d, Source3D, Source3DFromImage};

        // Load simulation images from the media folder
        let base_path = env!("CARGO_MANIFEST_DIR");
        let paths = vec![
            format!("{}/../../media/simulation-0.png", base_path),
            format!("{}/../../media/simulation-1.png", base_path),
            format!("{}/../../media/simulation-2.png", base_path),
        ];

        let source = Source3DFromImage::from_paths(&paths, 0.5).unwrap();
        let repr = repr_source_3d(&source);

        // Write to /tmp for inspection
        std::fs::write("/tmp/simulation_ascii.txt", &repr).unwrap();
        println!("ASCII art written to /tmp/simulation_ascii.txt");
        println!("Dimensions: {}x{}x{}", source.width(), source.height(), source.depth());

        // Verify dimensions
        let lines: Vec<&str> = repr.lines().collect();
        let layer_sep_count = lines.iter().filter(|l| l.starts_with("----")).count();
        assert_eq!(layer_sep_count, 3, "Should have 3 layer separators");
    }
}