示例#1
0
def setup_behavior_tree():
    logging.debug("setting up tree")
    # Top-down construction of behavior tree
    root = Sequence(name='Defensive and Origional Root')
    root2 = Selector(name='High Level Ordering of Strategies')
    logging.debug("roots are set up")

    defensive_plan = Sequence(name='Defensive Strategy')
    logging.debug("defensive plan is created")
    has_planets = Check(has_multiple_planets)
    #logging.debug("defensive plan is created")
    defend = Action(defend_planets)
    #logging.debug("defensive plan is created")
    defensive_plan.child_nodes = [has_planets, defend]
    #logging.debug("defensive plan is created")

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_strongest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]
    logging.debug("offensive plan is created")

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_highest_producer)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]
    logging.debug("spread plan is created")

    root2.child_nodes = [offensive_plan, spread_sequence, attack.copy()]
    root.child_nodes = [root2, defensive_plan]
    logging.info('\n' + root.tree_to_string())
    return root
示例#2
0
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    defensive_plan = Sequence(name='Defensive Strategy')
    attacked_check = Check(is_being_attacked)
    defend = Action(defend_planet_attack)
    defensive_plan.child_nodes = [attacked_check, defend]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_closest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    offensive_plan = Sequence(name="Offensive Strategy")
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    root.child_nodes = [
        offensive_plan, defensive_plan, spread_sequence,
        attack.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#3
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    """offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    defensive_plan = Sequence(name= 'Defensive Plan')
    have_largest_fleet = Check(have_largest_fleet)
    match_fleets = Action(defend_planets2)
    defensive_plan.child_nodes = [enemy_attacking_check, match_fleets]"""

    have_largest = Check(have_largest_fleet)
    defend = Action(defend_planets2)
    spread_sequence = Action(spread)
    equal_action = Action(equalize)

    defensive_plan = Sequence(name='Defensive Plan')
    defensive_plan.child_nodes = [equal_action, defend, spread_sequence]

    offensive_plan = Sequence(name='Offensive Strategy')
    offensive_plan.child_nodes = [have_largest, spread_sequence, defend]

    root.child_nodes = [offensive_plan, defensive_plan]

    logging.info('\n' + root.tree_to_string())
    return root
示例#4
0
文件: bt_bot.py 项目: mdhsieh/cmpm146
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    # Otherwise, attack everywhere
    attack_all = Action(attack_everyone)

    # spread to all neutral planets
    # spread_all = Action(spread_all_neutral)

    # root.child_nodes = [offensive_plan, spread_sequence, attack.copy()]
    root.child_nodes = [offensive_plan, spread_sequence, attack_all]

    logging.info('\n' + root.tree_to_string())
    return root
示例#5
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    defensive_plan = Sequence(name='Defensive Strategy')
    planet_number_check = Check(have_more_planets)
    defend_action = Action(defend)
    defensive_plan.child_nodes = [planet_number_check, defend_action]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    #increase_planet_growth = Sequence(name='Must construct additional pylons')
    #growth_check = Check(have_largest_growth)
    #grow = Action(grow_planet)
    #growth_plan.child_nodes = [growth_check, grow]

    root.child_nodes = [
        defensive_plan, spread_sequence, offensive_plan,
        attack.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#6
0
def setup_behavior_tree():

    #Punish the Opponent Strategy:

    #if our effective attack power (distance, fleet power in distance, planet growth)
    #is greater than
    #our opponents effective defense power (distance, fleet power in distance, planet growth)
    #then capture the planet

    #if it isn't greater start to move resources towards the frontier

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    acquire_freebies = Sequence(name='Free Planets Strategy')
    free_planet_check = Check(if_free_planet)
    attack = Action(free_planet_plan)
    acquire_freebies.child_nodes = [free_planet_check, attack]

    defensive_plan = Sequence(name='Defensive Strategy')
    enemy_fleet_check = Check(if_enemy_fleet)
    defend = Action(intercept_plan)
    defensive_plan.child_nodes = [enemy_fleet_check, defend]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_until_advantaged)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [acquire_freebies, defensive_plan, spread_sequence]

    logging.info('\n' + root.tree_to_string())
    return root
示例#7
0
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    defensive_plan = Sequence(name='Defensive Strategy')
    attacked_check = Check(is_being_attacked)
    defend = Action(defend_planet)
    defensive_plan.child_nodes = [attacked_check, defend]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_time)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    neut_sequence = Sequence(name='Neutral Strategy')
    neut_attacked_check = Check(neut_attacked)
    neut_action = Action(neut_overtake)
    neut_sequence.child_nodes = [neut_attacked_check, neut_action]

    offensive_plan = Sequence(name="Offensive Strategy")
    attack = Action(attack_fun)
    offensive_plan.child_nodes = [attack]

    super_offensive_plan = Sequence(name="Super Offensive Strategy")
    super_offensive_check = Check(killing_blow)
    super_attack = Action(killing_blow_action)
    super_offensive_plan.child_nodes = [super_offensive_check, super_attack]

    root.child_nodes = [
        super_offensive_plan, offensive_plan, neut_sequence, defensive_plan,
        spread_sequence
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#8
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    """
    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    counter_action = Action(counter_fleet)

    regrow_sequence = Sequence(name='Regrow Strategy')
    lone_ally_check = Check(lone_ally)
    take_high_growth_action = Action(take_high_growth)
    regrow_sequence.child_nodes = [lone_ally_check, take_high_growth_action]

    checkmate_sequence = Sequence(name='Checkmate Strategy')
    lone_enemy_check = Check(lone_enemy)
    rush_first_target_action = Action(rush_first_target)
    checkmate_sequence.child_nodes = [lone_enemy_check, rush_first_target_action]
    """

    early_game_strategy = Sequence(name='Early Game Strategy')
    lone_ally_check = Check(lone_ally)
    grow_from_one_action = Action(grow_from_one)
    early_game_strategy.child_nodes = [lone_ally_check, grow_from_one_action]

    production_action = Action(production)

    aggressive_strategy = Selector(name='Aggressive Strategy')
    attack_sequence = Sequence(name='Attack Sequence')
    largest_fleet_check = Check(have_largest_fleet)
    attack_action = Action(attack)
    attack_sequence.child_nodes = [largest_fleet_check, attack_action]
    spread_action = Action(spread)
    aggressive_strategy.child_nodes = [attack_sequence, spread_action]

    defend_action = Action(defend)

    root.child_nodes = [
        early_game_strategy, aggressive_strategy, defend_action
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#9
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    spread_out_plan = Sequence(name='Spread Out Strategy')
    spread_out_attack = Action(wide_spread)
    spread_out_plan.child_nodes = [spread_out_attack]

    defense = Action(defend)

    close_enemy_planet_attack = Action(attack_close_enemy_planet)
    close_neutral_planet_attack = Action(attack_close_neutral_planet)

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [
        defense, spread_out_plan, close_enemy_planet_attack,
        close_neutral_planet_attack, offensive_plan, spread_sequence,
        attack.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#10
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    '''
    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [offensive_plan, spread_sequence, attack.copy()]
    '''

    test_plan = Sequence(name='Attack Best Planet')
    attack = Action(take_best_planet)
    test_plan.child_nodes = [attack]

    root.child_nodes = [test_plan]

    logging.info('\n' + root.tree_to_string())
    return root
示例#11
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack_choice = Selector(name='Attack Method')
    attack_growth = Action(attack_highest_growth)
    attack_closest = Action(attack_nearest_enemy_planet)
    attack_weakest = Action(attack_weakest_enemy_planet)
    attack_choice.child_nodes = [attack_growth, attack_closest, attack_weakest]
    offensive_plan.child_nodes = [largest_fleet_check, attack_choice]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_nearest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    defense_sequence = Sequence(name='Defense Strategy')
    multiple_planet_check = Check(if_have_multiple_planets)
    redistribute_action = Action(strongest_to_weakest)
    defense_sequence.child_nodes = [multiple_planet_check, redistribute_action]

    root.child_nodes = [
        offensive_plan, spread_sequence, defense_sequence,
        attack_closest.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#12
0
def setup_behavior_tree():
    """
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [offensive_plan, spread_sequence, attack.copy()]
    """

    root = Selector(name="Strategy Sequence")

    spread_sequence = Sequence(name="Spread Strategy")
    neutral_available_check = Check(if_neutral_planet_available)
    succeed_spread = AlwaysSucceed(name="Spread Succeeder")
    spread = Action(spread_to_best_neutral)
    succeed_spread.child_node = spread
    succeed_defend = AlwaysSucceed(name="Defend Succeeder")
    defend = Action(defend_planets)
    succeed_defend.child_node = defend
    spread_sequence.child_nodes = [
        neutral_available_check, succeed_spread, succeed_defend
    ]

    attack_sequence = Sequence(name="Attack Strategy")
    alive_check = Check(opponent_alive)
    succeed_attack = AlwaysSucceed(name="Succeed Attack")
    attack = Action(attack_opponent_planets)
    succeed_attack.child_node = attack
    attack_sequence.child_nodes = [
        alive_check, succeed_attack,
        succeed_defend.copy()
    ]

    root.child_nodes = [spread_sequence, attack_sequence]
    logging.info('\n' + root.tree_to_string())
    return root
示例#13
0
def setup_behavior_tree():
    """

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [offensive_plan, spread_sequence, attack.copy()]

    logging.info('\n' + root.tree_to_string())
    return root

    """

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    Gambit = Sequence(name="Gambit")
    besieged = Check(is_attacking)
    counter = Action(attack_or_defend)
    Gambit.child_nodes = [besieged, counter]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    offensive_plan = Sequence(name='War')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    root.child_nodes = [Gambit, spread_sequence, offensive_plan]

    logging.info('\n' + root.tree_to_string())
    return root
def new_tree():
    root = Selector()
 
    #plan for the first few turns of the game, expand to easy neutral planets then switch to aggressive expansion
    startingMoves = Sequence()
    gameStart = Check(homeBase)
    fleetEngage = Check(readyShips)
    createEmpire = Action(expandToNeutrals)
    startingMoves.child_nodes = [gameStart, fleetEngage, createEmpire]

    #once we have a stable base, we can start spreading out and attacking enemy planets
    expandEmpire = Sequence()
    muster = Check(checkForces)
    crusade = Action(assult)
    expandEmpire.child_nodes = [muster, crusade]

    root.child_nodes = [startingMoves, expandEmpire]

    logging.info('\n' + root.tree_to_string())
    return root
示例#15
0
文件: bt_bot.py 项目: aAshkan/GameAI
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    grab_what_enemy_wants = Sequence(name='Getting what enemy wants')
    neutral_planet_check = Check(if_neutral_planet_available)
    is_grabbing = Check(if_a_good_neutral_available)
    take_good_neutral = Action(if_a_good_neutral_available_now)
    grab_what_enemy_wants.child_nodes = [
        neutral_planet_check, is_grabbing, take_good_neutral
    ]

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    #largest_growth_rate_check = Check(have_largest_growth_rate)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [attack]
    """
    send_three_to_neutral = Sequence(name='send 3 neutral')
    above_30 = Check(above_30_not_sending)
    send_one = Action(send_to_closest_neutral_if_backup)
    send_backup = Action(send_affensive_help)
    send_three_to_neutral.child_nodes = [above_30, send_one, send_backup, send_backup]
    """

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_selector = Selector(name='Spread Selector')
    enough = Check(if_dont_have_enough_neutral)
    not_close_enough = Check(if_enemy_too_far)
    spread_selector.child_nodes = [enough, not_close_enough]
    worth = Check(worth_attacking_neutral)
    spread_action = Action(spread_to_best_neutral)
    spread_sequence.child_nodes = [
        neutral_planet_check, spread_selector, worth, spread_action
    ]

    root.child_nodes = [grab_what_enemy_wants, spread_sequence, offensive_plan]

    logging.info('\n' + root.tree_to_string())
    return root
示例#16
0
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    reinforcements = Sequence(name='Send Reinforcements')
    invaded_check = Check(invaded_maybe)
    send_backup = Action(send_aid_to_invaded_planet)
    reinforcements.child_nodes = [invaded_check, send_backup]

    multi_plan = Sequence(name='Multi Attack')
    have_planets = Check(min_planets)
    multi_action = Action(multi_attack)

    multi_plan.child_nodes = [largest_fleet_check, have_planets, multi_action]

    mul_spread = Sequence(name='Multi Spread')
    have_planets = Check(min_planets)
    is_neutral = Check(if_neutral_planet_available)
    multi_spread_action = Action(multi_spread)

    mul_spread.child_nodes = [have_planets, is_neutral, multi_spread_action]

    strong_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    strongest_attack = Action(strong_attack)
    strong_plan.child_nodes = [largest_fleet_check, strongest_attack]

    finish_plan = Sequence(name='Finish Plan')
    largest_fleet_check = Check(have_largest_fleet)
    have_planets = Check(min_planets)
    finish_action = Action(barrage)
    finish_plan.child_nodes = [largest_fleet_check, have_planets, finish_action]

    pinpoint_plan = Sequence(name='Pinpoint')
    largest_fleet_check = Check(have_largest_fleet)
    have_planets = Check(min_planets)
    pinpoint_action = Action(pinpoint)
    pinpoint_plan.child_nodes = [largest_fleet_check, have_planets, pinpoint_action]

    root.child_nodes = [offensive_plan, spread_sequence, reinforcements, mul_spread, multi_plan, finish_plan, attack.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#17
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack_action = Action(attack)
    offensive_plan.child_nodes = [largest_fleet_check, attack_action]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    defense_plan = Sequence(name='Defense Strategy')
    defense_check = Check(have_weak_planets)
    defense_action = Action(defend)
    defense_plan.child_nodes = [defense_check, defense_action]

    desperado_plan = Sequence(name='Desperado Strategy')
    under_attack_check = Check(planet_under_attack)
    attack_desperado_action = Action(desperado_attack)
    desperado_plan.child_nodes = [under_attack_check, attack_desperado_action]

    root.child_nodes = [
        offensive_plan, defense_plan, spread_sequence,
        attack_action.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#18
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    steal_plan = Sequence(name='Steal Strategy')
    enemy_just_conquered_check = Check(enemy_just_conquered)
    steal = Action(attack_recent_lost_neutral_planet)
    steal_plan.child_nodes = [enemy_just_conquered_check, steal]

    offensive_plan = Sequence(name='Offensive Strategy')
    #largest_fleet_check = Check(have_largest_fleet)
    stable_check = Check(is_stable_enough_to_attack)
    attack_close = Action(attack_closet_enemy_outpost)
    attack_weak = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [stable_check, attack_close, attack_weak]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    repair_sequence = Sequence(name='Repair Strategy')
    weak_planet_check = Check(is_my_weakest_planet_at_risk)
    repair_action = Action(spread_my_fleet)
    repair_sequence.child_nodes = [weak_planet_check, repair_action]

    root.child_nodes = [steal_plan, offensive_plan, spread_sequence, repair_sequence, attack_close.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#19
0
def setup_behavior_tree():
    
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    
    oppression = Sequence(name="Oppression")
    alpha_check = Check(apex)
    plan_alpha = Action(order_alpha)
    oppression.child_nodes = [alpha_check, plan_alpha]

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_plan)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    deny_sequence = Sequence(name='Deny Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    deny_plan = Action(deny_enemy_fleet)
    s_plan = Action(spread_plan)
    deny_sequence.child_nodes = [neutral_planet_check, deny_plan]
    
    root.child_nodes = [offensive_plan, deny_sequence, oppression, attack.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#20
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(starting_position_close)
    attack = Action(attack_start)
    offensive_plan.child_nodes = [largest_fleet_check, attack]
    """
    this shouldn't have to be ever used. at all.
    spread_sequence = Sequence(name='Defense Strategy')
    spread_action = Action(defend)
    defend_check =  Check(have_five_planets)
    spread_sequence.child_nodes = [defend_check, spread_action]
    """

    spread_close = Sequence(name='Spreading Strategy')
    spread_close_action = Action(spread_to_weakest_and_closest_planet)
    spread_close.child_nodes = [spread_close_action]

    attack = Sequence(name='Attack Strategy')
    attack_action = Action(attack_them)
    attack_check = Check(have_five_planets)
    attack.child_nodes = [attack_check, attack_action]

    root.child_nodes = [offensive_plan, spread_close, attack]

    logging.info('\n' + root.tree_to_string())
    return root
示例#21
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    # Define available actions to take.
    colonize = Action(take_defenseless_territory)
    invade = Action(attack_with_no_mercy)
    reinforce = Action(reinforce_with_vengeance)
    retaliate = Action(retaliate_with_fury)

    # *** Begin preliminary suprise invasion over the galaxy. ***
    imperial_ambition = Sequence(name='Expansion Strategy: Manifest Destiny')
    imperial_ambition.child_nodes = [colonize, invade]

    # *** Consolidate and retaliate if under attack by hostiles. ***
    imperial_shield = Sequence(name='Security Strategy: Cereberus')
    danger_check = Check(if_under_attack)
    imperial_shield.child_nodes = [danger_check, reinforce, retaliate]
    
    # *** If the advantage is ours, attack with full force. ***
    imperial_aggression = Sequence(name='Aggressive Strategy: Crush All Remaining Resistance')
    largest_fleet_check = Check(have_largest_fleet)
    imperial_aggression.child_nodes = [largest_fleet_check, invade]

    # Begin selecting strategies. 
    root.child_nodes = [imperial_ambition, imperial_aggression, imperial_shield, invade.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#22
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    logging.info('building tree')
    snipe_plan = Sequence(name='Snipe Strategy')
    snipe_available_check = Check(snipe_available)
    snipe_attack = Action(snipe_boi)
    snipe_plan.child_nodes = [snipe_available_check, snipe_attack]

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_best_neutral)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    defense_plan = Sequence(name='Defensive Strategy')
    defend_boi_check = Check(defend_boi_available)
    defend_action = Action(defend_boi)
    defense_plan.child_nodes = [defend_boi_check, defend_action]
    '''
    snipe_plan,
    '''
    root.child_nodes = [
        defense_plan, snipe_plan, offensive_plan, spread_sequence,
        attack.copy()
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#23
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    #attack plan
    invert_att = Inverter()
    succeed_att = Succeeder()
    offensive_plan = Sequence(name='Offensive Strategy')
    enough_planets_check = Check(has_enough_planets)
    attack = Action(attack_weakest_enemy_planet)
    invert_att.child_node = succeed_att
    succeed_att.child_node = offensive_plan
    offensive_plan.child_nodes = [enough_planets_check, attack]

    #defense plan
    invert_def = Inverter()
    succeed_def = Succeeder()
    defense = Action(defend_weakest_ally)
    succeed_def.child_node = defense
    invert_def.child_node = succeed_def

    #reinforce plan
    #invert_reinforce = Inverter()
    #succeed_reinforce = Succeeder()
    #reinforce = Action(reinforce_new_planet)
    #succeed_reinforce.child_node = reinforce
    #invert_reinforce.child_node = succeed_reinforce

    #spread plan
    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [invert_att, invert_def, spread_sequence, attack.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#24
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    
    # sequence = Sequence(name)
    # check(s) = Check(name_of_check) - takes boolean
    # action = Action(name_of_behavior) - do something
    # sequence.child_nodes = [check(s), action(s)]

    #spread_sequence = Sequence(name='Spread Strategy')
    #neutral_planet_check = Check(if_neutral_planet_available)
    #spread_action = Action(spread_to_weakest_neutral_planet)
    #spread_sequence.child_nodes = [neutral_planet_check, spread_action]
    
    spread_production_sequence = Sequence(name='Spread Production Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_production_sequence_action = Action(spread_production)
    spread_production_sequence.child_nodes = [neutral_planet_check, spread_production_sequence_action]
    
    defend_sequence = Sequence(name='Defend Strategy')
    enemy_attacks_check = Check(enemy_attacks)
    defend_action = Action(defend2)
    defend_sequence.child_nodes = [enemy_attacks_check, defend_action]
    
    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]

    # 
    root.child_nodes = [spread_production_sequence, offensive_plan, attack.copy()]
    
    #root.child_nodes = [spread_sequence, spread_production_sequence, offensive_plan, attack.copy()]

    logging.info('\n' + root.tree_to_string())
    return root
示例#25
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]

    spread_enemy = Sequence(name='Spread Attack')
    enemy_check = Check(spread_check)
    spread_go = Action(start_spread)
    spread_enemy.child_nodes = [enemy_check, spread_go]

    defense = Sequence(name='defense')
    defensive_check = Check(defense_check)
    defense_go = Action(defense_action)
    defense.child_nodes = [defensive_check, defense_go]

    root.child_nodes = [spread_sequence, spread_enemy, defense]

    logging.info('\n' + root.tree_to_string())
    return root
示例#26
0
文件: bt_bot.py 项目: dbirtola/146
def parse_tree(tree_string):

    root = Selector(name="Root")

    #Current node has the current selector or sequence that we are processing
    current_node = root

    for char in tree_string:
        if char == "-":
            #Selector
            new_node = Selector(name="Selector")
            new_node.parent_node = current_node
            new_node.child_nodes = []
            current_node.child_nodes.append(new_node)

        elif char == "_":
            #Sequence
            new_node = Sequence(name="Sequence")
            new_node.parent_node = current_node
            new_node.child_nodes = []
            current_node.child_nodes.append(new_node)

        elif char == "[":
            #Start children
            current_node = current_node.child_nodes[-1]

        elif char == "]":
            #End children
            current_node = current_node.parent_node

        elif char.isupper():
            #Check
            new_node = Check(node_dict[char])
            new_node.parent_node = current_node
            current_node.child_nodes.append(new_node)

        elif char.islower():                   
            #Action
            new_node = Action(node_dict[char])
            new_node.parent_node = current_node
            current_node.child_nodes.append(new_node)  
    logging.info('\n Decoded tree as: ' + root.tree_to_string())

    return root   
示例#27
0
def generate_tree(root):
    num_children = random.randint(2, 5)
    while True:

        is_composite = random.randint(0, 100) < 10
        if is_composite:
            new_class = ["-", Selector] if random.randint(
                0, 2) == 0 else ["_", Sequence]
        else:
            new_class = random.choice(list(node_dict.items()))

        if new_class[1] == Selector:

            new_node = Selector(name="Selector")
            new_node.child_nodes = []
            new_root = generate_tree(new_node)
            new_root.parent_node = root
            root.child_nodes.append(new_root)

        elif new_class[1] == Sequence:

            new_node = Sequence(name="Sequence")
            new_node.child_nodes = []
            new_root = generate_tree(new_node)
            new_root.parent_node = root
            root.child_nodes.append(new_root)

        elif new_class[0].isupper():
            new_node = Check(new_class[1])
            new_node.parent_node = root
            root.child_nodes.append(new_node)

        elif new_class[0].islower():
            new_node = Action(new_class[1])
            new_node.parent_node = root
            root.child_nodes.append(new_node)

        if num_children > 0:
            num_children -= 1
        if num_children <= 0:
            break
    return root
示例#28
0
def parse_tree(tree_string):

    root = Selector(name="Root")

    #Current node has the current selector or sequence that we are processing
    current_node = root

    for char in tree_string[1,-1]:
        if char == "-":
            #Selector
            new_node = Selector(name="Selector")
            new_node.parent = current_node
            current_node.child_nodes.append(new_node)

        elif char == "_":
            #Sequence
            new_node = Selector(name="Sequence")
            new_node.parent = current_node
            current_node.child_nodes.append(new_node)

        elif char == "[":
            #Start children
            current_node = current_node.child_nodes[-1]

        elif char == "]":
            #End children
            current_node = current_node.parent_node

        elif char.isupper():
            #Check
            new_node = Check(node_dict(char))
            new_node.parent_node = current_node
            current_node.child_nodes.append(new_node)

        elif char.islower():                   
            #Action
            new_node = Action(node_dict(char))
            new_node.parent_node = current_node
            current_node.child_nodes.append(new_node)  

    return root   
示例#29
0
def setup_behavior_tree():
    logging.info('Setting Up Behavior Tree')
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    logging.info('Root Defined')

    play_offensively = Sequence(name='Offensive Tactics')
    winning_check = Check(have_most_planets)
    play_defensively = Sequence(name='Defensive Tactics')
    losing_check = Check(have_least_planets)
    logging.info('Offensive - Defensive Check Defined')

    early_occupy = Sequence(name='Early Occupation of Neutrals')
    owned_planets_check = Check(low_planets_check)
    occupy = Action(occupy_nearest_neutral_planet)
    early_occupy.child_nodes = [owned_planets_check, occupy]
    logging.info('Occupation Strategy Defined')

    offensive_plan = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offensive_plan.child_nodes = [largest_fleet_check, attack]
    logging.info('Offensive Strategy Defined')

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread_sequence.child_nodes = [neutral_planet_check, spread_action]
    logging.info('Spread Sequence Defined')

    defensive_plan = Sequence(name='Defensive Strategy')
    smallest_fleet_check = Check(have_smallest_fleet)
    reinforce = Action(reinforce_weakest_planet)
    defensive_plan.child_nodes = [smallest_fleet_check, reinforce]
    logging.info('Defensive Strategy Defined')

    play_offensively.child_nodes = [
        winning_check, early_occupy, offensive_plan, spread_sequence
    ]
    play_defensively.child_nodes = [
        losing_check, early_occupy, defensive_plan, spread_sequence
    ]

    root.child_nodes = [play_offensively, play_defensively, occupy.copy()]
    logging.info('Children Assigned')

    logging.info('\n' + root.tree_to_string())
    return root
示例#30
0
def setup_behavior_tree():

    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')
    # This sequence is only executed at the beginning of the game,
    # it spreads to the 4 weakest/nearest planets to establish a foothold
    initialize_sequence = Sequence(name='Initialize Sequence')
    start = Check(is_start)
    fleet_check = Check(fleets)
    spread_action = Action(spread_to_closest_weak_planets)
    initialize_sequence.child_nodes = [start, fleet_check, spread_action]

    # This is the plan of attack that is used throughout the bots strategy
    # The bot checks to see if it has an arbitrarily set strong enough store of ships on its planet
    # and attacks enemy or neutral planets with those numbers.
    attack_plan = Sequence(name='Attacking Plan')
    strong_fleet = Check(strong_fleet_check)
    attack = Action(strong_attack)
    attack_plan.child_nodes = [strong_fleet, attack]

    # This strategy is executed when the bot is losing, it will begin to attack the enemy more agressively,
    # taking the enemies weakest planets to regain ground
    less_planet_strategy = Sequence(name='Losing Plan')
    less_planets = Check(planet_control_check)
    take_weakest_planet = Action(take_weakest_planets)
    attack_spread = Action(spread)
    less_planet_strategy.child_nodes = [
        less_planets, take_weakest_planet, attack_spread
    ]

    # This strategy executes when the bot is winning.
    # It will shift into a defensive mode, reinforcing currently owned planets while still seeking to spread
    more_planet_strategy = Sequence(name='Winning Plan')
    more_planets = Check(planet_control_check_winning)
    defend_planets = Action(defend)
    defense_spread = Action(spread)
    more_planet_strategy.child_nodes = [
        more_planets, take_weakest_planet, defend_planets, defense_spread
    ]

    root.child_nodes = [
        initialize_sequence, less_planet_strategy, more_planet_strategy,
        attack_plan
    ]

    logging.info('\n' + root.tree_to_string())
    return root
示例#31
0
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    spread_sequence = Sequence(name='Spread Strategy')
    neutral_planet_check = Check(if_neutral_planet_available)
    neutral_planet_check2 = Check(if_desirable_planet)
    spread_action = Action(spread_to_desirable_planet)
    spread_sequence.child_nodes = [
        neutral_planet_check, neutral_planet_check2, spread_action
    ]

    defend_planet = Sequence(name='Defense Strategy')
    enemy_attack_check = Check(enemy_attack)
    defend_action = Action(defend_friendly_planet)
    defend_planet.child_nodes = [enemy_attack_check, defend_action]

    optimal_offense = Sequence(name='Offensive Strategy')
    largest_fleet_check = Check(have_largest_fleet)
    desirable_planet_check = Check(if_desirable_attack)
    best_attack = Action(attack_desirable_planet)
    optimal_offense.child_nodes = [
        largest_fleet_check, desirable_planet_check, best_attack
    ]

    offense = Sequence(name='Offensive Strategy 2')
    largest_fleet_check2 = Check(have_largest_fleet)
    attack = Action(attack_weakest_enemy_planet)
    offense.child_nodes = [largest_fleet_check2, attack]

    reinforce = Sequence(name='Reinforce')
    reinforce_check = Check(low_count)
    reinforce_action = Action(reinforce_friendly_planet)
    reinforce.child_nodes = [reinforce_check, reinforce_action]

    spread2 = Sequence(name='Spread 2')
    neutral_planet_check = Check(if_neutral_planet_available)
    spread_action = Action(spread_to_weakest_neutral_planet)
    spread2.child_nodes = [neutral_planet_check, spread_action]

    root.child_nodes = [spread_sequence, offense, optimal_offense]
    #spread_sequence,defend_planet, reinforce, optimal_offense, spread2, offense

    logging.info('\n' + root.tree_to_string())
    return root
示例#32
0
def setup_behavior_tree():
    # Top-down construction of behavior tree
    root = Selector(name='High Level Ordering of Strategies')

    # Checks
    largest_fleet_check = Check(have_largest_fleet)
    enemy_planet_check = Check(if_enemy_planet_available)
    neutral_planet_check = Check(if_neutral_planet_available)

    # Spread to weakest neutral
    spread_orig = Sequence(name='Spread Original')
    # spread_orig = Selector(name='Spread Original')
    spread_orig_action = Action(spread_to_weakest_neutral_planet)
    spread_orig.child_nodes = [spread_orig_action]

    # Spread vanilla
    spread_vanilla_plan = Sequence(name='Spread Vanilla')
    # spread_vanilla_plan = Selector(name='Spread Vanilla')
    spread_vanilla_action = Action(spread_vanilla)
    spread_vanilla_plan.child_nodes = [spread_vanilla_action]

    # Spread to high growth rate
    spread_hgr_plan = Sequence(name='Spread High Growth Rate')
    # spread_hgr_plan = Selector(name='Spread High Growth Rate')
    spread_hgr_action = Action(spread_to_highest_growth_rate)
    spread_hgr_plan.child_nodes = [spread_hgr_action]

    # Spread default
    spread_def_plan = Sequence(name='Spread Default')
    # spread_def_plan = Selector(name='Spread Default')
    spread_def_action = Action(spread_default)
    spread_def_plan.child_nodes = [spread_def_action]

    # Attack Vanilla
    attack_plan = Sequence(name='Attack Vanilla')
    # attack_plan = Selector(name='Attack Vanilla')
    attack_action = Action(attack_vanilla)
    attack_plan.child_nodes = [attack_action]

    # Attack high growth rate
    attack_hgr_plan = Sequence(name='Attack High Growth Rate')
    # attack_hgr_plan = Selector(name='Attack High Growth Rate')
    attack_hgr_action = Action(attack_high_growth)
    attack_hgr_plan.child_nodes = [attack_hgr_action]

    # Attack-full
    attack_full = Sequence(name='Attack Full Sequence')
    attack_full.child_nodes = [largest_fleet_check, enemy_planet_check, attack_plan, attack_hgr_plan]

    # Spread-full
    spread_full = Sequence(name='Spread Full Sequence')
    spread_full.child_nodes = [neutral_planet_check, spread_def_plan, spread_hgr_plan, spread_vanilla_plan, spread_orig]

    root.child_nodes = [attack_full, spread_full, attack_action.copy(),
                        attack_hgr_action.copy(), spread_vanilla_action.copy(),
                        spread_orig_action.copy(), spread_def_action.copy(),
                        spread_hgr_action.copy()]
    logging.info('\n' + root.tree_to_string())
    return root