diff --git a/images/sapper_idle/agent0.png b/images/sapper_idle/agent0.png index c3e84ad..8869cc5 100644 Binary files a/images/sapper_idle/agent0.png and b/images/sapper_idle/agent0.png differ diff --git a/images/sapper_idle/agent2.png b/images/sapper_idle/agent2.png index 8869cc5..c3e84ad 100644 Binary files a/images/sapper_idle/agent2.png and b/images/sapper_idle/agent2.png differ diff --git a/src/BFS.py b/src/BFS.py index 0a2573f..3036c03 100644 --- a/src/BFS.py +++ b/src/BFS.py @@ -11,9 +11,12 @@ def successor(x: int, y: int, direction: int): for i in range(4): # TODO # naprawić by zaczął od prawej i szedł zgodnie z zegarem + # prawo -> góra -> lewo -> dół + # chcemy: prawo -> dół -> lewo -> góra neighbour_x = x + DIRECTIONS_X[i] neighbour_y = y + DIRECTIONS_Y[i] neighbour_side = DIRECTIONS_SIDE[i] + # print(neighbour_x, neighbour_y, neighbour_side) if 0 <= neighbour_x <= 9 and 0 <= neighbour_y <= 9: # TODO @@ -26,10 +29,10 @@ def successor(x: int, y: int, direction: int): # d 100 # w 119 # 1 direction -> prawo - # neighbour side 1 -> po prawej 1-1 =0 -> W - # neighbour side 2 -> na gorze 2-1 =1 -> D + W - # neighbour side 3 -> po lewej 3-1 =2 -> D + D + W - # neighbour side 0 -> na dole 0-1 =-1 -> A + W + # neighbour side 1 -> po prawej 1-1 = 0 -> W + # neighbour side 2 -> na gorze 2-1 = 1 -> D + W + # neighbour side 3 -> po lewej 3-1 = 2 -> D + D + W + # neighbour side 0 -> na dole 0-1 = -1 -> A + W def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, start_direction: int): @@ -43,12 +46,11 @@ def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, st if field[node.y][node.x].mine: path = [] actions = [] - print(explored) while node.parent: path.append((node.x, node.y)) - actions.extend(node.actions) + actions.append(node.actions) node = node.parent - return path, actions + return path[::-1], sum(actions[::-1], []) for x, y, direction, actions in successor(node.x, node.y, node.direction): if field[y][x].number in (2, 3): @@ -59,4 +61,4 @@ def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, st neighbour_node = Node(x, y, direction, node, actions) node_queue.put(neighbour_node) - return False + return False, False diff --git a/src/const.py b/src/const.py index d912b8e..b50f30f 100644 --- a/src/const.py +++ b/src/const.py @@ -63,6 +63,14 @@ DEFAULT_FIELD = [ ] # TODO # to poprawić + +# -1 -> prawo, ruch +# 0 -> ruch +# 1 -> lewo, ruch +# -2 -> prawo, prawo, ruch +# 2 -> lewo, lewo, ruch +# -3 -> lewo, ruch +# 3 -> prawo, ruch ACTIONS = { -1: [pg.K_d, pg.K_w], 0: [pg.K_w], @@ -74,5 +82,5 @@ ACTIONS = { } # TODO DIRECTIONS_X = (1, 0, -1, 0) -DIRECTIONS_Y = (0, -1, 0, 1) +DIRECTIONS_Y = (0, 1, 0, -1) DIRECTIONS_SIDE = (1, 2, 3, 0) diff --git a/src/game_ui.py b/src/game_ui.py index e9b2aa9..a3f4ae4 100644 --- a/src/game_ui.py +++ b/src/game_ui.py @@ -14,7 +14,7 @@ class GameUi: def move(self): coord = 'x' if self.agent.direction in (1, 3) else 'y' - shift = -1 if self.agent.direction in (2, 3) else 1 + shift = -1 if self.agent.direction in (0, 3) else 1 if coord == 'x': if self.env.field[self.agent.y][self.agent.x+shift].number in (2, 3): diff --git a/src/main.py b/src/main.py index cd897fd..1ec8d80 100644 --- a/src/main.py +++ b/src/main.py @@ -25,10 +25,10 @@ def main(): # TODO # poprawić numeracje stron agenta by szło zgodnie z zegarem # ruchy agenta: - # 1 - right - # 2 - up - # 3 - left - # 0 - down + # 1 - right -> 1 + # 0 - up -> 0 + # 3 - left -> 3 + # 2 - down -> 2 while running: for event in pg.event.get(): @@ -42,11 +42,12 @@ def main(): elif (event.key == pg.K_w or event.key == pg.K_UP) \ and ((agent.direction == 1 and agent.x * 80 < 700) or (agent.direction == 3 and agent.x * 80 > 5) - or (agent.direction == 2 and agent.y * 80 > 0) - or (agent.direction == 0 and agent.y * 80 < 700)): + or (agent.direction == 0 and agent.y * 80 > 0) + or (agent.direction == 2 and agent.y * 80 < 700)): game_ui.move() elif event.key == pg.K_SPACE: if env.field[agent.y][agent.x].mine: + env.mine_count -= 1 env.field[agent.y][agent.x] = factory.create_tile( IMAGES[env.field[agent.y][agent.x].number].parent ) @@ -55,9 +56,15 @@ def main(): # TODO # petla while dopóki env.mine_count != 0 # uwzglednienie czy bfs zwraca False i wtedy break + # for i in range(1): + pg.time.delay(50) path, actions = breadth_first_search(env.field, agent.x, agent.y, agent.direction) print(path, actions) + if not path: + print("CHUJA") + break for action in actions: + print(action) pg.event.post(pg.event.Event(pg.KEYDOWN, {'key': action})) pg.event.post(pg.event.Event(pg.KEYDOWN, {'key': pg.K_SPACE}))