def setup_memory_addresses(): return { "fighting": Address('0x02011389', 'u8'), "winsP1": Address('0x02011383', 'u8'), "winsP2": Address('0x02011385', 'u8'), "healthP1": Address('0x02068D0A', 's16'), "healthP2": Address('0x020691A2', 's16') }
def run_read(output_pipe): addresses = { "test1": Address("0x00000000", "u8"), "test2": Address("0x00000001", "u16") } screen_dims = {"width": 1, "height": 1} data_pipe = DataPipe("env1", screen_dims, addresses, "../mame/pipes") write_pipe = setup_data_pipe(data_pipe) write_pipe.write("1+2+abc\n") write_pipe.flush() output_pipe.put(data_pipe.read_data())
def test_step(self): memory_addresses = {"test": Address("02000008", "u8")} game_id = "sfiii3n" emulator = None try: emulator = Emulator("testEnv1", game_id, memory_addresses) data = emulator.step([]) assert_that(data["frame"].shape, equal_to((224, 384, 3))) assert_that(data["test"], equal_to(0)) finally: emulator.close()
def test_screen_dimensions(self): memory_addresses = {"test": Address("02000008", "u8")} game_id = "sfiii3n" roms_path = "/home/michael/dev/MAMEToolkit/MAMEToolkit/emulator/mame/roms" emulator = None try: emulator = Emulator("testEnv1", roms_path, game_id, memory_addresses) assert_that(emulator.screenDims["width"], equal_to(384)) assert_that(emulator.screenDims["height"], equal_to(224)) finally: emulator.close()
def test_step(self): memory_addresses = {"test": Address("02000008", "u8")} game_id = "sfiii3n" roms_path = "/home/michael/dev/MAMEToolkit/MAMEToolkit/emulator/mame/roms" emulator = None try: emulator = Emulator("testEnv1", roms_path, game_id, memory_addresses) data = emulator.step([]) assert_that(data["frame"].shape, equal_to((224, 384, 3))) assert_that(data["test"], equal_to(0)) finally: emulator.close()
def test_lua_string(self): data_pipe, write_pipe = [None] * 2 try: addresses = { "test1": Address("0x00000000", "u8"), "test2": Address("0x00000001", "u16") } screen_dims = {"width": 1, "height": 1} data_pipe = DataPipe("env1", screen_dims, addresses, "../mame/pipes") write_pipe = setup_data_pipe(data_pipe) write_pipe.write("1+2+abc\n") write_pipe.flush() assert_that( data_pipe.get_lua_string(), equal_to( 'dataPipe:write(mem:read_u8(0x00000000).."+"..mem:read_u16(0x00000001).."+"..s:bitmap_binary().."\\n"); dataPipe:flush(); ' )) finally: close_pipes(data_pipe, write_pipe)
def test_multiprocessing(self): workers = 2 game_id = "sfiii3n" roms_path = "/home/michael/dev/MAMEToolkit/MAMEToolkit/emulator/mame/roms" memory_addresses = {"test": Address("02000008", "u8")} output_queue = Queue() processes = [Process(target=run_emulator, args=[f"testEnv{i}", roms_path, game_id, memory_addresses, output_queue]) for i in range(workers)] [process.start() for process in processes] sleep(14) [process.join(timeout=1) for process in processes] for i in range(workers): data = output_queue.get(timeout=0.1) assert_that(data["frame"].shape, equal_to((224, 384, 3))) assert_that(data["test"], equal_to(0))
def test_read_data(self): data_pipe, write_pipe = [None] * 2 try: addresses = { "test1": Address("0x00000000", "u8"), "test2": Address("0x00000001", "u16") } screen_dims = {"width": 1, "height": 1} data_pipe = DataPipe("env1", screen_dims, addresses, "../mame/pipes") write_pipe = setup_data_pipe(data_pipe) write_pipe.write("1+2+abc\n") write_pipe.flush() data = data_pipe.read_data() assert_that(len(data), is_(equal_to(3))) assert_that(data["frame"][0][0][0], is_(equal_to(97))) assert_that(data["frame"][0][0][1], is_(equal_to(98))) assert_that(data["frame"][0][0][2], is_(equal_to(99))) assert_that(data["test1"], is_(equal_to(1))) assert_that(data["test2"], is_(equal_to(2))) finally: close_pipes(data_pipe, write_pipe)
def test_lua_string(self): assert_that( Address('test', 'u8').get_lua_string(), equal_to('mem:read_u8(test)')) assert_that( Address('test', 'u16').get_lua_string(), equal_to('mem:read_u16(test)')) assert_that( Address('test', 'u32').get_lua_string(), equal_to('mem:read_u32(test)')) assert_that( Address('test', 's8').get_lua_string(), equal_to('mem:read_i8(test)')) assert_that( Address('test', 's16').get_lua_string(), equal_to('mem:read_i16(test)')) assert_that( Address('test', 's32').get_lua_string(), equal_to('mem:read_i32(test)'))
def setup_memory_addresses(): return { # Health values range from 0xA6 (decimal 166) to 0x00 during normal gameplay "healthP1": Address('0x01060A60', 's16'), "healthP2": Address('0x01061610', 's16'), # Stamina values for performing combos range from 0x30 to 0x00 during normal gameplay "turboP1": Address('0x01060A70', 's16'), "turboP2": Address('0x01061620', 's16'), # Consecutive round wins for each player, 2 round wins needed to win a stage "total_round_winsP1": Address('0x01062310', 'u8'), "total_round_winsP2": Address('0x01062320', 'u8'), # Round wins for each player for the current stage, 2 round wins needed to win a stage "current_round_winsP1": Address('0x01060A90', 'u8'), "current_round_winsP2": Address('0x01061640', 'u8'), # Time remaining ranges from decimal 99 to 00 during normal gameplay under the default settings "time_remaining_tens_digit": Address('0x0105F330', 'u8'), "time_remaining_ones_digit": Address('0x0105F340', 'u8'), # A flag value used for rendering some of the background of a stage during a fight # It is 1 during a stage, becomes 0 in between stages but remains 1 in-between rounds "fighting": Address('0x0105F350', 'u8') }
def test_invalid_lua_string(self): with self.assertRaises(Exception) as context: Address('test', 'INVALID').get_lua_string(), assert_that(str(context.exception), contains_string('Invalid address mode used'))