Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #python 3.5.2
- from random import randint
- UP = 1
- RIGHT = 2
- DOWN = 3
- LEFT= 4
- graph = {}
- # graph = {'0:0': {'1': True, '3': True}, '0:1': {...}}
- SIZE = 10
- def addEdge(graph, x, y, direction):
- directions = {
- UP: [0, -1],
- RIGHT: [1, 0],
- DOWN: [0, 1],
- LEFT: [-1, 0]
- }
- x2 = x+directions[direction][0]
- y2 = y+directions[direction][1]
- if (x2 < 1) or (x2 > SIZE) or (y2 < 1) or (y2 > SIZE):
- return False
- node1 = str(x)+':'+str(y)
- node2 = str(x2)+':'+str(y2)
- if node2 not in graph:
- graph[node2] = {}
- graph[node1][direction] = True
- graph[node2][(direction+1)%4+1] = True
- return True
- for x in range(1,SIZE+1):
- for y in range(1,SIZE+1):
- directions = []
- node = str(x)+':'+str(y)
- if node not in graph:
- graph[node] = {}
- d = randint(1, 4)
- while not addEdge(graph, x, y, d):
- d = randint(1, 4)
- d2 = randint(1, 4)
- while (d2 != d) and (not addEdge(graph, x, y, d2)):
- d2 = randint(1, 4)
- row = "#"
- for x in range(1,SIZE+2):
- row = row + "###"
- print(row)
- for y in range(1,SIZE+1):
- row = "# "
- for x in range(1,SIZE+1):
- key = str(x)+':'+str(y)
- c = " "
- if (RIGHT in graph[key]):
- c = "--"
- row = row + "+" + c
- print(row+"#")
- if y >= SIZE-1:
- break
- row = "# "
- for x in range(1,SIZE+1):
- key = str(x)+':'+str(y)
- c = " "
- if (DOWN in graph[key]):
- c = "| "
- row = row + c + " "
- print(row+"#")
- row = "#"
- for x in range(1,SIZE+2):
- row = row + "###"
- print(row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement