示例#1
0
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        self.game = game
        self.unit = unit
        self.debug = debug

        def distance_sqr(a, b):
            return (a.x - b.x) ** 2 + (a.y - b.y) ** 2
        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, self.game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(
                box.item, model.Item.Weapon), self.game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        target_pos = nearest_enemy.position

        action = self.RRT(unit.position, nearest_weapon.position)

        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(
                nearest_enemy.position.x - unit.position.x,
                nearest_enemy.position.y - unit.position.y)
        jump = target_pos.y > unit.position.y
        if target_pos.x > unit.position.x and self.game.level.tiles[int(unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and self.game.level.tiles[int(unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True

        debug.draw(model.CustomData.Log(f"{action}"))
        if action != None:
            return model.UnitAction(
                velocity=action[0],
                jump=action[1],
                jump_down=action[2],
                aim=aim,
                shoot=False,
                reload=False,
                swap_weapon=False,
                plant_mine=False)
        else:
            return model.UnitAction(
                velocity=0,
                jump=False,
                jump_down=False,
                aim=aim,
                shoot=False,
                reload=False,
                swap_weapon=False,
                plant_mine=False)
示例#2
0
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        print(nearest_enemy.position)
        target_pos = unit.position
        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
        target_pos.x, target_pos.y = self.findtarget(game, 29)

        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        jump = target_pos.y > unit.position.y and self.checkifjumpvalid(
            game, unit.position, target_pos)
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        elif target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x > unit.position.x and game.level.tiles[
                int(unit.position.x) + 1][int(unit.position.y -
                                              1)] == model.Tile.EMPTY:
            jump = True
        elif target_pos.x < unit.position.x and game.level.tiles[
                int(unit.position.x) - 1][int(unit.position.y -
                                              1)] == model.Tile.EMPTY:
            jump = True
        #print(unit.position)
        #self.findnodes(game)
        #self.findnodes_wall(game)
        #cspace=np.zeros([40,30],dtype=int)
        #cspace=self.createcspace(game,cspace,int(unit.position.x),int(unit.position.y))
        #for row in cspace:
        #for val in row:
        #print(val,end='')
        #print()
        return model.UnitAction(velocity=target_pos.x - unit.position.x,
                                jump=jump,
                                jump_down=False,
                                aim=aim,
                                shoot=True,
                                reload=False,
                                swap_weapon=False,
                                plant_mine=False)
示例#3
0
    def get_action(self, unit, game, debug):
        nearest_enemy, nearest_weapon, nearest_hpbox, nearest_mine, expected_enemy_pos = self.calc_objects(
            unit, game)

        target_pos, velocity = self.calc_move(unit, nearest_weapon,
                                              nearest_enemy, nearest_hpbox,
                                              nearest_mine)

        aim, los = self.calc_aim(nearest_enemy, unit, game)

        shoot = self.calc_shoot(los)

        jump = self.calc_jump(unit, game, target_pos)

        plant_mine = self.calc_plant_mine(unit, nearest_enemy, velocity)

        self.prev_enemy_pos = nearest_enemy.position

        return model.UnitAction(velocity=velocity,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=shoot,
                                reload=False,
                                swap_weapon=self.swap_weapon,
                                plant_mine=plant_mine and not shoot)
示例#4
0
 def do_nothing(self):
     self.shoot.can_shoot(self.actions_stack)
     self.shoot.who("nearest_enemy")
     return model.UnitAction(velocity=0,
                             jump=False,
                             jump_down=False,
                             aim=self.shoot.aim,
                             shoot=self.shoot.shoot,
                             reload=self.shoot.reload,
                             swap_weapon=self.swap,
                             plant_mine=self.plant)
示例#5
0
 def down(self):
     self.shoot.can_shoot(self.actions_stack)
     self.shoot.who("nearest_enemy")
     #pop action to execute
     self.which_unit()
     ac = self.pop()
     self.should_push_back(ac)
     return model.UnitAction(velocity=self.speed *
                             (ac[1].x - self.unit.position.x),
                             jump=False,
                             jump_down=True,
                             aim=self.shoot.aim,
                             shoot=self.shoot.shoot,
                             reload=self.shoot.reload,
                             swap_weapon=self.swap,
                             plant_mine=self.plant)
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        target_pos = unit.position
        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        jump = target_pos.y > unit.position.y
        print("target_pos.y", target_pos.y)
        print("unit_pos.y", unit.position.y)
        print("jump", jump)

        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        jump = True  #The unit all need JUMP
        return model.UnitAction(velocity=target_pos.x - unit.position.x,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=True,
                                reload=False,
                                swap_weapon=False,
                                plant_mine=False)
示例#7
0
    def get_action(self, unit, game, debug):
        nearest_enemy, nearest_weapon, nearest_hpbox, expected_enemy_pos = self.calc_objects(
            unit, game)

        target_pos = self.calc_move(unit, nearest_weapon, nearest_enemy,
                                    nearest_hpbox)

        aim, shoot = self.calc_aim(nearest_enemy, unit, game)

        jump = self.calc_jump()

        self.prev_enemy_pos = nearest_enemy.position

        return model.UnitAction(velocity=(target_pos.x - unit.position.x) * 10,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=shoot,
                                reload=False,
                                swap_weapon=False,
                                plant_mine=False)
示例#8
0
    def get_action(self, unit, game, debug):
        # Replace this code with your own

        if len(game.units) > 2:
            nearest_friend = max(
                filter(lambda u: u.player_id == unit.player_id, game.units),
                key=lambda u: distance_sqr(u.position, unit.position),
                default=None)
        else:
            nearest_friend = None

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)

        nearest_enemy2 = max(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)

        nearest_weapon = None
        if nearest_friend:
            if nearest_friend.id > unit.id:
                nearest_weapon = min(filter(
                    lambda box: isinstance(box.item, model.Item.Weapon) and box
                    .item.weapon_type != model.WeaponType.ROCKET_LAUNCHER,
                    game.loot_boxes),
                                     key=lambda box: distance_sqr(
                                         box.position, unit.position),
                                     default=None)
            else:
                nearest_weapon = min(filter(
                    lambda box: isinstance(box.item, model.Item.Weapon) and box
                    .item.weapon_type == model.WeaponType.ROCKET_LAUNCHER,
                    game.loot_boxes),
                                     key=lambda box: distance_sqr(
                                         box.position, unit.position),
                                     default=None)
        if not nearest_weapon:
            nearest_weapon = min(
                filter(lambda box: isinstance(box.item, model.Item.Weapon),
                       game.loot_boxes),
                key=lambda box: distance_sqr(box.position, unit.position),
                default=None)

        nearest_hp = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        nearest_hp2 = max(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        target_pos = unit.position
        if unit.health < 80 and nearest_hp:
            debug.draw(model.CustomData.Log("target: xp"))
            target_pos = nearest_hp.position
            if nearest_enemy:
                d1 = distance_sqr_u(unit, nearest_hp)
                d2 = distance_sqr_u(nearest_enemy, nearest_hp)
                if d2 < d1:
                    target_pos = nearest_hp2.position
                    debug.draw(model.CustomData.Log("target: xp2"))
        elif unit.weapon is None:
            debug.draw(model.CustomData.Log("target: initial weapon"))
            target_pos = nearest_weapon.position
        elif nearest_weapon and unit.weapon and unit.weapon.typ == model.WeaponType.ROCKET_LAUNCHER:
            debug.draw(model.CustomData.Log("target: weapon"))
            target_pos = nearest_weapon.position
        elif nearest_enemy:
            debug.draw(model.CustomData.Log("target: enemy"))
            target_pos = nearest_enemy.position

        pos = one_step_to(game, unit, target_pos)
        if pos:
            target_pos = pos

        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        debug.draw(model.CustomData.Log("Unit pos: {}".format(unit.position)))
        jump = target_pos.y > unit.position.y
        dx = target_pos.x - unit.position.x
        if dx > 0.5 and game.level.tiles[int(unit.position.x + 1)][int(
                unit.position.y)] == model.Tile.WALL:
            jump = True
        if dx < -0.5 and game.level.tiles[int(unit.position.x - 1)][int(
                unit.position.y)] == model.Tile.WALL:
            jump = True
        if nearest_enemy:
            dx = (nearest_enemy.position.x - unit.position.x -
                  math.copysign(1, target_pos.x - unit.position.x))
            print(dx)
            if abs(dx) < 1:
                jump = True
                if nearest_friend and nearest_friend.id < unit.id:
                    jump = False
        if nearest_friend and nearest_friend.id > unit.id:
            dx = (nearest_friend.position.x - unit.position.x -
                  math.copysign(1, target_pos.x - unit.position.x))
            dy = (nearest_friend.position.y - unit.position.y)
            if abs(dx) < 1.5 and abs(dy) < 1.5:
                jump = True

        shoot = True
        if nearest_friend:
            if nearest_enemy and on_fire_line(unit, nearest_enemy,
                                              nearest_friend, game):
                nearest_enemy = nearest_enemy2
                if nearest_enemy and on_fire_line(unit, nearest_enemy,
                                                  nearest_friend, game):
                    shoot = False
        else:
            if on_fire_line(unit, nearest_enemy, unit, game):
                nearest_enemy = nearest_enemy2
                if on_fire_line(unit, nearest_enemy, unit, game):
                    shoot = False

        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        direction = 1
        for u in game.units:
            if u.player_id != unit.player_id or True:
                if u.weapon and u.weapon.typ == model.WeaponType.ROCKET_LAUNCHER:
                    if distance_sqr(u.position, unit.position) < 150:
                        direction = -1
                        if nearest_friend and nearest_friend.id < unit.id:
                            direction = 1
                        break

        velocity = direction * 20 * (target_pos.x - unit.position.x)
        print('vel', velocity, random.randint(-10, 10) / 10)
        return model.UnitAction(
            velocity=direction * 20 * (target_pos.x - unit.position.x) +
            random.randint(-10, 10) / 10,
            jump=jump,
            jump_down=not jump,
            aim=aim,
            shoot=shoot,
            reload=False,
            swap_weapon=(unit.weapon
                         and (unit.weapon.typ
                              == model.WeaponType.ROCKET_LAUNCHER)),
            plant_mine=(nearest_friend and unit.health < 20))
示例#9
0
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x) ** 2 + (a.y - b.y) ** 2
        def help(approach):
            if(approach is not None and (unit.health>80 or nearest_health is None))and unit.weapon is not None:
            #debug.draw(model.CustomData.Log("Nearest bullet velocity: {}".format(nearest_bullet.velocity)))
            #debug.draw(model.CustomData.Log("Nearest bullet position: {}".format(nearest_bullet.position)))
            #debug.draw(model.CustomData.Log("Nearest bullet distance: {}".format(distance_sqr(nearest_bullet.position,unit.position))))
            
                if(distance_sqr(approach.position,unit.position)<25):
                    '''
                    ind=0
                    yind=0
                    #target_pos.x=unit.position.x+2*nearest_bullet.position.x//abs(nearest_bullet.position.x)
                    for i in range(nearest_bullet.position.x,50*(nearest_bullet.velocity.x),nearest_bullet.velocity.x//abs(nearest_bullet.velocity.x)):
                        ind=i
                        yind=nearest_bullet.y/nearest_bullet.x()
                        if(game.level.tiles[int(i)][int((nearest_enemy.position.y-unit.position.y)*(i-unit.position.x)/(nearest_enemy.position.x-unit.position.x)+unit.position.y)]==model.Tile.WALL):

                    '''
                    if(approach.velocity.x>0):
                        left=approach.velocity.y/approach.velocity.x*(unit.position.x-.9-approach.position.x)+approach.position.y
                        if(left-(unit.position.y+1.8)>0):
                            jump=False
                            
                        else:
                            #target_pos.y=32
                            '''
                            if(game.level.tiles[int(unit.position.x)][int(unit.position.y-3.8)] == model.Tile.EMPTY):
                                jump=False
                            else:
                            '''
                            jump=True
                        
                    else:
                        right=approach.velocity.y/approach.velocity.x*(unit.position.x+.9-approach.position.x)+approach.position.y
                        if(right-(unit.position.y+1.8)>0):
                            jump=False
                        else:
                            #target_pos.y=32
                            '''
                            if(game.level.tiles[int(unit.position.x )][int(unit.position.y-3.8)] == model.Tile.EMPTY):
                                jump=False
                            else:
                            '''
                            jump=True
                    if(approach.velocity.y<0):
                        up=((unit.position.y+1.8-approach.position.y)/(approach.velocity.y/approach.velocity.x)+approach.position.x)
                        if(abs(up-(unit.position.x-.9))>abs(up-(unit.position.x+.9))):
                            velocity=-50
                        else:
                            velocity=50
                    else:
                        down=((unit.position.y-approach.position.y)/(approach.velocity.y/approach.velocity.x)+approach.position.x)
                        if(abs(down-(unit.position.x-.9))>abs(down-(unit.position.x+.9))):
                            velocity=-50
                        else:
                            velocity=50
                    return jump,velocity
        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),key=lambda u: distance_sqr(u.position, unit.position),default=None)
        
        nearest_weapon = min(filter(lambda box: isinstance(box.item, model.Item.Weapon), game.loot_boxes),key=lambda box: distance_sqr(box.position, unit.position),default=None)
        nearest_health = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack), game.loot_boxes),key=lambda box: distance_sqr(box.position, unit.position),default=None)
        f = sorted(filter(lambda box: isinstance(box.item, model.Item.Weapon), game.loot_boxes),key=lambda box: distance_sqr(box.position, nearest_enemy.position),reverse=True)
        farthest_weapon=nearest_enemy
        for i in f:
            if(distance_sqr(unit.position,i.position)<=distance_sqr(i.position,nearest_enemy.position)):
                farthest_weapon=i
                break

        nearest_bullet=min(
            filter(lambda u: u.player_id != unit.player_id, game.bullets),key=lambda u: distance_sqr(u.position, unit.position),default=None)

        def approachingbullet():
            nearest=sorted(game.bullets,key=lambda u: distance_sqr(u.position, unit.position))
            for bull in nearest:
                vec2=model.Vec2Double(0, 0)
                vec2.x=unit.position.x-bull.position.x
                vec2.y=unit.position.y-bull.position.y
                if vec2.x*bull.velocity.x+vec2.y*bull.velocity.y>0:
                    return bull
            return None



        target_pos =model.Vec2Double(0, 0)
        target_pos.x=unit.position.x
        target_pos.y=unit.position.y 
        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        
        #debug.draw(model.CustomData.Log("unit pos: {}".format(unit.position)))
        #debug.draw(model.CustomData.Log("approaching bullet: {}".format(approachingbullet())))
        aim = model.Vec2Double(0, 0)
        reloadweapon=False
        shoot=True
        #jump=False
        swap=False
       
        plant=False
        
        
                
                
        trick=1
        #print('Walked_right=',unit.walked_right)
        #print('shoot=',unit.shoot)
        '''
        if(len(game.bullets)!=0):
            print(game.bullets[0].player_id)
        '''
        
        if unit.weapon is not None  and (nearest_health is None ):
            if(str(unit.weapon.typ)!='WeaponType.ROCKET_LAUNCHER' ):
                target_pos=farthest_weapon.position
                jump=True
            else:
                target_pos=nearest_enemy.position


        #print(unit.size)
        #gap=1
        
        if nearest_health is not None and unit.weapon is not None and  nearest_enemy.position.x-nearest_health.position.x!=0 and unit.health>=90:
            #print('bhai')
            target_pos=nearest_health.position
            trick=(nearest_enemy.position.x-nearest_health.position.x)//abs((nearest_enemy.position.x-nearest_health.position.x))
            if(unit.position.y!=target_pos.y):
                trick*=-1
            target_pos.x+=trick
        if(unit.health<90 and nearest_health is not None and unit.weapon is not None):
            #velocity=(target_pos.x - unit.position.x)
            target_pos=nearest_health.position
            #debug.draw(model.CustomData.Log("Health: {}".format(nearest_health.position)))            
        
        
        
            #print(nearest_weapon.item.weapon_type)
        
        if nearest_weapon is not None and unit.weapon is not None and (unit.health>80 or nearest_health is None):
            if (str(nearest_weapon.item.weapon_type)=='WeaponType.ROCKET_LAUNCHER' and str(unit.weapon.typ)!='WeaponType.ROCKET_LAUNCHER' ):
                target_pos=nearest_weapon.position
                swap=True
            elif(str(nearest_weapon.item.weapon_type)!='WeaponType.PISTOL' and str(unit.weapon.typ)=='WeaponType.PISTOL' ):
                target_pos=nearest_weapon.position
                swap=True

        if(unit.weapon is not None):
            if str(unit.weapon.typ)=='WeaponType.ROCKET_LAUNCHER'  and unit.health==100:
                target_pos=nearest_enemy.position

        flag=0
        
        mini=min(int(unit.position.x),int(nearest_enemy.position.x))
        maxi=max(int(unit.position.x),int(nearest_enemy.position.x))
        for i in range(mini+1,maxi):
            if(game.level.tiles[int(i)][int((nearest_enemy.position.y-unit.position.y)*(i-unit.position.x)/(nearest_enemy.position.x-unit.position.x)+unit.position.y)]==model.Tile.WALL):
                #print('wall')
                flag=1
                break
        if(flag==1):
            shoot=False
            reloadweapon=True
        #l=[i.player_id for i in game.units]
        #print(l)
        for i in game.units:
            if(i.player_id==unit.player_id and (unit.position.x!=i.position.x or unit.position.y!=i.position.y) and nearest_enemy.position.x!=unit.position.x):
                if(((nearest_enemy.position.y-unit.position.y)*(i.position.x-unit.position.x)/(nearest_enemy.position.x-unit.position.x)+unit.position.y)>=i.position.y and ((nearest_enemy.position.y-unit.position.y)*(i.position.x-unit.position.x)/(nearest_enemy.position.x-unit.position.x)+unit.position.y)<=i.position.y+2):
                    if(distance_sqr(unit.position,i.position)<distance_sqr(unit.position,nearest_enemy.position)):
                        shoot=False
                        debug.draw(model.CustomData.Log("Health{}".format(shoot)))
                        reloadweapon=True
            elif(i.player_id==unit.player_id and (unit.position.y!=i.position.y) and i.position.x==unit.position.x and nearest_enemy.position.x==unit.position.x):
                if(distance_sqr(unit.position,i.position)<distance_sqr(unit.position,nearest_enemy.position)):
                        shoot=False
                        debug.draw(model.CustomData.Log("Health{}".format(shoot)))
                        reloadweapon=True

        
        
        #print(target_pos)
        
        '''
        if nearest_enemy.weapon is not None and unit.weapon is not None:
            if str(nearest_enemy.weapon.typ)=='WeaponType.ROCKET_LAUNCHER' or str(unit.weapon.typ)=='WeaponType.ROCKET_LAUNCHER':
                if distance_sqr(nearest_enemy,unit)<5:
                    target_pos=(nearest_enemy.position+unit.position)%25  

        '''
        #print(game.level.tiles)
        jump = (target_pos.y != unit.position.y)
        velocity=(target_pos.x - unit.position.x)
        
        
        if target_pos.x > unit.position.x and game.level.tiles[int(unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        elif target_pos.x < unit.position.x and game.level.tiles[int(unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        elif(abs(velocity)<5):
            velocity=(velocity)*5
        if(abs(target_pos.x-unit.position.x)<=2 and target_pos.y+1<unit.position.y):
            jump=False
        
        if(velocity>0 ):
            for i in game.units:
                if((unit.position.x<i.position.x and unit.position.x+2>i.position.x )and ( abs(unit.position.y-i.position.y)<=3)):
                    if(game.level.tiles[int(i.position.x )][int(i.position.y-3.8)] == model.Tile.EMPTY):
                        debug.draw(model.CustomData.Log("jump"))
                        jump=True
                    
                    else:

                        jump=False
        else:
            for i in game.units:
                if((unit.position.x>i.position.x and unit.position.x-1.5<i.position.x )and abs(unit.position.y-i.position.y)<=3):
                    if(game.level.tiles[int(i.position.x )][int(i.position.y-3.8)] == model.Tile.EMPTY):
                        debug.draw(model.CustomData.Log("jump"))
                        jump=True
                
                    else:
                        jump=False

        #print(len(game.units))
        approach=approachingbullet()
        if approach is not None:
            if(help(approach) is not None):
                jump,velocity=help(approach)
                debug.draw(model.CustomData.Log("approach"))
        elif(nearest_bullet is not None):
            if(help(nearest_bullet) is not None):
                jump,velocity=help(nearest_bullet)
                debug.draw(model.CustomData.Log("NearestBullet"))
        

        debug.draw(model.CustomData.Log("Velocity: {}".format(velocity)))  
            
        
        
        
            
    

        #debug.draw(model.CustomData.Log("Target: {}".format(target_pos)))
        if nearest_enemy is not None:
            #if(nearest_enemy.walked_right==True):
            if velocity!=0:
                aim = model.Vec2Double(nearest_enemy.position.x- unit.position.x,nearest_enemy.position.y - unit.position.y)
                
            else:
                aim = model.Vec2Double(nearest_enemy.position.x- unit.position.x,nearest_enemy.position.y - unit.position.y)
        return model.UnitAction(
            velocity=velocity,
            jump=jump,
            jump_down=not jump,
            aim=aim,
            shoot=shoot,
            reload=reloadweapon,
            swap_weapon=swap,
            plant_mine=plant) 
示例#10
0
    def get_action(self, unit, game, debug):
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        # Find the nearest enemy unit
        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)

        # Find the best weapon: the nearest one
        best_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        # Calculate the position in the next tick
        if unit.weapon is None and best_weapon is not None:
            target_pos = best_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
        else:
            target_pos = unit.position
        '''
        if unit.weapon is None and best_weapon is not None:
            target_pos = best_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
        '''

        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))

        # Calculate the aiming direction
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        # Decide whether the unit should jump
        jump = target_pos.y > unit.position.y
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True

        # Decide whether the unit should shoot
        vector_len = (aim.x**2 + aim.y**2)**0.5
        unit_aim = model.Vec2Double(aim.x / vector_len, aim.y / vector_len)

        start_x = min(unit.position.x, nearest_enemy.position.x)
        end_x = max(unit.position.x, nearest_enemy.position.x)
        start_y = min(unit.position.y, nearest_enemy.position.y)
        end_y = max(unit.position.y, nearest_enemy.position.y)
        shoot = True

        cur_x, cur_y = unit.position.x, unit.position.y
        while start_x <= cur_x <= end_x and start_y <= cur_y <= end_y:
            if game.level.tiles[int(cur_x)][int(cur_y)] != model.Tile.EMPTY:
                shoot = False
                break
            else:
                cur_x += unit_aim.x
                cur_y += unit_aim.y

        unit_action = model.UnitAction(velocity=target_pos.x - unit.position.x,
                                       jump=jump,
                                       jump_down=not jump,
                                       aim=aim,
                                       shoot=shoot,
                                       reload=False,
                                       swap_weapon=False,
                                       plant_mine=False)

        return unit_action
示例#11
0
    def get_action(self, unit, game, debug):
        global max_health

        if unit.health > max_health:
            max_health = unit.health
        mine = False
        weapon_change = False
        shoot_e = True
        target_pos = unit.position

        # max_health = model.Properties.unit_max_health

        #   Determining nearest entities to pickup

        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        nearest_mine = min(
            filter(lambda box: isinstance(box.item, model.Item.Mine),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        nearest_health = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position

        if nearest_health is not None and unit.health <= max_health * 0.7:
            target_pos = nearest_health.position

        aim = model.Vec2Double(0, 0)

        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        if unit.weapon is not None and nearest_mine is not None:
            if distance_sqr(nearest_mine.position, unit.position) < 100:
                target_pos = nearest_mine.position

        if unit.weapon is not None and nearest_weapon is not None:
            if int(nearest_weapon.item.weapon_type) > int(unit.weapon.typ):
                target_pos = nearest_weapon.position
                weapon_change = True

        #   Steering

        vel, jump = self.rrt(unit.position, target_pos, unit, game)

        #   Basic properties

        if nearest_enemy is not None and unit.weapon is not None:
            if nearest_enemy.position.x < unit.position.x and model.game.tiles[
                    int(unit.position.x - 1),
                    int(unit.position.y)] == model.Tile.WALL:
                shoot_e = False
            elif nearest_enemy.position.x > unit.position.x and model.game.tiles[
                    int(unit.position.x + 1),
                    int(unit.position.y)] == model.Tile.WALL:
                shoot_e = False

        #   Printing entites

        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        debug.draw(
            model.CustomData.Log("Current pos: {}".format(unit.position)))
        debug.draw(
            model.CustomData.Log("Opponent position: {}".format(
                nearest_enemy.position)))

        return model.UnitAction(velocity=vel,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=shoot_e,
                                reload=False,
                                swap_weapon=weapon_change,
                                plant_mine=mine)
示例#12
0
    def get_action(self, unit, game, debug):

        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        def getNearestWeapon(weapon_name):
            nearest_weapon = min(
                filter(lambda box: isinstance(box.item, model.Item.Weapon),
                       game.loot_boxes),
                key=lambda box: distance_sqr(box.position, unit.position)
                if str(box).split('WeaponType.')[1].split(':')[
                    0] == weapon_name else len(game.level.tiles[0]) *
                2,  # если интересующее нас оружие, кладем его координату, иначе кладем координату заведомо проигрышную, ширина поля *
                default=None)
            return nearest_weapon

        def getNearestHealthPack():
            nearest_healthPack = min(
                filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                       game.loot_boxes),
                key=lambda box: distance_sqr(box.position, unit.position),
                default=None)
            return nearest_healthPack

        def getBooleanShoot():
            # заменить позицию на упрежденную точку, в которой будет персонаж, когда он будет с выстрелом на заданном расстоянии
            koords = list()
            tan = (max(nearest_enemy.position.y, unit.position.y) -
                   min(nearest_enemy.position.y, unit.position.y)) / (
                       max(nearest_enemy.position.x, unit.position.x) -
                       min(nearest_enemy.position.x, unit.position.x))
            debug.draw(model.CustomData.Log("tan: {0}".format(tan)))
            # for i in range(min(int(unit.position.x), int(nearest_enemy.position.x)), max(int(unit.position.x), int(nearest_enemy.position.x))):
            # 	koords.append([i, int(i * tan)])
            for i in range(
                    min(int(unit.position.x), int(nearest_enemy.position.x)),
                    max(int(unit.position.x), int(nearest_enemy.position.x))):
                # Кладем в массив пару: координата x и y
                koords.append([
                    i,
                    min(int(nearest_enemy.position.y), int(unit.position.y)) +
                    int(i * tan)
                ])

            result = False
            if len(koords) == 0:
                result = True
            else:
                try:
                    for koord in koords:
                        if game.level.tiles[koord[0]][
                                koord[1]] == model.Tile.WALL:
                            result = False
                            break
                    else:
                        result = True
                except:
                    result = True

            return result

        # Текущая целевая точка
        self.target_pos = unit.position

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)

        nearest_weapon = getNearestWeapon(self.best_weapon[self.index % 3])
        nearest_healthPack = getNearestHealthPack()
        self.target_pos = nearest_weapon.position

        # Если подобрано лучшее оружее, то больше пушки не меняем
        if (unit.weapon and str(unit.weapon.typ) == 'WeaponType.' +
                self.best_weapon[self.index % 3]) or self.shoot:
            self.swap_weapon = False
            self.target_pos = nearest_weapon.position

        # Если пушка подобрана, то определяем, стрелять или нет
        if unit.weapon:

            if self.target_pos.y > unit.position.y:
                if self.target_pos.x > unit.position.x and game.level.tiles[
                        int(unit.position.x + 1)][int(
                            unit.position.y + 1
                        )] != model.Tile.WALL and game.level.tiles[int(
                            unit.position.x + 1)][int(
                                unit.position.y
                            )] != model.Tile.WALL and game.level.tiles[int(
                                unit.position.x
                            )][int(
                                unit.position.y +
                                1)] != model.Tile.WALL and game.level.tiles[
                                    int(unit.position.x - 1)][int(
                                        unit.position.y)] != model.Tile.WALL:
                    self.shoot = getBooleanShoot()
                elif self.target_pos.x < unit.position.x and game.level.tiles[
                        int(unit.position.x - 1)][int(
                            unit.position.y + 1
                        )] != model.Tile.WALL and game.level.tiles[int(
                            unit.position.x - 1)][int(
                                unit.position.y
                            )] != model.Tile.WALL and game.level.tiles[int(
                                unit.position.x
                            )][int(
                                unit.position.y +
                                1)] != model.Tile.WALL and game.level.tiles[
                                    int(unit.position.x + 1)][int(
                                        unit.position.y)] != model.Tile.WALL:
                    self.shoot = getBooleanShoot()
            else:
                if self.target_pos.x > unit.position.x and game.level.tiles[
                        int(unit.position.x + 1)][int(
                            unit.position.y - 1
                        )] != model.Tile.WALL and game.level.tiles[int(
                            unit.position.x + 1)][int(
                                unit.position.y
                            )] != model.Tile.WALL and game.level.tiles[int(
                                unit.position.x)][int(
                                    unit.position.y
                                )] != model.Tile.WALL and game.level.tiles[int(
                                    unit.position.x)][int(
                                        unit.position.y -
                                        1
                                    )] != model.Tile.WALL and game.level.tiles[
                                        int(unit.position.x -
                                            1)][int(unit.position.y -
                                                    1)] != model.Tile.WALL:
                    self.shoot = getBooleanShoot()
                elif self.target_pos.x < unit.position.x and game.level.tiles[
                        int(unit.position.x - 1)][int(
                            unit.position.y - 1
                        )] != model.Tile.WALL and game.level.tiles[int(
                            unit.position.x - 1)][int(
                                unit.position.y
                            )] != model.Tile.WALL and game.level.tiles[int(
                                unit.position.x)][int(
                                    unit.position.y
                                )] != model.Tile.WALL and game.level.tiles[int(
                                    unit.position.x)][int(
                                        unit.position.y -
                                        1
                                    )] != model.Tile.WALL and game.level.tiles[
                                        int(unit.position.x +
                                            1)][int(unit.position.y -
                                                    1)] != model.Tile.WALL:
                    self.shoot = getBooleanShoot()
            if int(
                    math.sqrt(
                        distance_sqr(unit.position,
                                     nearest_enemy.position))) < 1:
                self.shoot = True
            debug.draw(model.CustomData.Log("Shoot: {0}".format(self.shoot)))

            if (self.shoot and unit.health == game.properties.unit_max_health
                ) or (self.shoot
                      and unit.health < game.properties.unit_max_health
                      and not nearest_healthPack):
                self.target_pos = unit.position
                self.jump = False
                self.jump_down = False
            else:
                self.target_pos = nearest_enemy.position

        else:
            self.target_pos = nearest_weapon.position

        # Если уровень здоровья не 100%, бежим к ближайшей аптечке
        if unit.health < game.properties.unit_max_health and not unit.weapon:
            try:
                self.target_pos = nearest_healthPack.position
            except:
                self.target_pos = nearest_weapon.position
        elif unit.health < game.properties.unit_max_health and unit.weapon:
            try:
                self.target_pos = nearest_healthPack.position
            except:
                self.target_pos = nearest_enemy.position

        # Если цель выше нас или на одном уровне с нами, то прыгаем
        # self.jump = self.target_pos.y >= unit.position.y
        # Так же прыгаем, если тайл мешает пройти
        if self.target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            self.jump = True
            self.jump_down = False
        if self.target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            self.jump = True
            self.jump_down = False

        if int(self.target_pos.x) == int(unit.position.x) and int(
                self.target_pos.y) < int(unit.position.y):
            self.jump = False
            self.jump_down = True

        # Если противник мешает пройти, пытаемся его перепрыгнуть
        if self.target_pos != nearest_enemy.position and math.fabs(
                nearest_enemy.position.x - unit.position.x) < 1:
            self.jump = True
            self.jump_down = True

        # if self.boo:
        # 	print(unit.health)
        # 	self.boo = False
        # Стараемся держаться на "безопасном расстоянии от врага"
        if self.target_pos == unit.position and nearest_enemy.position.x < unit.position.x:
            self.target_pos.x = self.target_pos.x + 5
        elif self.target_pos == unit.position and nearest_enemy.position.x > unit.position.x:
            self.target_pos.x = self.target_pos.x - 5

        debug.draw(
            model.CustomData.Log("Speed: {0}".format(
                math.fabs(int((self.target_pos.x - unit.position.x))) *
                game.properties.unit_max_horizontal_speed)))
        debug.draw(
            model.CustomData.Log("Target: {0}:{1}".format(
                int(self.target_pos.x - unit.position.x),
                int(self.target_pos.y - unit.position.y))))

        # Прицеливание бота
        # if self.boo:

        # 	# main()
        # 	self.boo = False

        aim = model.Vec2Double(0, 0)

        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        # # Если цель выше нас или на одном уровне с нами, то прыгаем
        # self.jump = self.target_pos.y >= unit.position.y
        # # Так же прыгаем, если тайл мешает пройти
        # if self.target_pos.x > unit.position.x and game.level.tiles[int(unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
        # 	self.jump = True
        # if self.target_pos.x < unit.position.x and game.level.tiles[int(unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
        # 	self.jump = True

        return model.UnitAction(
            # velocity = (self.target_pos.x - unit.position.x) * game.properties.unit_max_horizontal_speed,
            velocity=(self.target_pos.x - unit.position.x) *
            game.properties.unit_max_horizontal_speed,
            jump=self.jump,
            jump_down=self.jump_down,
            aim=aim,
            shoot=self.shoot,
            swap_weapon=self.swap_weapon,
            plant_mine=False)
示例#13
0
    def get_action(self, unit, game, debug):
        global max_health
        global flag
        global prev_x

        #   Declaration of constants

        mine = False
        weapon_change = False
        shoot_e = True
        target_pos = unit.position
        if unit.health > max_health:
            max_health = unit.health

        #   Determining nearest entities to pickup

        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        nearest_mine = min(
            filter(lambda box: isinstance(box.item, model.Item.Mine),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        nearest_health = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        #   Deciding target

        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position

        if nearest_health is not None and unit.health <= max_health * 0.7:
            target_pos = nearest_health.position

        print(int(nearest_weapon.item.weapon_type))

        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        debug.draw(
            model.CustomData.Log("Current pos: {}".format(unit.position)))
        debug.draw(
            model.CustomData.Log("Opponent position: {}".format(
                nearest_enemy.position)))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        if unit.weapon is not None and nearest_mine is not None:
            if distance_sqr(nearest_mine.position, unit.position) < 100:
                target_pos = nearest_mine.position

        if unit.weapon is not None and nearest_weapon is not None:
            if int(nearest_weapon.item.weapon_type) > int(unit.weapon.typ):
                target_pos = nearest_weapon.position
                weapon_change = True

        jump = target_pos.y > unit.position.y

        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            if unit.weapon is not None and unit.weapon.last_angle > 0:
                print(unit.weapon.last_angle)
                shoot_e = False
            jump = True

        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            if unit.weapon is not None and unit.weapon.last_angle > 0:
                shoot_e = False
            jump = True

        vel = target_pos.x - unit.position.x

        # if unit.weapon is not None and unit.weapon.last_angle is not None:
        #     if unit.weapon.last_angle < 0 and game.level.tiles[int(unit.position.x)][int(unit.position.y-1)] == model.Tile.WALL:
        #         if unit.position.x < nearest_enemy.position.x and game.level.tiles[int(unit.position.x-1)][int(unit.position.y-1)] == model.Tile.WALL:
        #             shoot_e = False
        #         elif unit.position.x > nearest_enemy.position.x and game.level.tiles[int(unit.position.x+1)][int(unit.position.y-1)] == model.Tile.WALL:
        #             shoot_e = False

        isRetracing = False
        if distance_sqr(unit.position, nearest_enemy.position) < 9:
            flag = 1

        if flag:
            isRetracing = True
            vel = vel * (-1)
            if abs(vel) < 2:
                vel = vel * 10

        if unit.mines is not None and isRetracing:
            mine = True

        if flag and distance_sqr(unit.position, nearest_enemy.position) > 64:
            flag = 0

        # print("{}   {}   {}".format(unit.jump_state.max_time, unit.jump_state.speed, unit.jump_state.max_time * unit.jump_state.speed))

        if unit.jump_state.max_time > 0 and unit.jump_state.max_time == 5.5:
            max_height = unit.jump_state.max_time * unit.jump_state.speed
            for i in range(int(max_height)):
                if unit.position.y + i < 28 and game.level.tiles[int(
                        unit.position.x)][int(unit.position.y +
                                              i)] == model.Tile.WALL:
                    print("%%%%%%%%%%%%%%%%%%%%%%%%")
                    target_pos.x = random.randint(
                        int(unit.position.x) - 20,
                        int(unit.position.x) + 20)
                    target_pos.y = unit.position.y

        if target_pos.y > unit.jump_state.max_time * unit.jump_state.speed:
            print("*****************")
            jump = True
            if vel < 0 and game.level.tiles[int(unit.position.x - 1)][int(
                    unit.position.y)] == model.Tile.WALL:
                target_pos.x = random.randint(int(unit.position.x),
                                              int(unit.position.x) + 20)
            if vel > 0 and game.level.tiles[int(unit.position.x + 1)][int(
                    unit.position.y)] == model.Tile.WALL:
                target_pos.x = random.randint(
                    int(unit.position.x) - 20, int(unit.position.x))
            else:
                target_pos.x = random.randint(
                    int(unit.position.x) - 20,
                    int(unit.position.x) + 20)
            target_pos.y = unit.position.y

        return model.UnitAction(velocity=vel,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=shoot_e,
                                reload=False,
                                swap_weapon=weapon_change,
                                plant_mine=mine)
示例#14
0
文件: strat.py 项目: NehaDalmia/raic
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        def distance_sqr(a, b, c):
            return (a.x - b)**2 + (a.y - c)**2

        target_pos = unit.position
        nearest_enemy = min(filter(lambda u: u.player_id != unit.player_id,
                                   game.units),
                            key=lambda u: distance_sqr(
                                u.position, unit.position.x, unit.position.y),
                            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position.x, unit.
                                         position.y),
            default=None)
        jump = target_pos.y > unit.position.y and self.checkifjumpvalid(
            game, unit.position, target_pos)
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        nearest_weapon.position.x, nearest_weapon.position.y = self.findtarget(
            game, 29)
        if (unit.position.y >= nearest_weapon.position.y):
            target_pos = unit.position
            jump = False
            return model.UnitAction(velocity=target_pos.x - unit.position.x,
                                    jump=jump,
                                    jump_down=False,
                                    aim=aim,
                                    shoot=True,
                                    reload=False,
                                    swap_weapon=False,
                                    plant_mine=False)
        """for t in range(2,5):
        	if unit.position.y+t<28:
        		if (game.level.tiles[int (unit.position.x)][int (unit.position.y+t)]==model.Tile.WALL or game.level.tiles[int (unit.position.x+0.1)][int (unit.position.y+t)]==model.Tile.WALL or game.level.tiles[int (unit.position.x-1)][int (unit.position.y+t)]==model.Tile.WALL)and game.level.tiles[int (unit.position.x)][int (unit.position.y-1)]!=model.Tile.EMPTY  :
        		

        			nearest_weapon.position.x=unit.position.x-2
        			nearest_weapon.position.y
        			target_pos=nearest_weapon.position
        			print("strt")
        			return model.UnitAction(
            		velocity=target_pos.x - unit.position.x,
            		jump=jump,
            		jump_down=False,
            		aim=aim,
            		shoot=True,
            		reload=False,
            		swap_weapon=False,
            		plant_mine=False)"""

        k = 0
        #print(unit.position)
        arrx = [[]]
        arry = []
        arrx = self.findnodes(game, arrx, arry)
        print(arrx)
        print("\n\n\n\n\n\n")
        mini = 1000000
        k = 0
        flag = 1
        for i in arrx:
            if flag == 1:

                if (i[1] > unit.position.y or i[1] > unit.position.y + 0.005
                    ) and i[1] - unit.position.y <= 12:

                    for j in arrx:
                        #if(j[1]>i[1]):
                        #break
                        """print(j[0],"   ",j[1])
        				print(game.level.tiles[int (unit.position.x)][j[1]-1]==model.Tile.WALL or game.level.tiles[int (unit.position.x+0.3)][j[1]-1]==model.Tile.WALL)
        				print("C1=",float (-0.2)<(j[0]-unit.position.x)<float (0.2))
        				print("C2=",int (j[1])!=int (unit.position.y))"""
                        #if( float (-0.2)<(j[0]-unit.position.x)<float (0.2) and int (j[1])!=int (unit.position.y) and (game.level.tiles[int (unit.position.x)][j[1]-1]==model.Tile.WALL or game.level.tiles[int (unit.position.x+0.3)][j[1]-1]==model.Tile.WALL)):

                        #continue
                        if distance_sqr(
                                unit.position, j[0], j[1]
                        ) < mini and j[1] == i[1] and self.checkifjumpvalid(
                                game, unit.position, target_pos):
                            #print(self.checkifjumpvalid(game,unit.position,target_pos))
                            mini = distance_sqr(unit.position, j[0], j[1])
                            nearest_weapon.position.x = j[0]
                            nearest_weapon.position.y = j[1]
                    break
        target_pos = nearest_weapon.position
        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        debug.draw(model.CustomData.Log("Unit pos: {}".format(unit.position)))
        target_pos = nearest_weapon.position
        mini = 100000
        minx = -1
        miny = -1
        jumptest = 0
        for z in range(0, 39):
            if game.level.tiles[z][int(
                    unit.position.y
            )] == model.Tile.LADDER and game.level.tiles[z][int(
                    unit.position.y + 2)] != model.Tile.LADDER:
                print("No ladder")
                break
            elif game.level.tiles[z][int(
                    unit.position.y)] == model.Tile.LADDER:
                print("Ladder")
                if distance_sqr(unit.position, z, unit.position.y) < mini:
                    mini = distance_sqr(unit.position, z, unit.position.y)
                    minx = z
                    miny = unit.position.y
        if (mini != 100000):
            if self.checkwall(game, int(z), int(unit.position.x),
                              int(unit.position.y + 1)) == 0:

                print("Ladder")

                nearest_weapon.position.x = (minx + 0.5) if (
                    minx > unit.position.x) else (minx)
                nearest_weapon.position.y = miny + 2
                target_pos = nearest_weapon.position
                if (-0.1 < target_pos.x - unit.position.x < 0.1):

                    jumptest = 1
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        jump = target_pos.y > unit.position.y and self.checkifjumpvalid(
            game, unit.position, target_pos)
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        elif target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y -
                                          1)] == model.Tile.EMPTY:
            jump = True
        elif target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y -
                                          1)] == model.Tile.EMPTY:
            jump = True
        if (jumptest == 1):
            jump = True

        return model.UnitAction(velocity=(target_pos.x - unit.position.x),
                                jump=jump,
                                jump_down=False,
                                aim=aim,
                                shoot=True,
                                reload=False,
                                swap_weapon=False,
                                plant_mine=False)
