def find_explosion(colors): """Find the explostions using the tile map and colors.""" for y in range(len(colors)): for x in range(len(colors[y])): if colors[y][x] == TileExplode: return(vec2_t(x, y)) return(vec2_t(-1, -1))
def find_player(colors): """FInd the player using the tile map and colors.""" for y in range(len(colors)): for x in range(len(colors[y])): if colors[y][x] == TilePlayer: return(vec2_t(x, y)) return(vec2_t(-1, -1))
def step(self, action, tilemap): """Docstring...""" player_pos = obj_finder.find_player(tilemap) self.data = [] # for y in range(player_pos.y - 1,player_pos.y + 2): # for x in range(player_pos.x + 1,player_pos.x + 3): # if obj_finder.get_tile(tilemap, x, y) == obj_finder.TileEmpty: # self.data.append(0) # elif obj_finder.get_tile(tilemap, x, y) == obj_finder.TileWall: # self.data.append(1) # else: # self.data.append(2) # 2 = obstacle / kill u. # self.data.append(int(float(player_pos.x) * (9.0 / 30.0))) # self.data.append(int(float(player_pos.y) * (9.0 / 10.0))) # Add proper data into array. for y in self.y_range: for x in self.x_range: tile = obj_finder.get_tile( tilemap, x + player_pos.x,y + player_pos.y ) if tile == obj_finder.TileEmpty: self.data.append( 0 ) elif tile == obj_finder.TileWall: self.data.append( 1 ) else: self.data.append( 2 ) reward = 0 done = False if tilemap[0][0] == obj_finder.StateDead: reward -= 10 done = True else: reward += 1 if obj_finder.find_explosion(tilemap).not_equal(vec2_t(-1, -1)): reward += 5 if action == 0: # reward += 1 pass elif action == 1: reward += 1 game.press_jump() elif action == 2: game.press_dash() return((self.calc_state(), reward, done))
def click_at(x, y): """Leftclick mouse at specified location.""" new_pos = local_to_global(vec2_t(x, y)) x = new_pos.x y = new_pos.y # win32api.SetCursorPos((x, y)) win32api.mouse_event( win32con.MOUSEEVENTF_MOVE | win32con.MOUSEEVENTF_ABSOLUTE, int(x / win32api.GetSystemMetrics(0) * 65535.0), int(y / win32api.GetSystemMetrics(1) * 65535.0)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) time.sleep(1.0 / 60.0) # This makes the buttons actually work. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def get_pixel(x, y): """Get the pixel at the location x, y.""" pos = local_to_global(vec2_t(x, y)) x = pos.x y = pos.y desktop_window = win32gui.GetDesktopWindow() window_dc = win32gui.GetWindowDC(desktop_window) color = int(win32gui.GetPixel(window_dc, x, y)) return (color_t( (color & 0xFF), # Red ((color >> 8) & 0xFF), # Green ((color >> 16) & 0xFF))) # Blue
def local_to_global(vec2): """Convert local coordinates to global coordinates.""" local_to_global.window_rect = get_window_info() x = vec2.x + local_to_global.window_rect.left y = vec2.y + local_to_global.window_rect.top return (vec2_t(x, y))