Created
August 6, 2019 06:31
-
-
Save lidorshimoni/edb59be03cac7827098c25c56459b11f to your computer and use it in GitHub Desktop.
toolkit bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weakest_enemies=0 | |
WEAKEST_ENEMIES_LIST_LENGTH = 5 | |
def find_strongest_allies(pw, x): | |
strongList = list() | |
i = 0 | |
if x > len(pw.enemy_planets()): | |
x = len(pw.enemy_planets()) | |
while i < x: | |
first = True | |
for planet in pw.my_planets(): | |
if first: | |
if planet not in strongList: | |
strong = planet | |
first = False | |
else: | |
if planet.num_ships() > strong.num_ships() and planet not in strongList: | |
strong = planet | |
strongList.append(strong) | |
i += 1 | |
return strongList | |
def find_weakest_enemies(pw, x): | |
weakList = list() | |
i = 0 | |
if x > len(pw.enemy_planets()): | |
x = len(pw.enemy_planets()) | |
while i < x: | |
first = True | |
for planet in pw.enemy_planets(): | |
if first: | |
if planet not in weakList: | |
weak = planet | |
first = False | |
else: | |
if planet.num_ships() < weak.num_ships() and planet not in weakList: | |
weak = planet | |
weakList.append(weak) | |
i += 1 | |
return weakList | |
def update_weakest_enemies(pw, x): | |
global weakest_enemies | |
if x > len(pw.enemy_planets()): | |
x = len(pw.enemy_planets()) | |
if x > weakest_enemies: | |
x = weakest_enemies | |
new_weakest_enemies = find_weakest_enemies(pw, x) | |
if weakest_enemies == 0 or len(weakest_enemies)==0: | |
weakest_enemies = new_weakest_enemies | |
return | |
for i in range(x): | |
if weakest_enemies[i].planet_id() != new_weakest_enemies[i].planet_id(): | |
weakest_enemies = new_weakest_enemies | |
return False | |
pw.debug("---------------------------") | |
return True | |
def zimbur(pw): | |
global weakest_enemies | |
if weakest_enemies==0 or len(weakest_enemies)==0: | |
update_weakest_enemies(pw, WEAKEST_ENEMIES_LIST_LENGTH) | |
if len(weakest_enemies)==0: | |
expand(pw) | |
return | |
target = weakest_enemies[0] | |
weakest_enemies.remove(target) | |
attacker = find_strongest_allies(pw, 1)[0] | |
attack_force = pw.distance(attacker, target) + target.num_ships() | |
if attack_force > attacker.num_ships(): | |
if attacker.num_ships()-5 > target.num_ships: | |
attack_force = attacker.num_ships()-15 | |
else: | |
return | |
pw.debug("mazamber on turn: " + str(pw.turn_number())) | |
pw.issue_order(attacker, target, attack_force) | |
class sourceDest: | |
source = 0 | |
dest = 0 | |
def expand(pw): | |
optional_targets = pw.neutral_planets() | |
black_list=[] | |
while len(optional_targets) >=1: | |
pw.debug(len(optional_targets)) | |
possibilites = list() | |
sd = sourceDest() | |
for des in optional_targets: | |
sd = sourceDest() | |
sd.dest = des | |
source = pw.my_planets()[0] | |
for planet in pw.my_planets(): | |
if pw.distance(source, des) > pw.distance(planet, des): | |
source = planet | |
else: | |
if pw.distance(source, des) == pw.distance(planet, des): | |
if planet.num_ships() > source.num_ships(): | |
source = planet | |
else: | |
if planet.num_ships() == source.num_ships() and source.growth_rate() < planet.growth_rate(): | |
source = planet | |
sd.source = source | |
possibilites.append(sd) | |
if len(possibilites)>0: | |
sd = possibilites[0] | |
for check in possibilites: | |
pw.debug("----" + str(black_list)) | |
if check.dest.planet_id() in black_list: | |
continue | |
price = sd.dest.num_ships() + pw.distance(sd.dest, sd.source) | |
if check.dest.num_ships() + pw.distance(check.dest, check.source) < price: | |
sd = check | |
else: | |
if check.dest.num_ships() + pw.distance(check.dest, check.source) == price: | |
if sd.dest.growth_rate() < check.dest.growth_rate(): | |
sd = check | |
if sd.dest.num_ships() + pw.distance(check.dest, check.source) > sd.source.num_ships(): | |
if sd.source.num_ships() < sd.dest.num_ships(): | |
num_ships = sd.source.num_ships() | |
else: | |
num_ships = sd.dest.num_ships() | |
else: | |
num_ships = sd.dest.num_ships() + pw.distance(check.dest, check.source) | |
if(num_ships>sd.source.num_ships()): | |
black_list.append(sd.dest.planet_id()) | |
continue | |
for fleet in pw.my_fleets(): | |
if fleet.destination_planet()==sd.dest.planet_id(): | |
black_list.append(sd.dest.planet_id()) | |
continue | |
pw.issue_order(sd.source, sd.dest, num_ships) | |
return | |
def expand2(pw): | |
pass | |
def help(pw, planet): | |
helper = find_strongest_allies(pw,1)[0] | |
pw.issue_order(helper, planet, planet.growth_rate()) | |
def do_turn(pw): | |
if(len(pw.my_fleets())>=30): | |
return; | |
if(len(pw.my_planets())==0): | |
return | |
if (len(pw.enemy_planets())==0): | |
return | |
if len(pw.my_planets())>9 or len(pw.neutral_planets()) == 0: | |
zimbur(pw) | |
return | |
# for planet in pw.my_planets(): | |
# if planet.num_ships() < planet.growth_rate(): | |
# help(pw, planet) | |
# return | |
expand(pw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment