You are viewing a single comment's thread. Return to all comments →
I didn use graphs at all..
def moveminima(mat, rows, cols, strow, stcol, gorow, gocol): moves = ((1,0),(-1,0), (0,1), (0,-1)) visit = {(strow, stcol)} q = [[strow, stcol, 0]] while len(q)>0: path, q = q[0], q[1:] row, col, val = path for move in moves: nrow, ncol = row, col while True: nrow, ncol = nrow+move[0], ncol+move[1] if nrow>=0 and ncol>=0 and nrow<rows and ncol<cols and mat[nrow][ncol]== '.': if (nrow, ncol) == (gorow, gocol): return val+1 else: if (nrow, ncol) not in visit: visit.add((nrow, ncol)) q += [[nrow, ncol, val+1]] else: break return -1
def moveminima(mat, rows, cols, strow, stcol, gorow, gocol):
moves = ((1,0),(-1,0), (0,1), (0,-1)) visit = {(strow, stcol)} q = [[strow, stcol, 0]] while len(q)>0: path, q = q[0], q[1:] row, col, val = path for move in moves: nrow, ncol = row, col while True: nrow, ncol = nrow+move[0], ncol+move[1] if nrow>=0 and ncol>=0 and nrow<rows and ncol<cols and mat[nrow][ncol]== '.': if (nrow, ncol) == (gorow, gocol): return val+1 else: if (nrow, ncol) not in visit: visit.add((nrow, ncol)) q += [[nrow, ncol, val+1]] else: break return -1
Seems like cookies are disabled on this browser, please enable them to open this website
Castle on the Grid
You are viewing a single comment's thread. Return to all comments →
I didn use graphs at all..