示例#15
0
    def get_action(self, unit, game, debug):

        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        nearest_health = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        target_pos = unit.position

        #Verifica se ja esta com
        #Alguma arma, se não tiver
        #Ira em direção a arma
        #Se ja tiver uma arma, ira em direção
        #Ao Inimigo
        procurando_inimigo = False

        desviar_de_bullet = False

        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif unit.health < 90 and nearest_health is not None:
            target_pos = nearest_health.position

            #Se tiver outro pacote mais perto de mim
            #do que do inimigo, ira atraz dele

            #Pega o Objeto inimigo
            for j in game.units:
                if unit.id != j.id:
                    inimigo = j
            print("BEGIN FOR")
            health_mais_perto_de_mim = []
            #Itera em todos os pacotes
            for i in game.loot_boxes:
                #Se o pacote for de vida
                if isinstance(i.item, model.Item.HealthPack):
                    #print("loots.item:" , i)

                    #To mais perto que o inimigo
                    #Da vida
                    if distance_sqr(i.position, unit.position) < distance_sqr(
                            i.position, inimigo.position):
                        health_mais_perto_de_mim.append(i)

            print("TODOS PERTO DE MIM:", health_mais_perto_de_mim)
            if len(health_mais_perto_de_mim) > 0:
                target_pos = min(health_mais_perto_de_mim,
                                 key=lambda h_m_p_de_m: distance_sqr(
                                     h_m_p_de_m.position, unit.position),
                                 default=None).position
                #target_pos = health_mais_perto_de_mim[0].position
            print("MAIS PERTO DE MIM:", target_pos)

        #############3#elif unit.weapon is not None and unit.weapon.typ == 2:
        elif unit.weapon is not None and unit.weapon.typ == 0 or unit.weapon.typ == 1:
            if nearest_weapon is not None:
                target_pos = nearest_weapon.position

        elif len(game.bullets) > 0:
            #Pega o Objeto inimigo
            for j in game.units:
                if unit.id != j.id:
                    inimigo = j
            lista_bullet_inimigo = list(
                filter(lambda bull: (bull.unit_id == inimigo.id),
                       game.bullets))
            for i in lista_bullet_inimigo:
                print("INIMIGO BULLET:", i)

            if len(lista_bullet_inimigo):
                #nearest_bullet = min( game.bullets, key=lambda bull: distance_sqr(bull.position, unit.position) )
                nearest_bullet = min(lista_bullet_inimigo,
                                     key=lambda bull: distance_sqr(
                                         bull.position, unit.position))
                print("ALL BULLETS:", game.bullets)
                print("MIN BULLETS:", nearest_bullet)
                target_pos = nearest_bullet.position
                desviar_de_bullet = True

        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
            procurando_inimigo = True

        print("POS:", target_pos)

        debug.draw(model.CustomData.Log("Txarget pos: {}".format(target_pos)))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        #print("AIM:", aim)
        print("unit.position.x:", unit.position.x)
        print("unit.position.y:", unit.position.y)

        jump = target_pos.y > unit.position.y
        #Caso chegue em uma parede, ele pula
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True

        #posição do alvo maior que a posição minha atual
        shooting_command = True

        if nearest_enemy.position.x > unit.position.x:
            for i in range(int(unit.position.x), int(nearest_enemy.position.x),
                           1):
                if game.level.tiles[i][int(
                        unit.position.y)] == model.Tile.WALL:
                    shooting_command = False
                    print("NOOO SHOOTING MAN")
                    break

        elif nearest_enemy.position.x < unit.position.x:
            for i in range(int(nearest_enemy.position.x), int(unit.position.x),
                           1):
                if game.level.tiles[i][int(
                        unit.position.y)] == model.Tile.WALL:
                    shooting_command = False
                    print("NO NO NO NO SHOOTING MAN")
                    break

        #Troca de Arma
        #Se tiver com uma ROCKET_LAUNCHER troca, por qualquer outra
        troca_arma = MyStrategy.troca_arma(unit)

        velocidade_deslocamento = MyStrategy.aumentar_velocidade(
            target_pos.x - unit.position.x)

        if desviar_de_bullet == True:
            velocidade_deslocamento *= -1
            jump = not jump

        jump_down = not jump
        skill_plat_form = MyStrategy.skill_up_platform(unit, target_pos, game,
                                                       jump)
        if skill_plat_form == True:
            jump = False
            jump_down = False

        return model.UnitAction(
            velocity=velocidade_deslocamento,
            jump=jump,
            jump_down=jump_down,
            aim=aim,
            shoot=shooting_command,
            reload=False,
            swap_weapon=troca_arma,
            #plant_mine=plat_mine_command)
            plant_mine=False)
    def get_action(self, unit, game, debug):

        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        nearest_health = min(
            filter(lambda box: isinstance(box.item, model.Item.HealthPack),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)

        print(
            "filter:",
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes))

        #print("model.Item::", model.Item)
        #print("game.loot_boxes::", game.loot_boxes)

        print("bullet:", game.bullets)

        target_pos = unit.position

        #Verifica se ja esta com
        #Alguma arma, se não tiver
        #Ira em direção a arma
        #Se ja tiver uma arma, ira em direção
        #Ao Inimigo
        procurando_inimigo = False

        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif unit.health < 90 and nearest_health is not None:
            target_pos = nearest_health.position
        elif unit.weapon is not None and unit.weapon.typ == 2:
            if nearest_weapon is not None:
                target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
            procurando_inimigo = True

        debug.draw(model.CustomData.Log("Txarget pos: {}".format(target_pos)))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)

        jump = target_pos.y > unit.position.y
        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        #if procurando_inimigo :
        #    jump = True
        '''
        print("unit" , unit)
        print("unit.mines" , unit.mines)
        print("unit.health" , unit.health)
        print("unit.weapon" , unit.weapon)
        print("unit.id" , unit.id)
        print("unit.jump_state" , unit.jump_state)
        print("unit.on_ground" , unit.on_ground)
        print("unit.on_ladder" , unit.on_ladder)
        print("unit.player_id" , unit.player_id)
        print("unit.position" , unit.position)
        print("unit.size" , unit.size)
        print("unit.stand" , unit.stand)
        print("unit.walked_right" , unit.walked_right)
        print("nearest_enemy" , nearest_enemy)
        print("nearest_weapon" , nearest_weapon)
        print("nearest_health" , nearest_health)
        print("nearest_health.postion:" , nearest_health.position)        
        print("target_pos.y" , target_pos.y)
        print("unit_pos.y" , unit.position.y)
        print("jump" , jump)    
        '''

        plat_mine_command = True
        #Deve ter pelo menos uma mina
        #E não pode estar na escada
        if unit.mines > 0 and unit.on_ladder == False:
            jump = False
            plat_mine_command = True

        #Troca de Arma
        #Se tiver com uma PISTOLA troca, por qualquer outra
        troca_arma = False
        if unit.weapon is not None:
            if unit.weapon.typ == 2 or unit.weapon.typ == 2:
                troca_arma = True

    ## if unit.health >= 90:
    ##    velocidade_deslocamento = target_pos.x - unit.position.x
    ##else :
        if True:
            velocidade_deslocamento = target_pos.x - unit.position.x
            if abs(velocidade_deslocamento) < 4:
                velocidade_deslocamento *= 3
                if abs(velocidade_deslocamento) < 2:
                    velocidade_deslocamento *= 5

        print("Velocity:", target_pos.x - unit.position.x)
        print("velocidade_deslocamento:", velocidade_deslocamento)

        return model.UnitAction(velocity=velocidade_deslocamento,
                                jump=jump,
                                jump_down=not jump,
                                aim=aim,
                                shoot=True,
                                reload=False,
                                swap_weapon=troca_arma,
                                plant_mine=plat_mine_command)
