def __init__(self, width=64, height=48, cpu_speed_ratio=0.6, players_speed_ratio = 0.4, ball_speed_ratio=0.75, MAX_SCORE=11): actions = { "up": K_w, "down": K_s } PyGameWrapper.__init__(self, width, height, actions=actions) # the %'s come from original values, wanted to keep same ratio when you # increase the resolution. self.ball_radius = percent_round_int(height, 0.03) self.cpu_speed_ratio = cpu_speed_ratio self.ball_speed_ratio = ball_speed_ratio self.players_speed_ratio = players_speed_ratio self.paddle_width = percent_round_int(width, 0.023) self.paddle_height = percent_round_int(height, 0.15) self.paddle_dist_to_wall = percent_round_int(width, 0.0625) self.MAX_SCORE = MAX_SCORE self.dy = 0.0 self.score_sum = 0.0 # need to deal with 11 on either side winning self.score_counts = { "agent": 0.0, "cpu": 0.0 }
def __init__(self, width=48, height=48, num_creeps=3): actions = {"up": K_w, "left": K_a, "right": K_d, "down": K_s} PyGameWrapper.__init__(self, width, height, actions=actions) self.BG_COLOR = (255, 255, 255) self.N_CREEPS = num_creeps self.CREEP_TYPES = ["GOOD", "BAD"] self.CREEP_COLORS = [(40, 140, 40), (150, 95, 95)] radius = percent_round_int(width, 0.047) self.CREEP_RADII = [radius, radius] self.CREEP_REWARD = [ self.rewards["positive"], self.rewards["negative"] ] self.CREEP_SPEED = 0.25 * width self.AGENT_COLOR = (60, 60, 140) self.AGENT_SPEED = 0.25 * width self.AGENT_RADIUS = radius self.AGENT_INIT_POS = (self.width / 2, self.height / 2) self.creep_counts = {"GOOD": 0, "BAD": 0} self.dx = 0 self.dy = 0 self.player = None self.creeps = None
def __init__(self, width=22, height=21, target_speed_ratio=1, players_speed_ratio=1, bullet_speed_ratio=1, MAX_STEPS=100): actions = {"up": K_UP, "down": K_DOWN, "shoot": K_SPACE} PyGameWrapper.__init__(self, width, height, actions=actions) # the %'s come from original values, wanted to keep same ratio when you # increase the resolution. self.bullet_width = 1 self.target_speed_ratio = target_speed_ratio self.bullet_speed_ratio = bullet_speed_ratio self.players_speed_ratio = players_speed_ratio self.player_width = 1 self.player_height = 1 self.player_dist_to_wall = 1 self.MAX_STEPS = MAX_STEPS self.n_steps = 0 self.dy = 0.0 self.score_sum = 0.0 # need to deal with 11 on either side winning self.score_counts = {"agent": 0.0}
def __init__(self, width, height, dt): # Action dictionary corresponding to WASD keys + a no-op actions = { "up": K_w, "left": K_a, "right": K_d, "down": K_s, "nop": None } PyGameWrapper.__init__(self, width, height, actions=actions) self.dx = 0 self.dy = 0 self.dt = dt self.ticks = 0 self.bodies = [] self.escapes = 0 """ AGENT AND SUN PROPERTIES """ self.AGENT_COLOR = (60, 60, 140) self.AGENT_SPEED = 0.03 self.AGENT_SIZE = 10 self.AGENT_INIT_POS = (width / 2, height / 2 + 200) self.AGENT_MASS = int(1) self.SUN_COLOR = (255, 60, 60) self.SUN_SPEED = 0 self.SUN_RADIUS = 20 self.SUN_INIT_POS = (width / 2, height / 2) self.SUN_MASS = int(332953000000) self.dist_to_sun = 200
def __init__(self, map_config=None): """ Parameters ---------- None #### map_config: dict Customization of the map read only """ self.map_config = map_config self.map_array = None if not map_config or not 'map_array' in map_config: self.height = 315 self.width = 300 else: self.map_array = map_config['map_array'] self.height = 15 * len(self.map_array) self.width = 15 * len(self.map_array[0]) actions = { "left": K_a, "right": K_d, "jump": K_SPACE, "up": K_w, "down": K_s } PyGameWrapper.__init__(self, self.width, self.height, actions=actions) # value of reward if not 'rewards' in map_config: self.rewards = { "positive": 5, "win": 50, "negative": -25, "tick": 0 } else: self.rewards = map_config['rewards'] self.allowed_fps = None self._dir = os.path.dirname(os.path.abspath(__file__)) self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right2.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left2.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) }
def __init__(self, width=84, height=84): PyGameWrapper.__init__(self, width, height, actions=self.actions) self.dx = 0. self.dy = 0. self.ticks = 0 self._game_ended = False
def __init__(self, width=128, height=128): actions = {"up": K_w, "left": K_a, "right": K_d, "down": K_s} self.keyup = False self.keydown = False self.keyright = False self.keyleft = False self.key = 0 self.keynum = 0 self.perepisode = 100 PyGameWrapper.__init__(self, width, height, actions=actions)
def __init__(self, mapname, experiment): """ Parameters ---------- None """ self.mapname = mapname self.experiment = experiment self.height = 230 #modify height accordingly based on how long the game level is self.width = 230 self.status = 2 actions = { "left": K_a, "right": K_d, "jump": K_SPACE, "up": K_w, "down": K_s } PyGameWrapper.__init__(self, self.width, self.height, actions=actions) self.rewards = { "positive": 1.0, "negative": -1.0, "tick": 0, "loss": -5.0, "win": 5.0 } # self.rewards = { # "positive": 0, # "win": 1, # "negative": 0, # "tick": 0 # } self.allowed_fps = 30 self._dir = os.path.dirname(os.path.abspath(__file__)) self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right2.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left2.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) }
def __init__(self): """ Parameters ---------- None """ self.height = 345 #modify height accordingly based on how long the game level is self.width = 345 self.status = 2 # (2 : still alive, 1 : win, 0: dead/lose) actions = { "left": K_LEFT, "right": K_RIGHT, "jump": K_UP, "up": K_UP, "down": K_DOWN, "undo": K_SPACE } PyGameWrapper.__init__(self, self.width, self.height, actions=actions) self.rewards = {"positive": 0, "win": 1, "negative": 0, "tick": 0} self.allowed_fps = 30 self._dir = os.path.dirname(os.path.abspath(__file__)) print(self._dir) self.datafile = open(self._dir + "\datafile.txt", "a") self.datafile.write( str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) + "- " * 30 + '\n') self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right1.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right1.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left1.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left1.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) } self.prev_position = []
def __init__(self, width=64, height=48, player1_speed_ratio=0.5, player2_speed_ratio=0.5, ball_speed_ratio=0.75, MAX_SCORE=11, player1_name='PLAYER 1', player2_name='PLAYER 2'): actions = { (None, None): 0, ('up', None): 1, ('down', None): 2, (None, 'up'): 3, ('up', 'up'): 4, ('down', 'up'): 5, (None, 'down'): 6, ('up', 'down'): 7, ('down', 'down'): 8, } PyGameWrapper.__init__(self, width, height, actions=actions) self.player1_name = player1_name self.player2_name = player2_name # the %'s come from original values, wanted to keep same ratio when you # increase the resolution. self.ball_radius = percent_round_int(height, 0.03) self.player1_speed_ratio = player1_speed_ratio self.player2_speed_ratio = player2_speed_ratio self.ball_speed_ratio = ball_speed_ratio self.paddle_width = percent_round_int(width, 0.023) self.paddle_height = percent_round_int(height, 0.15) self.paddle_dist_to_wall = percent_round_int(width, 0.0625) self.MAX_SCORE = MAX_SCORE self.player1_dy = 0.0 self.player2_dy = 0.0 self.score_sum = 0.0 # need to deal with 11 on either side winning self.score_counts = {"player1": 0.0, "player2": 0.0}
def __init__(self): """ Parameters ---------- None """ self.height = 465 self.width = 500 actions = { "left": K_a, "right": K_d, "jump": K_SPACE, "up": K_w, "down": K_s } PyGameWrapper.__init__( self, self.width, self.height, actions=actions) self.rewards = { "positive": 5, "win": 50, "negative": -25, "tick": 0 } self.allowed_fps = 30 self._dir = os.path.dirname(os.path.abspath(__file__)) self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right2.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left2.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) }
def __init__(self, mk_config: Union[MkConfig, Dict]): if isinstance(mk_config, dict): mk_config = MkConfig(**mk_config) self.mk_config: MkConfig = mk_config self.reward_type = None self.height = self.mk_config.MapHeightInTiles * 15 #modify height accordingly based on how long the game level is , for map_short it was 210*210, for short2 it was 270*270, for short3 it is 170*170 self.width = self.mk_config.MapWidthInTiles * 15 actions = { "left": K_a, "right": K_d, "jump": K_SPACE, "up": K_w, "down": K_s } PyGameWrapper.__init__( self, self.width, self.height, actions=actions) self.rewards = { "positive": 5, # original was 5 "win": self.mk_config.RewardsWin, "negative": 0, # original was -25 "tick": 0 } self.allowed_fps = 30 self._dir = os.path.dirname(os.path.abspath(__file__)) self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right2.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left2.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) } if not self.mk_config.IsRender: os.environ["SDL_VIDEODRIVER"] = "dummy"
def __init__(self): """ Parameters ---------- None """ self.height = 230 #modify height accordingly based on how long the game level is self.width = 230 self.status = 2 actions = { "left": K_LEFT, "right": K_RIGHT, "jump": K_UP, "up": K_UP, "down": K_DOWN } self.datafile = open(r"datafile.txt", "w") PyGameWrapper.__init__(self, self.width, self.height, actions=actions) self.rewards = {"positive": 0, "win": 1, "negative": 0, "tick": 0} self.allowed_fps = 30 self._dir = os.path.dirname(os.path.abspath(__file__)) self.IMAGES = { "right": pygame.image.load(os.path.join(self._dir, 'assets/right1.png')), "right2": pygame.image.load(os.path.join(self._dir, 'assets/right1.png')), "left": pygame.image.load(os.path.join(self._dir, 'assets/left1.png')), "left2": pygame.image.load(os.path.join(self._dir, 'assets/left1.png')), "still": pygame.image.load(os.path.join(self._dir, 'assets/still.png')) }
def __init__(self, width=60, height=60, paddle_speed_ratio=0.9, ball_speed_ratio=0.4): actions = { "left": K_LEFT, "right": K_RIGHT, } PyGameWrapper.__init__(self, width, height, actions=actions) self.paddle_speed_ratio = paddle_speed_ratio self.ball_speed_ratio = ball_speed_ratio self.ball_radius = percent_round_int(height, 0.02) self.paddle_width = percent_round_int(width, 0.15) self.paddle_height = percent_round_int(height, 0.04) self.num_block_per_row = 10 self.num_row = 6 self.num_blocks = self.num_block_per_row * self.num_row self.hit_points = 5 self.score = 0.0 self.dy = 0.0