Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Add a test for v2 ttyrecs (read actions and states).
Browse files Browse the repository at this point in the history
This test did not exist previously, and was generated with this version
of nle.
  • Loading branch information
cdmatters committed May 9, 2022
1 parent a504774 commit 5362cfc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions nle/tests/nle.2734875.0.actions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
108 108 106 106 106 106 106 104 104 104 104 104 104 104 106 104 104 104 104 104 104 104 104 104 104 106 106 106 106 106 104 104 104 104 106 58 104 104 104 107 107 107 104 104 104 104 104 104 106 105 105 106 106 106 32 104 104 104 104 104 104 107 104 104 104 104 104 104 104 104 104 104 104 104 74 106 74 76 115 115 115 115 115 115 106 106 106 106 115 76 76 108 108 108 102 106 102 106 32 97 104 108 108 108 108 108 108 108 108 108 104 104 104 104 104 104 104 104 32 104 107 107 107 107 104 104 104 104 104 107 107 107 107 107 107 107 107 106 76 76 106 76 76 108 108 108 107 76 76 104
24 changes: 24 additions & 0 deletions nle/tests/nle.2734875.0.frame.150.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
It's solid stone.

----
.<.|
--------- .d.|
|.......- |...@
|.......| ####-------- #....|
|.....{.-## #-......|######-----
-.------- ####|.......#
# #|..._..|
#### #|......|
#### #--------
# #
--------|- ####`#
|......)..#)#######
|....$...|
|........|
|........
----------



Agent the Digger St:15 Dx:8 Co:13 In:16 Wi:16 Ch:7 Neutral S:47
Dlvl:1 $:7 HP:12(12) Pw:3(3) AC:9 Xp:1/10 T:91
Binary file added nle/tests/nle.2734875.0.ttyrec2.bz2
Binary file not shown.
29 changes: 29 additions & 0 deletions nle/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@
TTYREC_DECGRAPHICS = "2020-10-16.00_11_28.ttyrec.bz2"
TTYREC_DECGRAPHICS_FRAME_5 = "2020-10-16.00_11_28.frame.5.txt"

# Version 2 ttyrec
# This ttyrec uses DECGraphics (https://en.wikipedia.org/wiki/DEC_Special_Graphics)
TTYREC_NLE_V2 = "nle.2734875.0.ttyrec2.bz2"
TTYREC_NLE_V2_FRAME_150 = "nle.2734875.0.frame.150.txt"
TTYREC_NLE_V2_ACTIONS = "nle.2734875.0.actions.txt"

SEQ_LENGTH = 20
ROWS = 25
COLUMNS = 80

TTYREC_V1 = 1
TTYREC_V2 = 2


def getfilename(filename):
Expand Down Expand Up @@ -277,3 +284,25 @@ def test_dec_graphics(self):
actual = chars[5][row].tobytes().decode("utf-8").rstrip()
# print(actual)
assert actual == line.rstrip()

def test_nle_conversion(self):
seq_length = 150
COLUMNS = 120
converter = Converter(ROWS, COLUMNS, TTYREC_V2)

chars = np.zeros((seq_length, ROWS, COLUMNS), dtype=np.uint8)
colors = np.zeros((seq_length, ROWS, COLUMNS), dtype=np.int8)
cursors = np.zeros((seq_length, 2), dtype=np.int16)
actions = np.zeros((seq_length), dtype=np.uint8)
timestamps = np.zeros((seq_length,), dtype=np.int64)

converter.load_ttyrec(getfilename(TTYREC_NLE_V2))
assert converter.convert(chars, colors, cursors, timestamps, actions) == 0

with open(getfilename(TTYREC_NLE_V2_FRAME_150)) as f:
for row, line in enumerate(f):
actual = chars[-1][row].tobytes().decode("utf-8").rstrip()
assert actual == line.rstrip()

with open(getfilename(TTYREC_NLE_V2_ACTIONS)) as f:
assert " ".join("%i" % a for a in actions) == f.readlines()[0]

0 comments on commit 5362cfc

Please sign in to comment.