示例#17
0
    def get_action(self, unit, game, debug):
        nearest_enemy, nearest_weapon, nearest_hpbox, nearest_mine, expected_enemy_pos = self.calc_objects(
            unit, game)

        target_pos, velocity = self.calc_move(unit, nearest_weapon,
                                              nearest_enemy, nearest_hpbox,
                                              nearest_mine)

        aim, los = self.calc_aim(nearest_enemy, unit, game)

        shoot = self.calc_shoot(los)

        jump = self.calc_jump(unit, game, target_pos)
        jump_down = not jump

        plant_mine, jump, jump_down = self.calc_plant_mine(
            unit, nearest_enemy, velocity, jump, jump_down, los)

        #  Debug----------------------
        # if unit.weapon is not None:
        #    debug.draw(model.CustomData.Log(
        #        "Magazine: {}".format(unit.weapon.magazine)))
        #    debug.draw(model.CustomData.Log(
        #        "Fire timer: {}".format(unit.weapon.fire_timer)))
        #    debug.draw(model.CustomData.Log(
        #        "Last fire tick: {}".format(unit.weapon.last_fire_tick)))
        # debug.draw(model.CustomData.Log(
        #    "Shoot Counter: {}".format(self.shoot_counter)))
        # debug.draw(model.CustomData.Log(
        #     "rltv_dist: {}".format(self.rltv_enm_dist)))
        # debug.draw(model.CustomData.Log(
        #    "rltv_side: {}".format(self.rltv_enm_side)))
        #
        #    debug.draw(model.CustomData.Log(
        #        "Weapon: {}".format(unit.weapon.typ)))
        # debug.draw(model.CustomData.Log("mines: {}".format(unit.mines)))
        # debug.draw(model.CustomData.Log("plant_mine: {}".format(plant_mine)))
        # debug.draw(model.CustomData.Log(
        #    "Nearest Mine: {}".format(nearest_mine)))
        # debug.draw(model.CustomData.Log("Max HP: {}".format(self.max_hp)))
        # debug.draw(model.CustomData.Log("Current HP: {}".format(self.curr_hp)))
        # debug.draw(model.CustomData.Log("My velocity: {}".format(velocity)))
        # debug.draw(model.CustomData.Log(
        #     "Enemy velocity: {}".format(self.enemy_velocity)))
        # debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        # debug.draw(model.CustomData.Log("Unit pos: {}".format(unit.position)))
        # debug.draw(model.CustomData.Log(
        #     "Enemy pos: {}".format(nearest_enemy.position)))
        # debug.draw(model.CustomData.Log(
        #     "Expected enemy pos: {}".format(expected_enemy_pos)))
        # debug.draw(model.CustomData.Log(
        #    "Velocity: {}".format(target_pos.x - unit.position.x)))
        # debug.draw(model.CustomData.Log("Jump: {}".format(jump)))
        # debug.draw(model.CustomData.Log("Dist X: {}".format(
        #    nearest_enemy.position.x - unit.position.x)))
        # debug.draw(model.CustomData.Log("Dist Y: {}".format(
        #    nearest_enemy.position.y - unit.position.y)))
        # debug.draw(model.CustomData.Log("Trajectory length: {}".format(leng)))
        # debug.draw(model.CustomData.Log(
        #     "poslist: {}".format(poslist)))
        #  /Debug----------------------

        self.prev_enemy_pos = nearest_enemy.position

        return model.UnitAction(velocity=velocity,
                                jump=jump,
                                jump_down=jump_down,
                                aim=aim,
                                shoot=shoot,
                                reload=False,
                                swap_weapon=self.swap_weapon,
                                plant_mine=plant_mine and not shoot)
