Skip to content

Commit

Permalink
Improve test_labels_buffer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Apr 17, 2022
1 parent e4fa810 commit 2b08d6d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/test_labels_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# This test can be run as Python script or via PyTest

def check_label(labels_buffer, label):
# Returns True if label seems to be ok
if label.width > 0 and label.height > 0:
assert label.value > 1
if label.width > 4 and label.height > 4: # Sometimes very tiny objects may be obscured by level geometry or not rendered due to sprite size
# Values decrease with the distance from the player,
# check for >= since objects with higher values (closer ones) can obscure objects with lower values (further ones).
detect_color = (labels_buffer >= label.value)
Expand All @@ -23,24 +23,33 @@ def test_labels_buffer():

game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
game.set_labels_buffer_enabled(True)
game.set_window_visible(False)
game.set_render_hud(False)
game.set_window_visible(False)
#game.set_mode(vzd.Mode.SPECTATOR) # For manual testing

game.init()

actions = [[True, False, False, False], [False, True, False, False],
[False, False, True, False], [False, False, False, True]]

game.new_episode()
state_count = 0
seen_labels = 0
seen_unique_objects = set()

while not game.is_episode_finished():
state = game.get_state()
labels_buffer = state.labels_buffer
game.make_action(choice(actions))

state_count += 1
seen_labels += len(state.labels)
for l in state.labels:
seen_unique_objects.add(l.object_name)
check_label(labels_buffer, l)
game.close()

print(f"Seen {seen_labels} labels with {len(seen_unique_objects)} unique objects in {state_count} states.")

if __name__ == '__main__':
test_labels_buffer()

0 comments on commit 2b08d6d

Please sign in to comment.