def createStrategy(self): # Select a random one. n = self.strategies[self.mathManager.randInt(0, len(self.strategies) - 1)] s = strategy.getStrategy(n) return s(self.m_battle, self)
def main(): global OutPath, deploy, args, stra parser = argparse.ArgumentParser() parser.add_argument("out") parser.add_argument("--outcsv") parser.add_argument("--num-eval", type=int, default=24 * 4) parser.add_argument("--deploy", action="store_true") parser.add_argument("--lag", type=int, default=12) parser.add_argument("--strategy", default='Strategy2') parser.add_argument("--num-leaves", type=int, default=31) parser.add_argument("--lr", type=float, default=0.05) parser.add_argument("--max-iter", type=int, default=400) parser.add_argument("--max-bin", type=int, default=255) parser.add_argument("--es", type=int, default=40) parser.add_argument("--num-threads", type=int, default=2) args = parser.parse_args() if args.deploy and args.outcsv is None: parser.error('--outcsv is required when --deploy is selected') OutPath = args.out #sys.argv[1] deploy = args.deploy if not os.path.exists(OutPath): os.makedirs(OutPath) st = time.time() stra = strategy.getStrategy(args.strategy, args) df = stra.dataset #create_dataset1('../data/data.csv', MaxLagging=args.lag) stations = set(df['stationId']) ans = pd.read_csv('../data/submit/sample_submissioin.csv') target_stations = list( set(map(lambda x: x.split('#')[0], ans[ans.columns[0]]))) # ans = pd.read_csv('../../kdd/ans3.csv') # ans2 = ans.copy() # ans3 = ans.copy() fix_map = fix(target_stations, stations) print(target_stations, len(target_stations)) score_table = {'stationId': [], 'PM2.5': [], "PM10": [], "O3": []} import_table = None for (idx, _s) in enumerate(target_stations): s = fix_map[_s] score_table['stationId'].append(s) print('=====>%d/%d %s->%s' % (idx, len(target_stations), _s, s)) if not os.path.exists(os.path.join(OutPath, s)): os.mkdir(os.path.join(OutPath, s)) for t in ['PM2.5', 'PM10', 'O3']: import_table = work(df, import_table, t, s, _s, score_table, ans) if not deploy: pd.DataFrame(score_table).to_csv(os.path.join(OutPath, 'score.csv')) import_table.to_csv(os.path.join(OutPath, 'import_table.csv')) pd.DataFrame(import_table.groupby(['gas', 'feature']).mean()).reset_index()\ .sort_values(by=['gas', 'importance'], ascending=False).to_csv(os.path.join(OutPath, 'import_table_sorted.csv')) if deploy: ans.to_csv(args.outcsv, index=False) print('elapsed time={}s'.format(time.time() - st))
def createStrategy(self): a = None while a is None and self.inputManager.running(): a = self.menu.pop() if self.inputManager.running(): s = strategy.getStrategy(a.name) # Add experience and growth for this chosen strategy. self.experience.add(a.name, 1) self.growth.add(a.name, 1) return s(self.m_battle, self) else: return None
def addGrowthPoints(self, points): self.growth.add("points", points) # 'Level up' while self.growth.get("points") >= self.growth.get("needed"): s = float(sum(map(lambda n: self.growth.get(n), self.strategies))) relative = map(lambda n: float(self.growth.get(n)) / float(s), self.strategies) for i in range(len(self.strategies)): sn = self.strategies[i] strat = strategy.getStrategy(sn) self.status.add( "strength", int(round(relative[i] * float(strat.strength)))) self.status.add("defense", int(round(relative[i] * float(strat.defense)))) self.status.add("magic", int(round(relative[i] * float(strat.magic)))) self.status.add( "resistance", int(round(relative[i] * float(strat.resistance)))) self.status.add("maxhealth", int(s)) self.status.set("health", self.status.get("maxhealth")) # Update needed points self.growth.set("needed", int(float(self.growth.get("needed")) * 1.5)) self.growth.set("points", 0) for sn in self.strategies: self.growth.set(sn, 0) # Check for new strategies: for strat in strategy.all: # Unfortunately we need an instance of every strategy. inst = strat(None, None) if inst.isAvailableFor(self) and strat.name not in self.strategies: self.strategies += [strat.name] self.sceneManager.info(self.name.capitalize() + " learned strategy " + strat.name.capitalize() + "!")
def buildMenu(self): self.menu = menu.Menu(str(self.name.capitalize()), "Select behaviour for your combatant.") options = [] for sn in self.strategies: s = strategy.getStrategy(sn) added = False for sub in options: if sub.name == s.category and not added: sub.options += [menu.MenuItem(s.name, s.description)] added = True if not added: sub = menu.Menu(s.category, s.category.capitalize() + "-based strategies.") sub.options += [menu.MenuItem(s.name, s.description)] options += [sub] for sub in options: sub.setOptions() self.menu.setOptions(options) self.menu.leftBottom()