-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprolog_gui.py
More file actions
93 lines (79 loc) · 2.31 KB
/
prolog_gui.py
File metadata and controls
93 lines (79 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pygame
#import pygame.locals
#import gym - in the docker container the gym library is asked to be explicitly installed, after that it will interfere with the nle namespace and will not recognize it's gym's env's
import numpy as np
import janus_swi as janus
import interface
janus.consult('./main.pl',module='main')
global CLOCK
CLOCK = pygame.time.Clock
KEY_MAP = {
0: 'enter',
7: '[1]',
3: '[2]',
6: '[3]',
4: '[4]',
2: '[6]',
8: '[7]',
1: '[8]',
5: '[9]',
9: 'up',
10: 'down',
11: 'w',
12: 'o',
13: 'K',
14: 's',
15: 'e',
16: 'backspace',
17: 'i',
18: 'q',
19: '[+]'
}
# NLE ACTIONS FOR REFERENCE
# 0 MiscAction.MORE
# 1 CompassDirection.N
# 2 CompassDirection.E
# 3 CompassDirection.S
# 4 CompassDirection.W
# 5 CompassDirection.NE
# 6 CompassDirection.SE
# 7 CompassDirection.SW
# 8 CompassDirection.NW #this is also yes
# 9 MiscDirection.UP
# 10 MiscDirection.DOWN
# 11 MiscDirection.WAIT
# 12 Command.OPEN
# 13 Command.KICK
# 14 Command.SEARCH
# 15 Command.EAT
# 16 Command.ESC
# 17 Command.INVENTORY
# 18 Command.QUAFF
# 19 Command.PICKUP
#output text received from prolog
def output_text(text:str,var,game:interface.Game):
if type(var) != str:
text += str(var)
game.graphics.output_text(text)
else:
game.graphics.output_text(text + var)
#is currently printing to console
def display_inv(env):
inv_strs_index = env._observation_keys.index("inv_strs")
inv_letters_index = env._observation_keys.index("inv_letters")
inv_strs = env.last_observation[inv_strs_index]
inv_letters = env.last_observation[inv_letters_index]
for letter, line in zip(inv_letters, inv_strs):
if np.all(line == 0):
break
print(letter.tobytes().decode("utf-8"), line.tobytes().decode("utf-8"))
#step function that plays into the env and updates the graphic display (used by prolog)
def step(key,game:interface.Game):
#step_res = env.step(num)
#key_name = KEY_MAP[num]
is_game_over = game.prolog_move(key)
#game.graphics.update_graphics(env,0)
#memory leak susceptible. calling game over before terminating prolog will only terminate prolog after another game is either started or the game finishes
# if step_res == False:
# game.game_over()
return is_game_over