示例#1
0
def agent(obs, config):
    # Another for updates
    board = Board(obs, config)

    # Step of the board
    step = board.observation['step']

    ships = [
        ship.id for ship in sorted(board.current_player.ships,
                                   key=operator.attrgetter("halite"),
                                   reverse=True)
    ]
    actions = {}

    for ship_id in ships:
        if ship_id in board.current_player.ship_ids:
            next_action, action_type = DecisionShip(board, ship_id,
                                                    step).determine()

            if action_type != 'mine':
                actions[ship_id] = movement_dictionary[action_type]
                board.ships[ship_id].next_action = next_action
                board = board.next()

    shipyard_ids = ShipyardDecisions(board, board.current_player,
                                     step).determine()

    for shipyard_id in board.current_player.shipyard_ids:
        if shipyard_id in shipyard_ids:
            actions[shipyard_id] = 'SPAWN'
            board.shipyards[shipyard_id].next_action = ShipyardAction.SPAWN

            board = board.next()

    return actions
 def update_observation_for_shipyard(board: Board, uid, action):
     """Simulate environment step forward and update observation
     https://www.kaggle.com/sam/halite-sdk-overview#Simulating-Actions-(Lookahead)
     """
     ship = board.shipyards[uid]
     ship.next_action = action
     ret_val = board.next()
     return Observation(ret_val.observation)
示例#3
0
def agent(obs, config):
    # Another for updates
    board = Board(obs, config)

    # Step of the board
    step = board.observation['step']

    ships = [ship.id for ship in sorted(board.current_player.ships, key=operator.attrgetter("halite"), reverse=True)]
    actions = {}

    # It would be absurd to log when I am out of the game
    if not(len(board.current_player.ships) == 0 and board.current_player.halite < 500):
        log(str(step + 1) + '|-----------------------------------------------------------------------')

    for ship_id in ships:
        if ship_id in board.current_player.ship_ids:
            log(' Pos:' + str(board.ships[ship_id].position) + ', cargo: ' + str(board.ships[ship_id].halite) + ', player halite: ' + str(board.current_player.halite))
                
            next_action, action_type = DecisionShip(board, ship_id, step).determine()
                
            if action_type != 'mine':
                actions[ship_id] = movement_dictionary[action_type]
                board.ships[ship_id].next_action = next_action
                if step == 200: log(board)
                board = board.next()
                if step == 200: log(board)
        # else:
        #     log(' Not found')

    shipyard_ids = ShipyardDecisions(board, board.current_player, step).determine()

    for shipyard_id in board.current_player.shipyard_ids:
        if shipyard_id in shipyard_ids:
            actions[shipyard_id] = 'SPAWN'
            board.shipyards[shipyard_id].next_action = ShipyardAction.SPAWN
            
            board = board.next()
        
    return actions