示例#18
0
    def get_action(self, unit, game, debug):
        # Replace this code with your own
        def distance_sqr(a, b):
            return (a.x - b.x)**2 + (a.y - b.y)**2

        nearest_enemy = min(
            filter(lambda u: u.player_id != unit.player_id, game.units),
            key=lambda u: distance_sqr(u.position, unit.position),
            default=None)
        nearest_weapon = min(
            filter(lambda box: isinstance(box.item, model.Item.Weapon),
                   game.loot_boxes),
            key=lambda box: distance_sqr(box.position, unit.position),
            default=None)
        target_pos = unit.position
        if unit.weapon is None and nearest_weapon is not None:
            target_pos = nearest_weapon.position
        elif nearest_enemy is not None:
            target_pos = nearest_enemy.position
        debug.draw(model.CustomData.Log("Target pos: {}".format(target_pos)))
        velo = (target_pos.x - unit.position.x) * uniform(-1, 2)
        debug.draw(model.CustomData.Log("velo: {:f}".format(velo)))
        debug.draw(
            model.CustomData.Log("dx: {:f}".format(self.px - unit.position.x)))

        debug.draw(model.CustomData.Log(repr(game.properties)))
        tmp = game.level.tiles
        debug.draw(
            model.CustomData.Log(
                get_debug([
                    tmp[int(unit.position.x)][int(unit.position.y)],
                    tmp[int(unit.position.x - 1)][int(unit.position.y)],
                    tmp[int(unit.position.x)][int(unit.position.y + 1)],
                    tmp[int(unit.position.x + 1)][int(unit.position.y)],
                    tmp[int(unit.position.x)][int(unit.position.y - 1)]
                ])))
        aim = model.Vec2Double(0, 0)
        if nearest_enemy is not None:
            aim = model.Vec2Double(nearest_enemy.position.x - unit.position.x,
                                   nearest_enemy.position.y - unit.position.y)
        jump = target_pos.y > unit.position.y

        if target_pos.x > unit.position.x and game.level.tiles[int(
                unit.position.x + 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if target_pos.x < unit.position.x and game.level.tiles[int(
                unit.position.x - 1)][int(unit.position.y)] == model.Tile.WALL:
            jump = True
        if unit.position.x >= (len(game.level.tiles) - 2):
            self.vv = -1
        if unit.position.x <= 2:
            self.vv = 1
        jump = True
        if game.level.tiles[int(unit.position.x)][int(
                unit.position.y
        )] == model.Tile.PLATFORM and self.px - unit.position.x:
            jump = False
        self.px = unit.position.x
        return model.UnitAction(
            velocity=game.properties.unit_max_horizontal_speed * self.vv,
            jump=jump,
            jump_down=not jump,
            aim=aim,
            shoot=True,
            reload=False,
            swap_weapon=False,
            plant_mine=False)