-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatari_util.py
242 lines (214 loc) · 5.71 KB
/
atari_util.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import matplotlib.pyplot as plt
cmap10 = plt.get_cmap('tab10')
cmap20 = plt.get_cmap('tab20')
def color_fade(x, factor=0.5):
if len(x) == 3:
r,g,b = x
a = 1.0
else:
r,g,b,a = x
r = (1*factor+(1-factor)*r)
g = (1*factor+(1-factor)*g)
b = (1*factor+(1-factor)*b)
return (r, g, b, a)
GAME_GENRE = {
'alien': "Maze",
'amidar': "Maze",
'assault': "Fixed shooter",
'asterix': "Action",
'asteroids': "Multidirectional shooter",
'atlantis': "Fixed shooter",
'bankheist': "Maze",
'battlezone': "First-person shooter",
'beamrider': "Fixed shooter",
'berzerk': "Multidirectional shooter",
'bowling': "Sports",
'boxing': "Sports",
'breakout': "Action",
'centipede': "Fixed shooter",
'choppercommand': "Scrolling shooter",
'crazyclimber': "Climbing",
'defender': "Scrolling shooter",
'demonattack': "Fixed shooter",
'doubledunk': "Sports",
'enduro': "Sports", # racing
'fishingderby': "Sports",
'freeway': "Action",
'frostbite': "Action",
'gopher': "Action", # genre is hard to clasifiy
'gravitar': "Multidirectional shooter",
'hero': "Action",
'icehockey': "Sports",
'jamesbond': "Scrolling shooter",
'kangaroo': "Platform",
'krull': "Action",
'kungfumaster': "Beat 'em up",
'montezumarevenge': "Platform",
'mspacman': "Maze",
'namethisgame': "Action",
'phoenix': "Fixed shooter",
'pitfall': "Platform",
'pong': "Sports",
'privateeye': "Action",
'qbert': "Action",
'riverraid': "Scrolling shooter",
'roadrunner': "Racing",
'robotank': "First-person shooter", # Wiki says Shoot 'em up, but it's clearly the same genre as battlezone.
'seaquest': "Shoot 'em up",
'skiing': "Sports",
'solaris': "Space combat simulator",
'spaceinvaders': "Shoot 'em up",
'stargunner': "Scrolling shooter",
'surround': "Action",
'tennis': "Sports",
'timepilot': "Multidirectional shooter",
'tutankham': "Maze", # action-adventure / maze-shooter
'upndown': "Racing",
'venture': "Action",
'videopinball': "Pinball",
'wizardofwor': "Maze",
'yarsrevenge': "Multidirectional shooter",
'zaxxon': "Scrolling shooter",
}
GENRE_COLOR = {
'Platform': cmap20(0),
'Maze': cmap20(1),
'Racing': cmap20(2),
'Sports': cmap20(3),
'Pinball': cmap20(4),
'Climbing': cmap20(5),
"Shoot 'em up": cmap20(6),
"Beat 'em up": cmap20(7),
'Fixed shooter': cmap20(8),
'Scrolling shooter': cmap20(9),
'First-person shooter': cmap20(10),
'Multidirectional shooter': cmap20(11),
'Space combat simulator': cmap20(12),
'Action': cmap20(13),
}
GENRE_TO_CATEGORY = {
'Platform': 'Maze',
'Maze': 'Maze',
'Racing': 'Sports',
'Sports': 'Sports',
'Pinball': 'Other',
'Climbing': 'Other',
"Shoot 'em up": 'Combat',
"Beat 'em up": 'Combat',
'Fixed shooter': 'Combat',
'Scrolling shooter': 'Combat',
'First-person shooter': 'Combat',
'Multidirectional shooter': 'Combat',
'Space combat simulator': 'Combat',
'Action': 'Action',
}
CATEGORY_COLOR = {
'Combat': cmap10(1),
'Action': cmap10(0),
'Sports': cmap10(2),
'Maze': cmap10(3),
'Other': cmap10(7), # gray
}
CATEGORY_HATCH = {
'Combat': "+++",
'Action': "|||",
'Sports': "---",
'Maze': "...",
'Other': "xxx",
}
# these are the names of the games in the standard 57-game ALE benchmark.
canonical_57 = [
"Alien",
"Amidar",
"Assault",
"Asterix",
"Asteroids",
"Atlantis",
"Bank Heist",
"Battle Zone",
"Beam Rider",
"Berzerk",
"Bowling",
"Boxing",
"Breakout",
"Centipede",
"Chopper Command",
"Crazy Climber",
"Defender",
"Demon Attack",
"Double Dunk",
"Enduro",
"Fishing Derby",
"Freeway",
"Frostbite",
"Gopher",
"Gravitar",
"Hero",
"Ice Hockey",
"James Bond",
"Kangaroo",
"Krull",
"Kung Fu Master",
"Montezuma Revenge",
"Ms Pacman",
"Name This Game",
"Phoenix",
"Pitfall",
"Pong",
"Private Eye",
"QBert",
"Riverraid",
"Road Runner",
"Robotank",
"Seaquest",
"Skiing",
"Solaris",
"Space Invaders",
"Star Gunner",
"Surround",
"Tennis",
"Time Pilot",
"Tutankham",
"Up n Down",
"Venture",
"Video Pinball",
"Wizard of Wor",
"Yars Revenge",
"Zaxxon"
]
printable_57 = canonical_57.copy()
canonical_57 = ["".join(x.split(" ")).lower() for x in canonical_57]
for k, v in CATEGORY_COLOR.items():
CATEGORY_COLOR[k] = color_fade(v, 0.33)
def clean_name(game):
"""
Converts from a print name to a lowercase no spaces name. E.g. "Space Invaders" -> "spaceinvaders"
"""
return "".join(c for c in game.lower() if c in "abcdefghijklmnopqrstuvwxyz")
def print_name(game):
"""
Converts from a clean name to a print. E.g. "spaceinvaders" -> "Space Invaders"
"""
game = clean_name(game) # standarsize input
for canonical in printable_57:
if clean_name(canonical) == game:
return canonical
return "Unknown"
def get_game_genre_color(game):
# look up the genre
genre = GAME_GENRE.get(clean_name(game), "none")
if genre in GENRE_COLOR:
return GENRE_COLOR[genre]
else:
print(f"no color for game {game} genre {genre}")
return (0.8, 0.8, 0.8)
def get_game_category_color(game):
# look up the genre
genre = GAME_GENRE.get(clean_name(game), "none")
category = GENRE_TO_CATEGORY[genre]
return CATEGORY_COLOR[category]
def get_game_category_hatch(game):
# look up the genre
genre = GAME_GENRE.get(clean_name(game), "none")
category = GENRE_TO_CATEGORY[genre]
return CATEGORY_HATCH[category]