()
Process a request to do a battle among four agents.

    This is on the game manager server. The request includes the docker images
    for each agent, along with their agent id (aid) and the config.

    The execution order is:
    1. Tell each of the four servers to pull their given agent's container.
    2. They'll then send us back container_is_ready notifications.
    3. When we receive all of those notifications, we'll fire run_battle here.
    4. The run_battle script will then manage speaking to each of the servers.
    5. After the game is over, a result will be sent back to the web server.
Process a request to do a battle among four agents.
Process a request to do a battle among four agents .
def request_battle():
    """Process a request to do a battle among four agents.

    This is on the game manager server. The request includes the docker images
    for each agent, along with their agent id (aid) and the config.

    The execution order is:
    1. Tell each of the four servers to pull their given agent's container.
    2. They'll then send us back container_is_ready notifications.
    3. When we receive all of those notifications, we'll fire run_battle here.
    4. The run_battle script will then manage speaking to each of the servers.
    5. After the game is over, a result will be sent back to the web server.
    """
    try:
        incoming = request.get_json()
        agents = [{
            'docker_image':
            incoming.get('docker_image_agent_%d' % agent_id),
            'aid':
            incoming.get('aid_%d' % agent_id),
            'agent_id':
            agent_id
        } for agent_id in range(4)]
        battle_info = incoming['config']
        battle_info += '-%d-%d-%d-%d' % [agent['aid'] for agent in agents]
        success, message = notify_containers(agents, battle_info)
        if success:
            return jsonify(success=True, error="")
        else:
            return jsonify(success=False, error=message)
    except Exception as e:
        return jsonify(success=False, error=e)
def request_battle ( ) : try : incoming = request . get_json ( ) agents = [ { 'docker_image' : incoming . get ( 'docker_image_agent_%d' % agent_id ) , 'aid' : incoming . get ( 'aid_%d' % agent_id ) , 'agent_id' : agent_id } for agent_id in range ( 4 ) ] battle_info = incoming [ 'config' ] battle_info += '-%d-%d-%d-%d' % [ agent [ 'aid' ] for agent in agents ] success , message = notify_containers ( agents , battle_info ) if success : return jsonify ( success = True , error = "" ) else : return jsonify ( success = False , error = message ) except Exception as e : return jsonify ( success = False , error = e )