Agent defuse mine under him
This commit is contained in:
parent
63645f3b24
commit
de75ae3122
@ -1,5 +1,6 @@
|
|||||||
import queue
|
import queue
|
||||||
from typing import List
|
from typing import List
|
||||||
|
import pygame as pg
|
||||||
|
|
||||||
from node import Node
|
from node import Node
|
||||||
from tile import Tile
|
from tile import Tile
|
||||||
@ -36,6 +37,7 @@ def successor(x: int, y: int, direction: int):
|
|||||||
|
|
||||||
|
|
||||||
def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, start_direction: int):
|
def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, start_direction: int):
|
||||||
|
pg.time.delay(50)
|
||||||
explored = [(start_x, start_y)]
|
explored = [(start_x, start_y)]
|
||||||
node_queue = queue.SimpleQueue()
|
node_queue = queue.SimpleQueue()
|
||||||
node_queue.put(Node(start_x, start_y, start_direction))
|
node_queue.put(Node(start_x, start_y, start_direction))
|
||||||
|
@ -57,12 +57,14 @@ def main():
|
|||||||
# petla while dopóki env.mine_count != 0
|
# petla while dopóki env.mine_count != 0
|
||||||
# uwzglednienie czy bfs zwraca False i wtedy break
|
# uwzglednienie czy bfs zwraca False i wtedy break
|
||||||
# for i in range(1):
|
# for i in range(1):
|
||||||
|
# while env.mine_count:
|
||||||
pg.time.delay(50)
|
pg.time.delay(50)
|
||||||
path, actions = breadth_first_search(env.field, agent.x, agent.y, agent.direction)
|
path, actions = breadth_first_search(env.field, agent.x, agent.y, agent.direction)
|
||||||
print(path, actions)
|
print(path, actions)
|
||||||
if not path:
|
if not path:
|
||||||
print("CHUJA")
|
if not env.field[agent.y][agent.x].mine:
|
||||||
break
|
print("CHUJA")
|
||||||
|
break
|
||||||
for action in actions:
|
for action in actions:
|
||||||
print(action)
|
print(action)
|
||||||
pg.event.post(pg.event.Event(pg.KEYDOWN, {'key': action}))
|
pg.event.post(pg.event.Event(pg.KEYDOWN, {'key': action}))
|
||||||
|
Loading…
Reference in New Issue
Block a user