-
Notifications
You must be signed in to change notification settings - Fork 0
/
nimaze.nim
57 lines (48 loc) · 1.7 KB
/
nimaze.nim
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
import nimazepkg/utils
proc drawAscii*(map: Map): bool =
## Draw an ascii representation of a maze to stdout
##
## We only need to draw south and east walls, because
## we are starting in the top-left corner and moving down to the bottom-right
stdout.write " "
for i in 0..(map.width*2-1):
stdout.write "_"
stdout.write "\n"
for y in 0..map.height-1:
stdout.write "|"
for x in 0..map.width-1:
stdout.write if ((map.grid[y][x] and ord S) != 0): " "
else: "_"
if ((map.grid[y][x] and ord E) != 0):
stdout.write if (((map.grid[y][x] or map.grid[y][x+1]) and ord S) != 0): " "
else: "_"
else: stdout.write "|"
stdout.write "\n"
when isMainModule:
import docopt, strutils, random
# Import all algorithm modules here
import nimazepkg/recdescent
let doc = """
nimaze 0.1.0 by Luka Hadzi-Djokic
Usage:
nimaze [-w=<x>|--width=<x>] [-h=<y>|--height=<y>] [-s=<z>|--seed=<z>]
nimaze --help
nimaze (-v | --version)
Options:
-w --width=<x> Set width of maze [default: 0]
-h --height=<y> Set height of maze [default: 0]
-s --seed=<z> Set seed for prng [default: 0]
--help Show this screen.
-v --version Show version.
"""
let args = docopt(doc, version = "nimaze 0.1.0")
let width = if parseInt($args["--width"]) != 0: parseInt($args["--width"])
else: 10
let height = if parseInt($args["--height"]) != 0: parseInt($args["--height"])
else: width
let seed = if parseInt($args["--seed"]) != 0: parseInt($args["--seed"])
else: random high(int)
randomize seed
var map = newMap(width, height)
discard recursive_descent(0, 0, map)
discard drawAscii(map)