add basic console logging, fix rotating
This commit is contained in:
parent
995dd6860e
commit
90e11febc5
26
src/main.py
26
src/main.py
@ -12,23 +12,28 @@ def handle_keys(env, agent, game_ui, factory):
|
|||||||
for event in pg.fastevent.get():
|
for event in pg.fastevent.get():
|
||||||
if event.type == pg.KEYDOWN:
|
if event.type == pg.KEYDOWN:
|
||||||
if event.key == pg.K_d or event.key == pg.K_RIGHT:
|
if event.key == pg.K_d or event.key == pg.K_RIGHT:
|
||||||
game_ui.rotate(-1)
|
print('Turning right')
|
||||||
elif event.key == pg.K_a or event.key == pg.K_LEFT:
|
|
||||||
game_ui.rotate(1)
|
game_ui.rotate(1)
|
||||||
|
elif event.key == pg.K_a or event.key == pg.K_LEFT:
|
||||||
|
print('Turning left')
|
||||||
|
game_ui.rotate(-1)
|
||||||
elif (event.key == pg.K_w or event.key == pg.K_UP) \
|
elif (event.key == pg.K_w or event.key == pg.K_UP) \
|
||||||
and ((agent.direction == 1 and agent.x * 80 < 700)
|
and ((agent.direction == 1 and agent.x * 80 < 700)
|
||||||
or (agent.direction == 3 and agent.x * 80 > 5)
|
or (agent.direction == 3 and agent.x * 80 > 5)
|
||||||
or (agent.direction == 0 and agent.y * 80 > 0)
|
or (agent.direction == 0 and agent.y * 80 > 0)
|
||||||
or (agent.direction == 2 and agent.y * 80 < 700)):
|
or (agent.direction == 2 and agent.y * 80 < 700)):
|
||||||
|
print('Moving forward')
|
||||||
game_ui.move()
|
game_ui.move()
|
||||||
elif event.key == pg.K_SPACE:
|
elif event.key == pg.K_SPACE:
|
||||||
if env.field[agent.y][agent.x].mine:
|
if env.field[agent.y][agent.x].mine:
|
||||||
|
print('Defusing mine')
|
||||||
env.mine_count -= 1
|
env.mine_count -= 1
|
||||||
env.field[agent.y][agent.x] = factory.create_tile(
|
env.field[agent.y][agent.x] = factory.create_tile(
|
||||||
IMAGES[env.field[agent.y][agent.x].number].parent
|
IMAGES[env.field[agent.y][agent.x].number].parent
|
||||||
)
|
)
|
||||||
game_ui.update()
|
game_ui.update()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pg.init()
|
pg.init()
|
||||||
pg.display.set_caption('Super Saper')
|
pg.display.set_caption('Super Saper')
|
||||||
@ -44,13 +49,11 @@ def main():
|
|||||||
|
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
# TODO
|
|
||||||
# poprawić numeracje stron agenta by szło zgodnie z zegarem
|
|
||||||
# ruchy agenta:
|
# ruchy agenta:
|
||||||
# 1 - right -> 1
|
# 0 - up
|
||||||
# 0 - up -> 0
|
# 1 - right
|
||||||
# 3 - left -> 3
|
# 2 - down
|
||||||
# 2 - down -> 2
|
# 3 - left
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
for event in pg.fastevent.get():
|
for event in pg.fastevent.get():
|
||||||
@ -58,16 +61,21 @@ def main():
|
|||||||
running = False
|
running = False
|
||||||
elif event.type == pg.KEYDOWN:
|
elif event.type == pg.KEYDOWN:
|
||||||
if event.key == pg.K_t:
|
if event.key == pg.K_t:
|
||||||
|
print('Starting to clear the sector')
|
||||||
while env.mine_count:
|
while env.mine_count:
|
||||||
|
print('-'*20)
|
||||||
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)
|
|
||||||
if not path and not env.field[agent.y][agent.x].mine:
|
if not path and not env.field[agent.y][agent.x].mine:
|
||||||
|
print('Unable to find path, rocks are in the way')
|
||||||
break
|
break
|
||||||
|
print(f'Path{path}')
|
||||||
|
print(f'Actions:{actions}')
|
||||||
for action in actions:
|
for action in actions:
|
||||||
pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': action}))
|
pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': action}))
|
||||||
|
|
||||||
pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': pg.K_SPACE}))
|
pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': pg.K_SPACE}))
|
||||||
handle_keys(env, agent, game_ui, factory)
|
handle_keys(env, agent, game_ui, factory)
|
||||||
|
print('Sector clear')
|
||||||
else:
|
else:
|
||||||
pg.fastevent.post(event)
|
pg.fastevent.post(event)
|
||||||
handle_keys(env, agent, game_ui, factory)
|
handle_keys(env, agent, game_ui, factory)
|
||||||
|
Loading…
Reference in New Issue
Block a user