def main(): # map = "ParaSiteLE" ''' map = random.choice( [ # Most maps have 2 upper points at the ramp (len(self.main_base_ramp.upper) == 2) "AutomatonLE", "BlueshiftLE", "CeruleanFallLE", "KairosJunctionLE", "ParaSiteLE", "PortAleksanderLE", "StasisLE", "DarknessSanctuaryLE", "ParaSiteLE", # Has 5 upper points at the main ramp "AcolyteLE", # Has 4 upper points at the ramp to the in-base natural and 2 upper points at the small ramp "HonorgroundsLE", # Has 4 or 9 upper points at the large main base ramp ] )sc2.run_game( sc2.maps.get(map), [Bot(Race.Terran, RampWallBot()), Computer(Race.Zerg, Difficulty.Hard)], realtime=True, # sc2_version="4.10.1", )''' sc2.run_game( sc2.maps.get("AutomatonLE"), [Human(Race.Terran, fullscreen=True), Bot(Race.Terran, RampWallBot())], realtime=True)
def stand_alone_game(bot): """ Play a game against the ladder build or test the bot against ingame ai """ print("Starting local game...") print("Play as human? (y / n)") input_human = input(">> ") if input_human and input_human.lower() == "y": races = ["p", "z", "t", "r"] race = None while race is None: print("Input your race (p / z / t / r):") human_race = input(">> ").lower() if human_race in races: if human_race == "p": race = Race.Protoss elif human_race == "z": race = Race.Zerg elif human_race == "t": race = Race.Terran elif human_race == "r": race = Race.Random else: print(f'"{human_race}" not recognized.') return sc2.run_game(sc2.maps.get("AcropolisLE"), [Human(race), bot], realtime=True) return sc2.run_game(sc2.maps.get("AcropolisLE"), [bot, Computer(Race.Random, Difficulty.VeryHard)], realtime=False,)
def _human( self ) -> Dict[str, Tuple[Callable[[List[str]], AbstractPlayer], Optional[LadderZip]]]: # Human, must be player 1 return { "human": ((lambda params: Human(races[BotDefinitions.index_check( params, 0, "random")])), None) }
def two_windows(): """ Runing two games windows, Bot() is our AI. Human() is human control :return: """ run_game(maps.get("AbyssalReefLE"), \ [Human(Race.Terran), \ Bot(Race.Zerg, SentdeBot())], \ realtime=True)
def main(): sc2.run_game( sc2.maps.get("Abyssal Reef LE"), [ Human(Race.Terran), # Bot(Race.Protoss, CannonRushBot()) Bot(Race.Zerg, ZergRushBot()) ], realtime=True)
def main(): sc2.run_game( sc2.maps.get("Abyssal Reef LE"), [ Human(Race.Protoss), # Bot(Race.Protoss, CannonRushBot()) # Bot(Race.Zerg, ZergRushBot()) Bot(Race.Zerg, BanelingBustBot()) ], realtime=False)
def main(): #sc2.run_game( #sc2.maps.get("Simple128"), #[Bot(Race.Protoss, ThreebaseVoidrayBot()), Computer(Race.Protoss, Difficulty.Easy)], #realtime=True, #) sc2.run_game( sc2.maps.get("AutomatonLE"), [Human(Race.Terran, fullscreen=True), Bot(Race.Protoss, ThreebaseVoidrayBot())], realtime=True )
def main(): # sc2.run_game( # sc2.maps.get("AutomatonLE"), # [Bot(Race.Zerg, Hydralisk()), Computer(Race.Terran, Difficulty.Medium)], # realtime=False, # save_replay_as="ZvT.SC2Replay", # ) sc2.run_game( sc2.maps.get("AutomatonLE"), [Human(Race.Terran, fullscreen=True), Bot(Race.Zerg, Hydralisk())], realtime=True)
def main(): '''sc2.run_game( sc2.maps.get("AcropolisLE"), [Bot(Race.Zerg, ExpandEverywhere()), Computer(Race.Terran, Difficulty.Medium)], realtime=False, save_replay_as="ZvT.SC2Replay", )''' sc2.run_game(sc2.maps.get("AutomatonLE"), [ Human(Race.Terran, fullscreen=True), Bot(Race.Zerg, ExpandEverywhere()) ], realtime=True)
def main(): map_name = "Flat128" rlBot = RL_Bot(map_name) # rlBot.test_tag = True # rlBot.map_name = map_name if not rlBot.test_tag: n_epsiodes = EPSIODES win_rate = [] while n_epsiodes >= 0: # 保存模型 if n_epsiodes % SAVE_CYCLE == 0: isExists = os.path.exists("economicFirst/model/" + map_name) if not isExists: os.makedirs("economicFirst/model/" + map_name) rlBot.saver.save(rlBot.session, "economicFirst/model/" + map_name + "/save.ckpt") r = sc2.run_game( sc2.maps.get(map_name), [Bot(Race.Terran, rlBot, name="RL_bot"), Computer(Race.Terran, Difficulty.VeryHard)], realtime=False, ) reward = get_reward(r) rlBot.memory.inQueue([rlBot.current_state, np.eye(rlBot.action_dim)[rlBot.action], reward, rlBot.next_state, 1]) rlBot.current_state = None rlBot.action = None rlBot.next_state = None rlBot.research_combatshield = 0 rlBot.eConcussiveshells = 0 n_epsiodes -= 1 if reward == 1: rlBot.win += 1 win_rate.append(rlBot.win / (EPSIODES - n_epsiodes)) isExists = os.path.exists("economicFirst/result/" + map_name) if not isExists: os.makedirs("economicFirst/result/" + map_name) np.save("economicFirst/result/" + map_name + '/win_rate', win_rate) print("epsiodes: %d win_rate: %f" % (EPSIODES - n_epsiodes, rlBot.win / (EPSIODES - n_epsiodes))) else: rlBot.saver.restore(rlBot.session, "economicFirst/model/" + map_name + "/save.ckpt") sc2.run_game( sc2.maps.get("LostAndFoundLE"), [Human(Race.Terran, fullscreen=True), Computer(Race.Protoss, Difficulty.Harder), #Bot(Race.Terran, rlBot, name="RL_bot") ], realtime=True, )
def stand_alone_game(bot): """ Play a game against the ladder build or test the bot against ingame ai """ print("Starting local game...") print("Play as human? (y / n)") input_human = input(">> ") map_name = "AcropolisLE" folder = os.path.join("data", "games") if not os.path.isdir(folder): os.mkdir(folder) time = datetime.now().strftime("%Y-%m-%d %H_%M_%S") if input_human and input_human.lower() == "y": races = ["p", "z", "t", "r"] race = None while race is None: print("Input your race (p / z / t / r):") human_race = input(">> ").lower() if human_race in races: if human_race == "p": race = Race.Protoss elif human_race == "z": race = Race.Zerg elif human_race == "t": race = Race.Terran elif human_race == "r": race = Race.Random else: print(f'"{human_race}" not recognized.') file_name = f"Human{race}_{map_name}_{time}" path = f"{folder}/{file_name}.log" LoggingUtility.set_logger_file( log_level=get_config(False)["general"]["log_level"], path=path) return sc2.run_game(sc2.maps.get(map_name), [Human(race), bot], realtime=True) file_name = f"IngameAI_{map_name}_{time}" path = f"{folder}/{file_name}.log" LoggingUtility.set_logger_file( log_level=get_config(False)["general"]["log_level"], path=path) return sc2.run_game( sc2.maps.get(map_name), [bot, Computer(Race.Random, Difficulty.VeryHard)], realtime=False, )
def main(): self_race_string = race_to_string[self_race] enemy_race_string = race_to_string[enemy_race] folder = folder_buildorder + self_race_string + race_bot_separator + enemy_race_string + ending_folder + map_name_strategy + ending_folder path_strategy = folder + file_strategy hash = get_buildorder_hash(path_strategy, method) time_string = str(round(time.time())) id = map_name + self_race_string + race_bot_separator + enemy_race_string + time_string + "_" + hash # Note replay will not be saved due to connectivity issues output_replay = folder_human_vs_bot + id + ending_sc2replay path = folder + hash + ending_csv sc2.run_game(sc2.maps.get(map_name), [ Human(self_race), Bot(enemy_race, Bot_AI_Extended(path, method = "Human", map = map_name)) ], realtime=True, save_replay_as= output_replay)
bot = Bot(Race.Protoss, MyBot()) #bot = Bot(Race.Random, ExampleBot()) #allmaps = ['AutomatonLE', 'CyberForestLE', 'KairosJunctionLE', 'KingsCoveLE', 'NewRepugnancyLE', 'PortAleksanderLE', 'YearZeroLE'] # all maps allmaps = ['EternalEmpireLE'] #, 'PortAleksanderLE', 'YearZeroLE'] # all maps #allmaps = ['DigitalFrontier'] # test maps only _difficulty = random.choice( [Difficulty.CheatInsane, Difficulty.CheatMoney, Difficulty.CheatVision]) _realtime = True _difficulty = Difficulty.CheatInsane #CheatInsane, CheatMoney, CheatVision _opponent = random.choice([Race.Zerg, Race.Terran, Race.Protoss, Race.Random]) _opponent = Race.Zerg # Start game if __name__ == '__main__': if "--LadderServer" in sys.argv: # Ladder game started by LadderManager print("Starting ladder game...") run_ladder_game(bot) else: # Local game print("Starting local game...") sc2.run_game( sc2.maps.get(random.choice(allmaps)), [Human(Race.Terran, fullscreen=True), Bot(Race.Protoss, MyBot())], realtime=_realtime)
def main(): sc2.run_game( sc2.maps.get("Catalyst LE"), [Human(Race.Terran), Bot(Race.Terran, Model2E())], realtime=True)
root_logger.removeHandler(handler) handler.close() def setup_bot(player: AbstractPlayer, bot_code, enemy_text: str, args): if isinstance(player, Bot) and hasattr(player.ai, "config"): my_bot: KnowledgeBot = player.ai my_bot.opponent_id = bot_code + "-" + enemy_text my_bot.run_custom = True if args.release: my_bot.config = get_config(False) enemies = { # Human, must be player 1 "human": (lambda params: Human(races[index_check(params, 0, "random")])), # Protoss "adept": (lambda params: Bot(Race.Protoss, AdeptRush())), "zealot": (lambda params: Bot(Race.Protoss, ProxyZealotRushBot())), "dt": (lambda params: Bot(Race.Protoss, DarkTemplarRush())), "stalker": (lambda params: Bot(Race.Protoss, MacroStalkers())), "4gate": (lambda params: Bot(Race.Protoss, Stalkers4Gate())), "robo":(lambda params: Bot(Race.Protoss, MacroRobo())), "voidray": (lambda params: Bot(Race.Protoss, MacroVoidray())), "cannonrush": (lambda params: Bot(Race.Protoss, CannonRush())), "randomprotoss": (lambda params: Bot(Race.Protoss, RandomProtossBot())), # Zerg "12pool": (lambda params: Bot(Race.Zerg, TwelvePool())), "200roach": (lambda params: Bot(Race.Zerg, MacroRoach())),
""" 和你创建的AI对战 """ from sc2 import run_game, maps, Race from sc2.player import Bot, Human # Import the library import sc2 # All bots inherit from sc2.BotAI class WorkerRushBot(sc2.BotAI): # The on_step function is called for every game step # It is defined as async because it calls await functions # It takes current game state and current iteration async def on_step(self, iteration): if iteration == 0: # If this is the first frame for worker in self.workers: # Attack to the enemy base with this worker # (Assumes that there is only one possible starting location # for the opponent, which depends on the map) await self.do(worker.attack(self.enemy_start_locations[0])) run_game(maps.get("AutomatonLE"), [ Human(Race.Terran), Bot(Race.Zerg, WorkerRushBot()) ], realtime=True)
'CyberForestLE', 'KairosJunctionLE', 'KingsCoveLE', 'NewRepugnancyLE' ] #, 'PortAleksanderLE', 'YearZeroLE'] # all maps #allmaps = ['DigitalFrontier'] # test maps only _difficulty = random.choice( [Difficulty.CheatInsane, Difficulty.CheatMoney, Difficulty.CheatVision]) _realtime = True _difficulty = Difficulty.CheatInsane #CheatInsane, CheatMoney, CheatVision _opponent = random.choice([Race.Zerg, Race.Terran, Race.Protoss, Race.Random]) _opponent = Race.Zerg # Start game if __name__ == '__main__': if "--LadderServer" in sys.argv: # Ladder game started by LadderManager print("Starting ladder game...") run_ladder_game(bot) else: # Local game print("Starting local game...") sc2map = sc2.maps.get(random.choice(allmaps)) print("Map: " + str(sc2map)) player1 = Human(Race.Terran, "guliver", True) print("Player1: " + str(player1)) player2 = Bot(Race.Protoss, MyBot()) print("Player2: " + str(player2)) sc2.run_game(sc2map, [player1, player2], realtime=_realtime)
def main(): run_game(map_finder(map_list[random.randrange(0, len(map_list))]), [ Bot(Race.Protoss, Protoss_Death_Ball()), # Computer(Race.Random, Difficulty.Hard) Human(Race.Random) ], realtime=True)