Beispiel #1
0
    def __init__(self, width=64, height=64):

        actions = {"up": K_w, "left": K_a, "right": K_d, "down": K_s}

        base.Game.__init__(self, width, height, actions=actions)

        self.CREEP_BAD = {
            "radius_center": percent_round_int(width, 0.047),
            "radius_outer": percent_round_int(width, 0.265),
            "color_center": (110, 45, 45),
            "color_outer": (150, 95, 95),
            "speed": 0.05 * width
        }

        self.CREEP_GOOD = {
            "radius": percent_round_int(width, 0.047),
            "color": (40, 140, 40)
        }

        self.AGENT_COLOR = (60, 60, 140)
        self.AGENT_SPEED = 0.2 * width
        self.AGENT_RADIUS = percent_round_int(width, 0.047)
        self.AGENT_INIT_POS = (self.AGENT_RADIUS, self.AGENT_RADIUS)

        self.BG_COLOR = (255, 255, 255)
        self.dx = 0
        self.dy = 0
        self.ticks = 0
    def __init__(self, width=64, height=48, 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.players_speed = 0.22 * height
        self.cpu_speed = 0.7 * height
        self.ball_speed = 0.75 * height
        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=64,
        height=64):

        actions = {
            "up": K_w,
            "left": K_a,
            "right": K_d,
            "down": K_s
        }

        base.Game.__init__(self, width, height, actions=actions)

        self.CREEP_BAD = {
            "radius_center": percent_round_int(width, 0.047),
            "radius_outer": percent_round_int(width, 0.265),
            "color_center": (110, 45, 45),
            "color_outer": (150, 95, 95),
            "speed": 0.05*width
        }

        self.CREEP_GOOD = {
            "radius": percent_round_int(width, 0.047),
            "color": (40, 140, 40)
        }

        self.AGENT_COLOR = (60, 60, 140)
        self.AGENT_SPEED = 0.2*width 
        self.AGENT_RADIUS = percent_round_int(width, 0.047)
        self.AGENT_INIT_POS = (self.AGENT_RADIUS, self.AGENT_RADIUS)

        self.BG_COLOR = (255, 255, 255)
        self.dx = 0
        self.dy = 0
        self.ticks = 0
    def __init__(self,
                 width=64,
                 height=64,
                 init_length=3):

        actions = {
            "up": K_w,
            "left": K_a,
            "right": K_d,
            "down": K_s
        }

        base.PyGameWrapper.__init__(self, width, height, actions=actions)

        self.speed = percent_round_int(width, 0.45)

        self.player_width = percent_round_int(width, 0.05)
        self.food_width = percent_round_int(width, 0.09)
        self.player_color = (100, 255, 100)
        self.food_color = (255, 100, 100)

        self.INIT_POS = (width / 2, height / 2)
        self.init_length = init_length

        self.BG_COLOR = (25, 25, 25)
	def __init__(self, width=64, height=48, MAX_SCORE=11):

		actions = {
			"up": K_w,
			"down": K_s
		}

                base.Game.__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.players_speed = 0.022*height
                self.cpu_speed = 0.175 #has to be small because its pressed much faster than player
		self.ball_speed = 0.00075*height 
                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=64,
        height=64,
        init_length=3):

        actions = {
            "up": K_w,
            "left": K_a,
            "right": K_d,
            "down": K_s
        }

        base.Game.__init__(self, width, height, actions=actions)

        self.speed = percent_round_int(width, 0.45) 

        self.player_width = percent_round_int(width, 0.05)
        self.food_width = percent_round_int(width, 0.09)
        self.player_color = (100, 255, 100)
        self.food_color = (255, 100, 100)

        self.INIT_POS = (width/2, height/2)
        self.init_length = init_length

        self.BG_COLOR = (25, 25, 25)
Beispiel #7
0
    def __init__(self, width=64, height=64, init_lives=3):

        actions = {"left": K_a, "right": K_d}

        base.Game.__init__(self, width, height, actions=actions)

        self.fruit_size = percent_round_int(height, 0.06)
        self.fruit_fall_speed = 0.00095 * height

        self.player_speed = 0.021 * width
        self.paddle_width = percent_round_int(width, 0.2)
        self.paddle_height = percent_round_int(height, 0.04)

        self.dx = 0.0
        self.init_lives = init_lives
Beispiel #8
0
    def __init__(self, width=48, height=48, num_creeps=3):

        actions = {"up": K_w, "left": K_a, "right": K_d, "down": K_s}

        base.Game.__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=48,
        height=48,
        num_creeps=3):

        actions = {
            "up": K_w,
            "left": K_a,
            "right": K_d,
            "down": K_s
        }

        base.Game.__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 = [ 1, -3 ]
        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=64, height=64, init_lives=3):
        
        actions = {
                "left": K_a,
                "right": K_d
        }

        base.Game.__init__(self, width, height, actions=actions)

        self.fruit_size = percent_round_int(height, 0.06)
        self.fruit_fall_speed = 0.00095*height

        self.player_speed = 0.021*width
        self.paddle_width = percent_round_int(width, 0.2)
        self.paddle_height = percent_round_int(height, 0.04)

        self.dx = 0.0
        self.init_lives = init_lives
    def update_hitbox(self):
        # need to make a small rect pointing the direction the snake is
        # instead of counting the entire head square as a hit box, since
        # the head touchs the body on turns and causes game overs.

        x = self.head.pos.x
        y = self.head.pos.y

        if self.dir.x == 0:
            w = self.width
            h = percent_round_int(self.width, 0.25)

            if self.dir.y == 1:
                y += percent_round_int(self.width, 1.0)

            if self.dir.y == -1:
                y -= percent_round_int(self.width, 0.25)

        if self.dir.y == 0:
            w = percent_round_int(self.width, 0.25)
            h = self.width

            if self.dir.x == 1:
                x += percent_round_int(self.width, 1.0)

            if self.dir.x == -1:
                x -= percent_round_int(self.width, 0.25)

        if self.update_head:
            image = pygame.Surface((w, h))
            image.fill((0, 0, 0))
            image.set_colorkey((0, 0, 0))

            pygame.draw.rect(
                image,
                (255, 0, 0),
                (0, 0, w, h),
                0
            )

            self.head.image = image
            self.head.rect = self.head.image.get_rect()
            self.update_head = False

        self.head.rect.center = (x, y)
    def update_hitbox(self): 
        #need to make a small rect pointing the direction the snake is
        #instead of counting the entire head square as a hit box, since 
        #the head touchs the body on turns and causes game overs.

        x = self.head.pos.x
        y = self.head.pos.y

        if self.dir.x == 0:
            w = self.width
            h = percent_round_int(self.width, 0.25)
            
            if self.dir.y == 1:
                y += percent_round_int(self.width, 1.0)

            if self.dir.y == -1:
                y -= percent_round_int(self.width, 0.25)

        if self.dir.y == 0:
            w = percent_round_int(self.width, 0.25)
            h = self.width
            
            if self.dir.x == 1:
                x += percent_round_int(self.width, 1.0)

            if self.dir.x == -1:
                x -= percent_round_int(self.width, 0.25)

        if self.update_head:
            image = pygame.Surface((w, h))
            image.fill((0,0,0))
            image.set_colorkey((0,0,0))
            
            pygame.draw.rect(
                    image,
                    (255, 0, 0),
                    (0, 0, w, h),
                    0
            )

            self.head.image = image
            self.head.rect = self.head.image.get_rect()
            self.update_head = False

        self.head.rect.center = (x, y)