Commit fbd2d116 authored by Douglas AC's avatar Douglas AC
Browse files

Painting map.

parent 16ba0013
......@@ -3,24 +3,44 @@ from subprocess import Popen, PIPE
import numpy as np
def geraMapa(linhas, colunas, cores, semente):
process = Popen(["../accessories/geramapa", str(linhas), str(colunas), str(cores), str(semente)], stdout=PIPE)
def generateMap(rows, cols, colors, seed):
process = Popen(["../accessories/geraMapa", str(rows), str(cols), str(colors), str(seed)], stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
s_mapa = output.decode("utf-8").split("\n",1)[1]
s_map = output.decode("utf-8").split("\n",1)[1]
return np.fromstring(s_map, dtype=int, sep=' ').reshape(rows,cols)
def paint(map, prev_color, next_color, row, col, max_rows, max_cols):
if((row < 0) or (col < 0) or (row >= max_rows) or (col >= max_cols)):
return
if(map[row][col] != prev_color):
return
map[row][col] = next_color
paint(map, prev_color, next_color, row, col+1, max_rows, max_cols)
paint(map, prev_color, next_color, row, col-1, max_rows, max_cols)
paint(map, prev_color, next_color, row+1, col, max_rows, max_cols)
paint(map, prev_color, next_color, row-1, col, max_rows, max_cols)
return np.fromstring(s_mapa, dtype=int, sep=' ').reshape(linhas,colunas)
def main():
linhas = 10
colunas = 10
cores = 5
semente = 1234
mapa = geraMapa(linhas, colunas, cores, semente)
rows = 5
cols = 5
colors = 5
seed = 1234
map = generateMap(rows, cols, colors, seed)
print(map)
print(mapa)
paint(map, map[0][0], 1, 0, 0, rows, cols)
print(map)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment