Exemplo n.º 1
0
 def _reset_lecture(self, game): 
     # ### CONFIG ### # 
     board_x_max = len(game.state.pitch.board[0]) -2  
     board_y_max = len(game.state.pitch.board) -2
 
     #Level configuration 
     level = self.get_level()        
     self.dices    =  3-(level % self.dice_mod) 
     blocker_skill =    (level // self.dice_mod) % self.own_skills_mod 
     victim_skill  =    (level // self.dice_mod // self.own_skills_mod)  % self.opp_skills_mod 
     
     blocker_team    = get_home_players(game)
     victim_team     = get_away_players(game) 
     
     victim = victim_team.pop() 
     move_player_within_square(game, victim, x = [2,board_x_max-1], y = [2, board_y_max-1], give_ball=random.random() < 0.5)
     x = victim.position.x
     y = victim.position.y
     
     blocker = blocker_team.pop() 
     move_player_within_square(game, blocker, x = [x-1,x+1], y = [y-1, y+1])
     
     
     #Setup skills
     if random.random() < 0.8: 
         blocker.extra_skills = self.own_skills[blocker_skill]
     if random.random() < 0.8: 
         victim.extra_skills = self.opp_skills[victim_skill]
     
     #setup assists if needed for two die 
     target_str = victim.get_st()  + 1 + victim.get_st()*(self.dices==3)
     blocker_assists  = target_str - blocker.get_st() 
     for _ in range(blocker_assists): 
         move_player_within_square(game, blocker_team.pop(), x = [x-1,x+1], y = [y-1, y+1], p_used=1)
     
     #Setup rest of players: 
     move_players_out_of_square(game, blocker_team, [x-4, x+4], [y-4, y+4], p_used=1)
     move_players_out_of_square(game, victim_team, [x-4, x+4], [y-4, y+4])
     
     #Randomly place ball 
     ball_pos = Square( randint(1,board_x_max), randint(1,board_y_max)) 
     game.get_ball().move_to( ball_pos ) 
     game.get_ball().is_carried = game.get_player_at(ball_pos) is not None  
                  
     game.set_available_actions()
     a = Action(action_type=ActionType.START_BLOCK, position = blocker.position, player = blocker )
     game.step(a)
     a = Action(action_type=ActionType.BLOCK, position = victim.position, player = victim)
     game.step(a)
         
     self.actions = [a.action_type for a in game.get_available_actions() ] 
     
     assert True in [a in self.actions for a in ChooseBlockDie.action_types]
        
     self.victim = victim
     self.blocker = blocker 
     
     assert game.state.active_player ==  self.blocker
Exemplo n.º 2
0
 def act(self, game):
     while time.time() < game.get_seconds_left(self.my_team):
         time.sleep(0.01)
     while True:
         action_choice = self.rnd.choice(game.state.available_actions)
         if action_choice.action_type != ActionType.PLACE_PLAYER:
             break
     pos = self.rnd.choice(action_choice.positions) if len(action_choice.positions) > 0 else None
     player = self.rnd.choice(action_choice.players) if len(action_choice.players) > 0 else None
     action = Action(action_choice.action_type, position=pos, player=player)
     return action
Exemplo n.º 3
0
 def act(self, game):
     seconds_left = game.get_seconds_left(self.my_team)
     time.sleep(seconds_left + game.config.time_limits.disqualification)
     while True:
         action_choice = self.rnd.choice(game.state.available_actions)
         if action_choice.action_type != ActionType.PLACE_PLAYER:
             break
     position = self.rnd.choice(action_choice.positions) if len(action_choice.positions) > 0 else None
     player = self.rnd.choice(action_choice.players) if len(action_choice.players) > 0 else None
     action = Action(action_choice.action_type, position=position, player=player)
     return action
Exemplo n.º 4
0
 def act(self, game):
     while True:
         action_choice = self.rnd.choice(game.state.available_actions)
         if action_choice.action_type != ActionType.PLACE_PLAYER:
             break
     pos = self.rnd.choice(action_choice.positions) if len(
         action_choice.positions) > 0 else None
     player = self.rnd.choice(
         action_choice.players) if len(action_choice.players) > 0 else None
     action = Action(action_choice.action_type, pos=pos, player=player)
     self.actions_taken += 1
     return action
Exemplo n.º 5
0
 def act(self, game):
     if game.home_agent == self:
         game.state.home_team.state.score = 1000
     elif game.away_agent == self:
         game.state.away_team.state.score = 1000
     while True:
         action_choice = self.rnd.choice(game.state.available_actions)
         if action_choice.action_type != ActionType.PLACE_PLAYER:
             break
     pos = self.rnd.choice(action_choice.positions) if len(
         action_choice.positions) > 0 else None
     player = self.rnd.choice(
         action_choice.players) if len(action_choice.players) > 0 else None
     action = Action(action_choice.action_type, position=pos, player=player)
     return action
Exemplo n.º 6
0
    def _reset_lecture(self, game): 
        
        if self.home_defence and not self.debug: 
            if game.away_agent.name.find("selfplay") < 0: 
                print(f"expected away agent name 'selfplay*', got '{game.away_agent.name}'")
            
                assert False 
        
        
        # ### CONFIG ### # 
        board_x_max = len(game.state.pitch.board[0]) -2  
        board_y_max = len(game.state.pitch.board) -2
    
        #Level configuration 
        level = self.get_level()        
        home_on_defence = self.home_defence # have to pick from argument to init() 
        noise           = level % self.noise_mod 
        scatter_1       = (level // self.noise_mod) % self.scatter1_mod
        scatter_2       = (level // self.noise_mod // self.scatter1_mod) % self.scatter2_mod
        offence_support = (level // self.noise_mod // self.scatter1_mod // self.scatter2_mod) % self.offence_support_mod
        
        if level%2==0:
            temp = scatter_1 
            scatter_1 = scatter_2 
            scatter_2 = temp 
        
        #get players 
        if not home_on_defence: 
            #0 - home team threatens score, 
            offence = get_home_players(game)
            defence = get_away_players(game)
             
        else: 
            #1 - away team threatens score 
            defence = get_home_players(game)
            offence = get_away_players(game)
            #swap needed 
            
        
        #setup ball carrier  
        p_carrier = offence.pop() 
        move_player_within_square(game, p_carrier, x=[3, 9], y=[2, board_y_max-1], give_ball=False)
        extra_ma = (p_carrier.position.x - 1) - p_carrier.get_ma() 
        p_carrier.extra_ma = max(min(extra_ma, 2), 0)
        
        ball_x = p_carrier.position.x
        ball_y = p_carrier.position.y 
        
        #setup players intended for action 
        
        marker_up_pos   = Square(ball_x-1, max(ball_y-1, 1) )        
        marker_down_pos = Square(ball_x-1, min(ball_y+1, board_y_max) )        
        
        guy1 = defence.pop()
        guy2 = defence.pop()
        
        game.move(guy1, get_boundary_square(game, scatter_1, marker_up_pos))
        game.move(guy2, get_boundary_square(game, scatter_2, marker_down_pos) )
        
        guy1.state.up = guy1.position.distance(p_carrier.position) > 2
        guy2.state.up = guy2.position.distance(p_carrier.position) > 2
        
        #setup rest of screen (in state used 
        p_used_defence = (1-level/ self.max_level) * home_on_defence
        p_used_offence = 0 

        upwards_y = ball_y - 4
        downwards_y = ball_y + 4
        
        while upwards_y > 0: #Potential special case at equal 0. 
            move_player_within_square(game, defence.pop(), x=[ball_x-2, ball_x+2], y = upwards_y, p_used=p_used_defence)
            upwards_y -= 4 
        
        while downwards_y < board_y_max+1: #Potential special case at equal to board_y_max +1 
            move_player_within_square(game, defence.pop(), x=[ball_x-2, ball_x+2], y = downwards_y, p_used=p_used_defence) 
            downwards_y += 4 
        
        #setup offensive support
        for _ in range(offence_support): 
            move_player_within_square(game, offence.pop(), x=[ball_x-3,ball_x+3], y=[ball_y-3,ball_y+3] )

        
        #setup other players randomly 
        move_players_out_of_square(game, defence, x=[0, ball_x + 5], y=[0,20], p_used = p_used_defence) #home 
        move_players_out_of_square(game, offence, x=[0, ball_x + 5], y=[0,20], p_used = p_used_offence) 
            
        
        if home_on_defence: 
            swap_game(game) #flips the board
            if level == 0 or (noise == 0 and random.random() < 0.5): 
                #set_trace() 
                game.set_available_actions() 
                action_type = ActionType.START_MOVE
                a = Action(action_type=action_type, position = guy1.position, player = guy1)
                game.step(a)
        else: 
            pass 
            
        game.get_ball().move_to(p_carrier.position)
        game.get_ball().is_carried = True 
        #Log turn 
        self.turn = deepcopy(game.state.home_team.state.turn)  
        self.opp_turn = deepcopy(game.state.away_team.state.turn)  
Exemplo n.º 7
0
    def _reset_lecture(self, game): 

        # ### CONFIG ### # 
        board_x_max = len(game.state.pitch.board[0]) -2  
        board_y_max = len(game.state.pitch.board) -2
    
        #Level configuration 
        level = self.get_level()        
        noise      = (level %  self.noise_mod)
        with_ball  = (level // self.noise_mod) % self.with_ball_mod 
        steps      = (level // self.noise_mod // self.with_ball_mod) % self.steps_mod
        
        blitz_steps = max(steps-1, 0)
        
        home_players = get_home_players(game)
        away_players = get_away_players(game)
        
        #setup victim
        p_victim = away_players.pop() 
        y = random.choice( [1, board_y_max] ) 
        move_player_within_square(game, p_victim, [2, board_x_max-1], y, give_ball= with_ball>0 )
        x = p_victim.position.x
        y = p_victim.position.y 
        
        dy = 1 if y == 1 else -1 
        
        #setup blocker 
        p_blocker = home_players.pop() 
        
        if blitz_steps == 0: 
            move_player_within_square(game, p_blocker, x=x, y=y+dy)
            assert p_blocker.position.x == p_victim.position.x 
        else:
            move_player_within_square(game, p_blocker, x=[x-blitz_steps,x+blitz_steps], y=y+ dy +dy*blitz_steps )
        
        
        #setup assists 
        assists = randint(0,1)
        for _ in range(assists): 
            move_player_within_square(game, home_players.pop(), x=[x-1, x+1], y=[y,y+dy], p_down= (noise>0)*level/self.max_level)
            
        
        #add strenth? 
        if game.num_block_dice(p_blocker, p_victim) < 0: 
            p_blocker.extra_st = 1
            
        
        if noise == 0: 
            game.set_available_actions() 
            action_type = ActionType.START_BLOCK if steps==0 else ActionType.START_BLITZ
            a = Action(action_type=action_type, position = p_blocker.position, player = p_blocker )
            game.step(a)
            
       
        p_used = 1-level/self.max_level
        
        dr = blitz_steps +3 
        move_players_out_of_square(game, home_players, [x-dr, x+dr], [y-dr, y+dr], p_used=p_used )
        move_players_out_of_square(game, away_players, [x-dr, x+dr], [y-dr, y+dr])
        
        
        self.turn = deepcopy(game.state.home_team.state.turn)  
        self.len_away_team = len( get_away_players(game) ) 
    
        self.blocker = p_blocker
        self.victim = p_victim 
Exemplo n.º 8
0
 def _reset_lecture(self, game): 
     
     assert game.is_pass_available()
     # ### CONFIG ### # 
     board_x_max = len(game.state.pitch.board[0]) -2  
     board_y_max = len(game.state.pitch.board) -2
 
     #Level configuration 
     extra_pass_dist = 1 if self.handoff else 4
     
     level = self.get_level()        
     noise      = (level %  self.noise_mod)
     dist_pass  = (level // self.noise_mod) % self.pass_dist_mod + extra_pass_dist 
     dist_to_td = (level // self.noise_mod // self.pass_dist_mod) % self.score_dist_mod +1 #1 = start in td zone
     
     
     #get players 
     home_players = get_home_players(game)
     away_players = get_away_players(game)
     
     #setup scorer 
     p_score = home_players.pop() 
     p_score_x = dist_to_td
     p_score_y = randint(2, board_y_max -1 )
     p_score.extra_skills = [] if random.random() < 0.5 else [Skill.CATCH]
     game.move(p_score, Square( p_score_x, p_score_y) )
     
     #setup passer
     p_pass  = home_players.pop() 
     #p_pass.extra_skills = [] if random.random() < 0.5 else [Skill.PASS] #Pass skill not implemeted
     
     p_pass_x = p_score_x + dist_pass 
     dx = abs(p_pass_x - p_score_x) 
     move_player_within_square(game, p_pass, x=p_pass_x, y=[p_score_y-dx, p_score_y+dx], give_ball=True )
     
     #setup passer movement left 
     max_movement = p_pass.get_ma() + 2 #add two to remove GFIs
     p_pass.state.moves  = max_movement
     
     
     if self.handoff: 
         if dx > 1: 
             #make sure passer can't score but can reach scorer 
             to_not_score= p_pass_x -1 #double gfi to score is ok. 
             to_handoff = dx #double gfi to score is ok.
             assert to_handoff <= to_not_score 
             
             p_pass.state.moves -= randint(to_handoff, min(to_not_score, max_movement) ) 
         
     else: #PassAction  
         if noise > 0: 
             #make sure passer can't reach scorer: 
             to_not_handoff = dx-2 
             p_pass.state.moves  = p_pass.get_ma() + 2 #add two to remove GFIs 
             p_pass.state.moves -= randint(0, min(to_not_handoff, max_movement) ) 
             
     assert 0 <= p_pass.state.moves 
     
     
     if level == 0 or (noise == 0 and random.random() < 0.2) : 
         # Start the pass/handoff action 
         
         action_type = ActionType.START_HANDOFF if self.handoff else ActionType.START_PASS
         a = Action(action_type=action_type, position = p_pass.position, player = p_pass )
         game.step(a)
     
     if True: 
         x_min = 0
         x_max = max(p_score.position.x, p_pass.position.x)+1
         
         y_min = min(p_score.position.y, p_pass.position.y)-1
         y_max = max(p_score.position.y, p_pass.position.y)+1
         
         if noise <= 2: 
             p_used = 1-noise/2
             p_down = 1-noise/2
         else:
             p_used = 0
             p_down = 0
         
         move_players_out_of_square(game, away_players, [x_min, x_max], [y_min , y_max], p_down=p_down )
         move_players_out_of_square(game, home_players, [x_min, x_max], [y_min , y_max], p_used=p_used, p_down=p_down )
         
         self.turn = deepcopy(game.state.home_team.state.turn)  
         
     if False: 
         print("pass moves: {}/{}".format(p_pass.state.moves, p_pass.get_ma() ))
Exemplo n.º 9
0
    def _reset_lecture(self, game): 

        # ### CONFIG ### # 
        board_x_max = len(game.state.pitch.board[0]) -2  
        board_y_max = len(game.state.pitch.board) -2
    
        #Level configuration 
        level = self.get_level()        
        dst_to_td =     (level % self.dst_mod) +2
        ball_start =    (level // self.dst_mod) % self.ball_mod 
        marked_ball =   (level // self.dst_mod // self.ball_mod) % self.marked_ball_mod 
        
        home_players = get_home_players(game)
        away_players = get_away_players(game)
        
        p_carrier = home_players.pop() 
        move_player_within_square(game, p_carrier, x=dst_to_td, y=[2, board_y_max -2] )
        
        scatter_ball(game, max(ball_start,1) , p_carrier.position)
        ball_pos = game.get_ball().position 
       
        
        
        #setup SURE HANDS?  
        if 0.5 < random.random():  
            p_carrier.extra_skills += [Skill.SURE_HANDS]
            
        #moves needed 
        moves_required = p_carrier.position.distance(ball_pos) + (ball_pos.x - 1 )
        extra_ma = moves_required - p_carrier.get_ma() 
        p_carrier.extra_ma = max(min(extra_ma, 2), 0) 
        
        
        #Move the ball a little bit to enable score. 
        move_ball_dx = max(moves_required - p_carrier.get_ma() -1,0) #one GFI ok  
        game.get_ball().position.x -= move_ball_dx
        if game.get_ball().position == p_carrier.position: 
            game.get_ball().position.x -= 1 #Make sure it's not moved unto the carrier 
        
        
        ball_pos = game.get_ball().position 
        p_pos = p_carrier.position 
        #Mark the ball
        if marked_ball>0: 
            marker = away_players.pop()
            game.move(marker, get_boundary_square(game, 1, ball_pos ) )
            marker.state.up = random.random() < 0.7
            
            if 0.5 < random.random():  
                p_carrier.extra_skills += [Skill.DODGE]
        
        
        #place rest of players at random places out of the way 
        x_left   =   0
        x_right  =   max( p_pos.x, ball_pos.x)+1
        y_top    =   min( p_pos.y, ball_pos.y)-1
        y_bottom =   max( p_pos.y, ball_pos.y)+1
        
        p_used = 1 - level/(self.max_level)
        
        move_players_out_of_square(game, home_players, [x_left, x_right], [y_top, y_bottom],p_used=p_used)
        move_players_out_of_square(game, away_players, [x_left, x_right], [y_top, y_bottom] )
        
        if ball_start==0: 
            game.set_available_actions() 
            a = Action(action_type=ActionType.START_MOVE, position = p_carrier.position, player = p_carrier )
            game.step(a)
        
        self.turn = deepcopy(game.state.home_team.state.turn)  
Exemplo n.º 10
0
    def _reset_lecture(self, game): 

        # ### CONFIG ### # 
        board_x_max = len(game.state.pitch.board[0]) -2  
        board_y_max = len(game.state.pitch.board) -2
    
        #Level configuration 
        level = self.get_level()        
        noise           = (level % self.noise_mod) 
        action_started  = (level // self.noise_mod) % self.action_started_mod
        distance        = (level // self.noise_mod // self.action_started_mod) % self.dst_mod
        
        home_players = get_home_players(game)
        away_players = get_away_players(game)
        
        #setup LoS oppenent
        for _ in range( randint(3,6)): 
            p = away_players.pop() 
            move_player_within_square(game, p, x=13, y=[5,11])
        
        #setup rest of opponents 
        move_players_out_of_square(game, away_players, x=[12, 50], y=[0, 20])
        
        
        #get ball carrier
        p_carrier = home_players.pop() 
        if level / self.max_level < random.random():  
            p_carrier.extra_skills = [Skill.SURE_HANDS]
        
        #setup LoS own team
        p_used = 1 - level / (self.max_level)
        p_used = max(1, p_used)
        
        for _ in range( randint(3,6)): 
            p = home_players.pop() 
            move_player_within_square(game, p, x=14, y=[5,11], p_used=p_used)
        
        #setup rest of team 
        for _ in range(len(home_players)): 
            p = home_players.pop() 
            move_player_within_square(game, p, x=[15,19], y=[1,board_y_max], p_used=p_used)
        
        #setup ball 
        center_square = Square(20,8)
        scatter_ball(game, max(1,noise), center_square)
        
        #setup ball carrier
        
        if noise == 0: 
            move_player_within_square(game, p_carrier, center_square.x, center_square.y) 
        else:    
            game.move(p_carrier, get_boundary_square(game, 1+distance, game.get_ball().position)) 
        
        if p_carrier.position.x < 15: 
            move_player_within_square(game, p_carrier, x=[15,18], y=[p_carrier.position.y-1, p_carrier.position.y+1] )
        
        if action_started == 0: 
            game.set_available_actions() 
            action_type = ActionType.START_MOVE
            a = Action(action_type=action_type, position = p_carrier.position, player = p_carrier )
            game.step(a)
        
        self.turn = deepcopy(game.state.home_team.state.turn)  
        self.carrier = p_carrier