graph build fixed

This commit is contained in:
s473603 2023-04-21 12:17:15 +02:00
parent 8b88053ecb
commit 5e04365580

View File

@ -65,7 +65,7 @@ def draw_interface():
tractor = Tractor(x, y, Direction.RIGHT) tractor = Tractor(x, y, Direction.RIGHT)
grid = Grid(BOARD_SIZE, BOARD_SIZE, BLOCK_SIZE) grid = Grid(BOARD_SIZE, BOARD_SIZE, BLOCK_SIZE)
graph = Graph(grid)
fl_running = True fl_running = True
while fl_running: while fl_running:
draw_grid() draw_grid()
@ -192,10 +192,9 @@ class Grid:
i -= 1 i -= 1
def get_next_nodes(self, x, y): def get_next_nodes(self, x, y):
check_next_node = lambda x, y: True if 0 <= x < BOARD_SIZE and 0 <= y < BOARD_SIZE and ( check_next_node = lambda x, y: 1 if 0 <= x < BOARD_SIZE and 0 <= y < BOARD_SIZE and (self.grid[x][y] != types.ROCK) else 5
self.grid[x][y] != types.ROCK) else False
ways = [-1, 0], [1, 0], [0, -1], [0, 1] ways = [-1, 0], [1, 0], [0, -1], [0, 1]
return [(x + dx, y + dy) for dx, dy in ways if check_next_node(x + dx, y + dy)] return [(1 if self.grid[x][y] != types.ROCK else 5, (x + dx, y + dy)) for dx, dy in ways if check_next_node(x + dx, y + dy)]
class Graph: class Graph: