202305741_me14.py
unknown
python
2 years ago
4.7 kB
9
Indexable
lines = []
char_basis = []
char_blank = []
deviate = False
go_down = False
position = 0
column_counter = 0
row_counter = 0
plus_err = 0
maze_counter = 1
def length_matrix(n):
if "]]" not in n:
return True
def line_creator(matrix):
global lines
global row_counter
if "]]" not in matrix:
lines.append(matrix.replace('[', '').replace(']', '').replace(',', ''))
row_counter += 1
def maze_solver(maze):
global deviate, memory1, memory2, memory3
global position
global row_counter
global column_counter
global maze_counter
global go_down
global char_basis, char_blank
if maze[-1] == '0' and maze[0] == '0':
if len(maze) == maze_counter:
char_basis[position] = '1'
char_blank[position] = '1'
"Path found"
char_blank = str(char_blank)
char_blank = char_blank.replace("['", "[[").replace("']", "]]").replace("', '\\n', '", "],\n[").replace("'", "")
print(char_blank)
pass
if position < len(maze) - (column_counter + 1):
if maze[position + 1] == '0' and maze[position + (column_counter + 1)] == '0':
memory1 = position
memory2 = maze_counter
memory3 = char_basis
# Checkpoint
if go_down is True and memory2 <= len(maze) - (column_counter + 1):
if maze[memory1 + (column_counter + 1)] == '0':
char_basis[memory1] = '1'
'1Check'
position = memory1
maze_counter = memory2
position += (column_counter + 1)
maze_counter += (column_counter + 1)
go_down = False
return maze_solver(maze)
if position + 1 != len(maze):
# Case A
if maze[position + 1] == '0' and deviate is False:
char_basis[position] = '1'
char_blank[position] = '1'
position += 1
maze_counter += 1
return maze_solver(maze)
# Case B
elif maze[position + 1] == '1' and deviate is False:
"Stop, deviate"
deviate = True
return maze_solver(maze)
# Case C
elif (maze[position + 1] != 0 or maze[position + 1] != 1) and deviate is False:
"Endpoint, must deviate"
deviate = True
return maze_solver(maze)
# Case D
elif deviate is True and maze[position + (column_counter + 1)] == '0':
char_basis[position] = '1'
char_blank[position] = '1'
'1D'
position += (column_counter + 1)
maze_counter += (column_counter + 1)
deviate = False
return maze_solver(maze)
# Go back to memory bank as checkpoint
elif deviate is True and maze[position + (column_counter + 1)] == '1':
"Go to checkpoint"
go_down = True
deviate = False
return maze_solver(maze)
else:
print("No path found")
else:
print("No path found")
pass
# Recursive While Loop
def while_loop(w):
if w < 1:
pass
else:
global position
global deviate
global lines
global row_counter
global column_counter
global maze_counter
global go_down
global char_basis, char_blank
maze_input = str(input())
if length_matrix(maze_input) is True:
line_creator(maze_input)
w -= 0
else:
lines.append(maze_input.replace('[', '').replace(']', '').replace(',', ''))
column_counter = len(lines[0])
lines = str(lines)
row_counter += 1
reform_lines = lines.strip('[]').replace("'", "").replace(', ', '\n')
char_basis = list(reform_lines)
char_basis[0] = '1'
blank = lines.strip('[]').replace("'", "").replace('1', '0').replace(', ', '\n')
char_blank = list(blank)
maze_solver(reform_lines)
lines = []
column_counter = 0
row_counter = 0
position = 0
deviate = False
go_down = False
maze_counter = 1
char_basis = []
char_blank = []
w -= 1
return while_loop(w)
num_c = while_loop(int(input()))
Editor is loading...
Leave a Comment