def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option( "--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if(options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if(options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) counter = 0 resources = player.get_resources() troops_home = player.get_troops() thief_tot = troops_home['thief']['home'] + troops_home['thief']['training'] if 500 > thief_tot: player.train_military({'thief': 500-thief_tot}, "EMERGENCY") resources = player.get_resources() while resources['Money'] > 250 and player.get_soldiers() > 0: counter +=1 if counter > 4: break spec_count = resources['Money'] / 250 troops={'d-spec': spec_count/3, 'o-spec': 2*(spec_count/3)} trained_troops = player.train_military(troops, "EMERGENCY") log.info("train_military(%s): %s" % (troops, trained_troops))
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option( "--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if(options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if(options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) log.info("Get five random kds") islandlist=[] island=random.randint(0,41) for _ in range(1,10): log.info(islandlist) while island in islandlist: island = random.randint(1,41) islandlist.append(island) for kd in range(1,10): log.info("Fetching kd:%d, island:%d" % (kd, island)) kd_info = player.get_kd_info(kd,island) kd_json = json.dumps(kd_info).replace("'",'"') with open("%d-%d.txt"%(kd,island),'w') as f: f.write(kd_json) # post to db values={"textarea": kd_json} data = urllib.urlencode(values) headers={} log.debug("Posting %s to 127.0.0.1.", kd_json) req = urllib2.Request("http://127.0.0.1:5006/post_kd/", data, headers) urllib2.urlopen(req) time.sleep(random.randint(4,10)) print "DONE"
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option("--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if (options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if (options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) log.info("Get five random kds") islandlist = [] island = random.randint(0, 41) for _ in range(1, 10): log.info(islandlist) while island in islandlist: island = random.randint(1, 41) islandlist.append(island) for kd in range(1, 10): log.info("Fetching kd:%d, island:%d" % (kd, island)) kd_info = player.get_kd_info(kd, island) kd_json = json.dumps(kd_info).replace("'", '"') with open("%d-%d.txt" % (kd, island), 'w') as f: f.write(kd_json) # post to db values = {"textarea": kd_json} data = urllib.urlencode(values) headers = {} log.debug("Posting %s to 127.0.0.1.", kd_json) req = urllib2.Request("http://127.0.0.1:5006/post_kd/", data, headers) urllib2.urlopen(req) time.sleep(random.randint(4, 10)) print "DONE"
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option( "--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if(options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if(options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) available_spells = player.get_available_spells() log.debug("available_spells: %s" % available_spells) active_spells = player.get_active_spells() resources = player.get_resources() if 'Patriotism' in available_spells: #Check for presence in available spells (to avoid a future KeyError exception) if 'Patriotism' not in active_spells: # If the spell is not active, set it to -1 (again, to avoid KeyError exeptions) active_spells['Patriotism'] = -1 while active_spells['Patriotism'] <= 1 and resources['Runes'] > available_spells['Patriotism'][1] and 20 < player.get_mana(): if player.cast_spell('Patriotism') is not None: log.info("Cast Patriotism: Success") break log.info("Cast Patriotism: Failed") resources = player.get_resources() log.info("Cast Patriotism: Done") resources = player.get_resources() if 'Fertile Lands' in available_spells: if 'Fertile Lands' not in spells: active_spells['Fertile Lands'] = -1 while active_spells['Fertile Lands'] <= 1 and resources['Food'] < 20000 and resources['Runes'] > available_spells['Fertile Lands'][1] and 20 < player.get_mana(): if player.cast_spell('Fertile Lands') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fertile Lands: Done") resources = player.get_resources() if 'Love and Peace' in available_spells: if 'Love and Peace' not in active_spells: active_spells['Love and Peace'] = -1 while active_spells['Love and Peace'] <= 1 and resources['Runes'] > available_spells['Love and Peace'][1] and 20 < player.get_mana(): if player.cast_spell('Love and Peace') is not None: log.info("Cast Love and Peace: Success") break log.info("Cast Love and Peace: Failed") resources = player.get_resources() log.info("Cast Love and Peace: Done") resources = player.get_resources() print "DONE"
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option( "--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if(options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if(options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) log.info("Get five random kds") for _ in range(5): kd = random.randint(1,10) island = random.randint(1,40) log.info("Fetching kd:%d, island:%d" % (kd, island)) kd_info = player.get_kd_info(kd,island) kd_json = json.dumps(kd_info).replace("'",'"') with open("%d-%d.txt"%(kd,island),'w') as f: f.write(kd_json) # post to db values={"textarea": kd_json} data = urllib.urlencode(values) headers={} req = urllib2.Request("127.0.0.1:5001/post_kd/", data, headers) mana = player.get_mana() available_spells = player.get_available_spells() log.debug("available_spells: %s" % available_spells) spells = player.get_active_spells() resources = player.get_resources() # First and foremost, Make sure we have Minor Protection if 'Minor Protection' in available_spells: if 'Minor Protection' not in spells: spells['Minor Protection'] = 0 while spells['Minor Protection'] <= 1 and resources['Runes'] > available_spells['Minor Protection'][1] and 20 < player.get_mana(): if player.cast_spell('Minor Protection') is not None: log.info("Cast Minor Protection: Success") break log.info("Cast Minor Protection: Failed") resources = player.get_resources() log.info("Cast Minor Protection: Done") resources = player.get_resources() # if we got plague, remove it. # Because we still don't detect plague-removal, we reload the throne page on each iteraton if "Nature's Blessing" in available_spells: if "Nature's Blessing" not in spells: spells["Nature's Blessing"] = 0 while player.get_plague() and spells["Nature's Blessing"] <= 1 and resources['Runes'] > available_spells["Nature's Blessing"][1] and 10 < player.get_mana(): if player.cast_spell("Nature's Blessing") is not None: log.info("Cast Nature's Blessing: Success") break log.info("Cast Nature's Blessing: Failed") resources = player.get_resources() log.info("Cast Nature's Blessing: Done") resources = player.get_resources() # If we are low on food, make sure we cast Fertile lands. if 'Fertile Lands' in available_spells: if 'Fertile Lands' not in spells: spells['Fertile Lands'] = 0 while spells['Fertile Lands'] <= 1 and resources['Food'] < 30000 and resources['Runes'] > available_spells['Fertile Lands'][1] and 20 < player.get_mana(): if player.cast_spell('Fertile Lands') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fertile Lands: Done") # If we are low on food, make sure we cast Fertile lands. if 'Fountain of Knowledge' in available_spells: if 'Fountain of Knowledge' not in spells: spells['Fountain of Knowledge'] = 0 while spells['Fountain of Knowledge'] <= 1 and resources['Runes'] > available_spells['Fountain of Knowledge'][1] and 20 < player.get_mana(): if player.cast_spell('Fountain of Knowledge') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fontain of Knowledge: Done") counter = 0 resources = player.get_resources() while 20 < player.get_mana() and player.get_soldiers() > 0: counter +=1 if counter > 7: break resources = player.get_resources() leet_count = resources['Money'] / 500 while 1 > leet_count and player.get_mana() >= 20 and player.get_soldiers() > 0: counter += 1 if counter > 7: break player.cast_spell("Tree of Gold") available_spells = player.get_available_spells() resources = player.get_resources() leet_count = resources['Money'] / 500 #spec_count = resources['Money'] / 350 #troops={'o-spec': spec_count} troops={'elite': leet_count} trained_troops = player.train_military(troops) # if 1 > leet_count: # troops={'o-spec': spec_count} # if 1 > spec_count: # break # else: # troops={'elite': leet_count} log.info("train_military(%s): %s" % (troops, trained_troops)) # If we reach this point, and we're out of money. Let's try to spend our spec-credits resources = player.get_resources() if (0 < player.get_spec_credits() or 350 > resources['Money']) and 0 < player.get_soldiers(): troops={'o-spec': min(player.get_soldiers(), player.get_spec_credits())} trained_military = player.train_military(troops) log.debug("spec-credits: train_military(%s): %s" % (troops, trained_military)) info_msg = "" if 'Paradise' in available_spells: if resources['Runes'] > available_spells['Paradise']: info_msg = "Not enough runes (have: %s, need: %s)" % (resources['Runes'], available_spells['Paradise']) elif 10 >= player.get_mana(): info_msg = "Not enough mana (%s%)" % player.get_mana() else: while resources['Runes'] > available_spells['Paradise'][1] and 20 < player.get_mana(): result = player.cast_spell('Paradise') log.info("Cast Paradise - Result: %s" % result) resources = player.get_resources() else: info_msg = "Paradise not available to cast." log.info("Paradise done: %s"% info_msg) log.info("Prep building.") build_info = player.get_build_info() buildings = player.get_buildings() resources = player.get_resources() iterations_counter = 0 while 6 < iterations_counter and 0 < build_info['Total Undeveloped land'] and build_info['Construction Cost'] < resources['Money']: iterations_counter += 1 for k,v in buildings.items(): buildings[k]['total'] = v['built'] + v['incoming'] to_build = {} # min 8% farms if 0.08 < buildings['Farms']['total'] / build_info['Total Land']: to_build['Farms'] = int((0.07 - (buildings['Farms']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Farms'] : %s" % to_build['Farms']) if 0.15 < buildings['Guilds']['total'] / build_info['Total Land']: to_build['Guilds'] = int((0.15 - (buildings['Guilds']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Guilds'] : %s" % to_build['Guilds']) if 0.09 < buildings['Forts']['total'] / build_info['Total Land']: to_build['Forts'] = int((0.12 - (buildings['Forts']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Forts'] : %s" % to_build['Forts']) if 0.25 < buildings['Banks']['total'] / build_info['Total Land']: to_build['Banks'] = int((0.12 - (buildings['Banks']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Banks'] : %s" % to_build['Banks']) if 0.14 < buildings['Towers']['total'] / build_info['Total Land']: to_build['Towers'] = int((0.15 - (buildings['Towers']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Towers'] : %s" % to_build['Towers']) if 0.2 < buildings['Schools']['total'] / build_info['Total Land']: to_build['Schools'] = int((0.12 - (buildings['Schools']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Schools'] : %s" % to_build['Schools']) if 0.09 < buildings['Training Grounds']['total'] / build_info['Total Land']: to_build['Training Grounds'] = int((0.12 - (buildings['Training Grounds']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Training Grounds'] : %s" % to_build['Training Grounds']) if 0 <= len(to_build): log.info("No need to build anything.") break log.info("Want to build: %s"% to_build) player.build(to_build) log.info("build_info: %s" ,player.get_build_info()) log.info("buildings: %s", player.get_buildings()) build_info = player.get_build_info() resources = player.get_resources() if 0 < build_info['Total Undeveloped land']: # If we are low on food, make sure we cast Fertile lands. while 'Tree of Gold' in available_spells and resources['Runes'] > available_spells['Tree of Gold'][1] and 20 < player.get_mana() and player.cast_spell('Tree of Gold') is not None: resources = player.get_resources() # SCIENCE!!! available_books = player.get_science_info()['Books to Allocate'] if 3 < available_books: buy_sci = { "Alchemy": int(round(available_books/4)), "Tools": int(round(available_books/4)), "Housing": int(round(available_books/4)+random.randrange(0,10)), "Food": int(round(available_books/16)), "Military": int(round(available_books/16)), "Crime": int(round(available_books/16)), "Channeling": int(round(available_books/16)), } result = player.buy_science(buy_sci) info_msg="Bought science: %s"%result else: info_msg = "Less than 3 books (have: %s)"%available_books log.info("Buying science DONE: %s", info_msg) print "DONE"
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option( "--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if(options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if(options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) available_spells = player.get_available_spells() log.debug("available_spells: %s" % available_spells) active_spells = player.get_active_spells() resources = player.get_resources() def ensure_spells_are_cast(spells, active_spells, player): log.debug("ensure_spells_are_cast: {0}".format(spells)) resources = player.get_resources() for spell in spells: log.info("Trying to cast {0}.".format(spell)) if spell in available_spells: if spell not in active_spells: active_spells[spell] = 0 while active_spells[spell] <= 1 and resources['Runes'] > available_spells[spell][1] and 20 < player.get_mana(): if player.cast_spell(spell) is not None: log.info("Cast {0}: Success".format(spell)) break log.info("Cast {0}: Failed".format(spell)) resources = player.get_resources() log.info("Cast {0}: Done".format(spell)) resources = player.get_resources() spells = ['Minor Protection', 'Fertile Lands', 'Love and Peace', "Patriotism"] ensure_spells_are_cast(spells, active_spells, player) if "Nature's Blessing" in available_spells: while player.get_plague() and resources['Runes'] > available_spells["Nature's Blessing"][1] and 15 < player.get_mana(): if player.cast_spell("Nature's Blessing") is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() if 'Fertile Lands' in available_spells: if 'Fertile Lands' not in active_spells: active_spells['Fertile Lands'] = 0 while active_spells['Fertile Lands'] <= 1 and resources['Food'] < 20000 and resources['Runes'] > available_spells['Fertile Lands'][1] and 20 < player.get_mana(): if player.cast_spell('Fertile Lands') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fertile Lands: Done") resources = player.get_resources() # counter = 0 # resources = player.get_resources() # troops_home = player.get_troops() # thief_tot = troops_home['thief']['home'] + troops_home['thief']['training'] # thief_target = resources['Land'] * 2 # if thief_target > thief_tot: # player.train_military({'thief': thief_target-thief_tot}) # resources = player.get_resources() # while resources['Money'] > 500 and player.get_soldiers() > 0: # counter +=1 # if counter > 4: # break # spec_count = min(player.get_soldiers(), resources['Money'] / 500) # troops={'elite': (spec_count) } # trained_troops = player.train_military(troops) # log.info("train_military(%s): %s" % (troops, trained_troops)) # SCIENCE!!! available_books = player.get_science_info()['Books to Allocate'] if 3 < available_books: buy_sci = { "Alchemy": int(round(available_books)), #"Tools": int(round(available_books/7)), #"Housing": int(round(available_books/7)), #"Food": int(round(available_books/7)), #"Military": int(round(available_books/7)), #"Crime": int(round(available_books/7)), #"Channeling": int(round(available_books/7)), } result = player.buy_science(buy_sci) info_msg="Bought science: %s"%result else: info_msg = "Less than 3 books (have: %s)"%available_books log.info("Buying science DONE: %s", info_msg) print "DONE" # Dice cost *2 gives enough margin to cast all spels next cycle. # So, if we have dice cost *3, spend one dice if 'Paradise' in available_spells: while resources['Runes'] > available_spells['Paradise'][1]*3 and 20 < player.get_mana(): if player.cast_spell('Paradise') is not None: log.info("Cast Paradise: Success") break log.info("Cast Paradise: Failed") resources = player.get_resources() log.info("Cast Paradise: Done") #everything is looking good. # Lets fetch a few KDs and we 'target search' islandlist=[] island=random.randint(0,41) iterations = random.randint(3,10) for _ in range(iterations+1): log.info("Islandlist: %s" % islandlist) while island in islandlist: island = random.randint(1,41) islandlist.append(island) for kd in range(1,10): log.info("Fetching kd:%d, island:%d" % (kd, island)) kd_info = player.get_kd_info(kd,island) kd_json = json.dumps(kd_info).replace("'",'"') with open("%d-%d.txt"%(kd,island),'w') as f: f.write(kd_json) # post to db values={"textarea": kd_json} data = urllib.urlencode(values) headers={} log.debug("Posting %s to 127.0.0.1.", kd_json) req = urllib2.Request("http://127.0.0.1:5006/post_kd/", data, headers) urllib2.urlopen(req) time.sleep(random.randint(4,10))
def main(): parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Insturctions file (not yet implemented)") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Print lots of debug logging") parser.add_option("-l", "--log-level", dest="log_level", default=logging.WARN) parser.add_option("-c", "--config", help="Config file to read from (not implemented).") parser.add_option("--page-cache", help="Directory to dump pages to (for debugging only).") parser.add_option("-u", "--username", help="Username for player.") parser.add_option("-p", "--password", help="Password for player. (can be defined in conf too)") (options, args) = parser.parse_args() if (options.debug): options.log_level = 10 logging.basicConfig(level=int(options.log_level)) logging.basicConfig(level=logging.WARN) #Actual logic log.info("Instanciating player") player = UtopiaRobot() if (options.page_cache): player.page_cache = options.page_cache player.username = options.username log.info("set username = %s" % player.username) player.password = options.password log.info("set password = %s (masked)" % "".join(["*" for c in player.password])) log.info("Log in player (%s)...", player.username) log.info("Get five random kds") for _ in range(5): kd = random.randint(1, 10) island = random.randint(1, 40) log.info("Fetching kd:%d, island:%d" % (kd, island)) kd_info = player.get_kd_info(kd, island) kd_json = json.dumps(kd_info).replace("'", '"') with open("%d-%d.txt" % (kd, island), 'w') as f: f.write(kd_json) # post to db values = {"textarea": kd_json} data = urllib.urlencode(values) headers = {} req = urllib2.Request("127.0.0.1:5001/post_kd/", data, headers) mana = player.get_mana() available_spells = player.get_available_spells() log.debug("available_spells: %s" % available_spells) spells = player.get_active_spells() resources = player.get_resources() # First and foremost, Make sure we have Minor Protection if 'Minor Protection' in available_spells: if 'Minor Protection' not in spells: spells['Minor Protection'] = 0 while spells['Minor Protection'] <= 1 and resources[ 'Runes'] > available_spells['Minor Protection'][ 1] and 20 < player.get_mana(): if player.cast_spell('Minor Protection') is not None: log.info("Cast Minor Protection: Success") break log.info("Cast Minor Protection: Failed") resources = player.get_resources() log.info("Cast Minor Protection: Done") resources = player.get_resources() # if we got plague, remove it. # Because we still don't detect plague-removal, we reload the throne page on each iteraton if "Nature's Blessing" in available_spells: if "Nature's Blessing" not in spells: spells["Nature's Blessing"] = 0 while player.get_plague( ) and spells["Nature's Blessing"] <= 1 and resources[ 'Runes'] > available_spells["Nature's Blessing"][ 1] and 10 < player.get_mana(): if player.cast_spell("Nature's Blessing") is not None: log.info("Cast Nature's Blessing: Success") break log.info("Cast Nature's Blessing: Failed") resources = player.get_resources() log.info("Cast Nature's Blessing: Done") resources = player.get_resources() # If we are low on food, make sure we cast Fertile lands. if 'Fertile Lands' in available_spells: if 'Fertile Lands' not in spells: spells['Fertile Lands'] = 0 while spells['Fertile Lands'] <= 1 and resources[ 'Food'] < 30000 and resources['Runes'] > available_spells[ 'Fertile Lands'][1] and 20 < player.get_mana(): if player.cast_spell('Fertile Lands') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fertile Lands: Done") # If we are low on food, make sure we cast Fertile lands. if 'Fountain of Knowledge' in available_spells: if 'Fountain of Knowledge' not in spells: spells['Fountain of Knowledge'] = 0 while spells['Fountain of Knowledge'] <= 1 and resources[ 'Runes'] > available_spells['Fountain of Knowledge'][ 1] and 20 < player.get_mana(): if player.cast_spell('Fountain of Knowledge') is not None: log.info("Cast Fertile Lands: Success") break log.info("Cast Fertile Lands: Failed") resources = player.get_resources() log.info("Cast Fontain of Knowledge: Done") counter = 0 resources = player.get_resources() while 20 < player.get_mana() and player.get_soldiers() > 0: counter += 1 if counter > 7: break resources = player.get_resources() leet_count = resources['Money'] / 500 while 1 > leet_count and player.get_mana( ) >= 20 and player.get_soldiers() > 0: counter += 1 if counter > 7: break player.cast_spell("Tree of Gold") available_spells = player.get_available_spells() resources = player.get_resources() leet_count = resources['Money'] / 500 #spec_count = resources['Money'] / 350 #troops={'o-spec': spec_count} troops = {'elite': leet_count} trained_troops = player.train_military(troops) # if 1 > leet_count: # troops={'o-spec': spec_count} # if 1 > spec_count: # break # else: # troops={'elite': leet_count} log.info("train_military(%s): %s" % (troops, trained_troops)) # If we reach this point, and we're out of money. Let's try to spend our spec-credits resources = player.get_resources() if (0 < player.get_spec_credits() or 350 > resources['Money']) and 0 < player.get_soldiers(): troops = { 'o-spec': min(player.get_soldiers(), player.get_spec_credits()) } trained_military = player.train_military(troops) log.debug("spec-credits: train_military(%s): %s" % (troops, trained_military)) info_msg = "" if 'Paradise' in available_spells: if resources['Runes'] > available_spells['Paradise']: info_msg = "Not enough runes (have: %s, need: %s)" % ( resources['Runes'], available_spells['Paradise']) elif 10 >= player.get_mana(): info_msg = "Not enough mana (%s%)" % player.get_mana() else: while resources['Runes'] > available_spells['Paradise'][ 1] and 20 < player.get_mana(): result = player.cast_spell('Paradise') log.info("Cast Paradise - Result: %s" % result) resources = player.get_resources() else: info_msg = "Paradise not available to cast." log.info("Paradise done: %s" % info_msg) log.info("Prep building.") build_info = player.get_build_info() buildings = player.get_buildings() resources = player.get_resources() iterations_counter = 0 while 6 < iterations_counter and 0 < build_info[ 'Total Undeveloped land'] and build_info[ 'Construction Cost'] < resources['Money']: iterations_counter += 1 for k, v in buildings.items(): buildings[k]['total'] = v['built'] + v['incoming'] to_build = {} # min 8% farms if 0.08 < buildings['Farms']['total'] / build_info['Total Land']: to_build['Farms'] = int( (0.07 - (buildings['Farms']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Farms'] : %s" % to_build['Farms']) if 0.15 < buildings['Guilds']['total'] / build_info['Total Land']: to_build['Guilds'] = int( (0.15 - (buildings['Guilds']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Guilds'] : %s" % to_build['Guilds']) if 0.09 < buildings['Forts']['total'] / build_info['Total Land']: to_build['Forts'] = int( (0.12 - (buildings['Forts']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Forts'] : %s" % to_build['Forts']) if 0.25 < buildings['Banks']['total'] / build_info['Total Land']: to_build['Banks'] = int( (0.12 - (buildings['Banks']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Banks'] : %s" % to_build['Banks']) if 0.14 < buildings['Towers']['total'] / build_info['Total Land']: to_build['Towers'] = int( (0.15 - (buildings['Towers']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Towers'] : %s" % to_build['Towers']) if 0.2 < buildings['Schools']['total'] / build_info['Total Land']: to_build['Schools'] = int( (0.12 - (buildings['Schools']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Schools'] : %s" % to_build['Schools']) if 0.09 < buildings['Training Grounds']['total'] / build_info[ 'Total Land']: to_build['Training Grounds'] = int( (0.12 - (buildings['Training Grounds']['total'] / build_info['Total Land'])) * build_info['Total Land']) log.info("To build['Training Grounds'] : %s" % to_build['Training Grounds']) if 0 <= len(to_build): log.info("No need to build anything.") break log.info("Want to build: %s" % to_build) player.build(to_build) log.info("build_info: %s", player.get_build_info()) log.info("buildings: %s", player.get_buildings()) build_info = player.get_build_info() resources = player.get_resources() if 0 < build_info['Total Undeveloped land']: # If we are low on food, make sure we cast Fertile lands. while 'Tree of Gold' in available_spells and resources[ 'Runes'] > available_spells['Tree of Gold'][ 1] and 20 < player.get_mana() and player.cast_spell( 'Tree of Gold') is not None: resources = player.get_resources() # SCIENCE!!! available_books = player.get_science_info()['Books to Allocate'] if 3 < available_books: buy_sci = { "Alchemy": int(round(available_books / 4)), "Tools": int(round(available_books / 4)), "Housing": int(round(available_books / 4) + random.randrange(0, 10)), "Food": int(round(available_books / 16)), "Military": int(round(available_books / 16)), "Crime": int(round(available_books / 16)), "Channeling": int(round(available_books / 16)), } result = player.buy_science(buy_sci) info_msg = "Bought science: %s" % result else: info_msg = "Less than 3 books (have: %s)" % available_books log.info("Buying science DONE: %s", info_msg) print "DONE"