예제 #1
0
def do_turn(pw):
    """ Function that gets called every turn.
    This is where to implement the strategies.

    :type pw : PlanetWars
    """

    # Retrieve environment characteristics - features you can use to decide which bot to use for that specific map.
    # Are there characteristics you want to use instead, or are there more you'd like to use? Try it out!
    # In this example we will use the number of neutral planets and the average planet growth rate of neutral planets.
    neutral_planets = pw.neutral_planets()
    average_growth_rate = 0

    if len(neutral_planets) > 0:
        average_growth_rate = sum(
            p.growth_rate() for p in neutral_planets) / len(neutral_planets)

    adaptivity_map = AdaptivityMap()

    # Use AdaptivityMap to get the bot which matches the current environment characteristics
    this_turn_bot = adaptivity_map.get_best_bot(len(neutral_planets),
                                                average_growth_rate)

    if this_turn_bot is None:
        # There is no entry for the specified num_neutral_planets and average_growth_rate.
        RandomBot.do_turn(pw)
    elif this_turn_bot is 'BullyBot':
        BullyBot.do_turn(pw)
    elif this_turn_bot is 'RandomBot':
        RandomBot.do_turn(pw)
    elif this_turn_bot is 'LookaheadBot':
        LookaheadBot.do_turn(pw)
    else:
        # The bot in the entry is not supported yet.
        RandomBot.do_turn(pw)
예제 #2
0
def do_turn(pw):
    """ Function that gets called every turn.
    This is where to implement the strategies.

    @type pw : PlanetWars
    """

    # Retrieve environment characteristics - features you can use to decide which bot to use for that specific map.
    # Are there characteristics you want to use instead, or are there more you'd like to use? Try it out!
    # In this example we will use the number of neutral planets and the average planet growth rate of neutral planets.
    neutral_planets = pw.neutral_planets()
    average_growth_rate = 0

    if len(neutral_planets) > 0:
        average_growth_rate = sum(p.growth_rate() for p in neutral_planets) / len(neutral_planets)

    adaptivity_map = AdaptivityMap()

    # Use AdaptivityMap to get the bot which matches the current environment characteristics
    this_turn_bot = adaptivity_map.get_best_bot(len(neutral_planets), average_growth_rate)

    if this_turn_bot is None:
        # There is no entry for the specified num_neutral_planets and average_growth_rate.
        RandomBot.do_turn(pw)
    elif this_turn_bot is 'BullyBot':
        BullyBot.do_turn(pw)
    elif this_turn_bot is 'RandomBot':
        RandomBot.do_turn(pw)
    elif this_turn_bot is 'LookaheadBot':
        LookaheadBot.do_turn(pw)
    else:
        # The bot in the entry is not supported yet.
        RandomBot.do_turn(pw)
def DoTurn(pw):  
  # Retrieve environment characteristics - features you can use to decide which bot to use for that specific map.
  # Are there characteristics you want to use instead, or are there more you'd like to use? Try it out!
  # In this example we will use the number of neutral planets and the average planet growth rate of neutral planets.
  num_neutral_planets = len(pw.NeutralPlanets())
  average_growth_rate = 0
  for p in pw.NeutralPlanets():
    average_growth_rate += p.GrowthRate()
  if num_neutral_planets > 0:
    average_growth_rate = average_growth_rate / num_neutral_planets

  adaptivity_map = AdaptivityMap()
  # # Use AdaptivityMap to get the bot which matches the current environment characteristics  
  this_turn_bot = adaptivity_map.getBestBot(num_neutral_planets, average_growth_rate)
    
  if this_turn_bot is None:
    # There is no entry for the specified num_neutral_planets and average_growth_rate.
    RandomBot.DoTurn(pw)
  elif this_turn_bot == 'BullyBot':
    BullyBot.DoTurn(pw)
  elif this_turn_bot == 'RandomBot':
    RandomBot.DoTurn(pw)
  elif this_turn_bot == 'LookaheadBot':
    LookaheadBot.DoTurn(pw)
  else:
    # The bot in the entry is not supported yet.
    RandomBot.DoTurn(pw)