async def starcraft_launch(ctx: SC2Context, mission_id):
    ctx.rec_announce_pos = len(ctx.items_rec_to_announce)
    ctx.sent_announce_pos = len(ctx.items_sent_to_announce)
    ctx.announcements_pos = len(ctx.announcements)

    sc2_logger.info(f"Launching {lookup_id_to_mission[mission_id]}. If game does not launch check log file for errors.")

    run_game(sc2.maps.get(maps_table[mission_id - 1]), [Bot(Race.Terran, ArchipelagoBot(ctx, mission_id),
                                                            name="Archipelago", fullscreen=True)], realtime=True)
Example #2
0
def run():
    args = parse_arguments()

    bot = load_bot(args)

    # The presence of a LadderServer argument indicates that this is a ladder game
    if args.LadderServer:
        # Ladder game started by LadderManager
        print("Starting ladder game...")
        result, opponentid = run_ladder_game(args, bot)
        print(result, " against opponent ", opponentid)
    else:
        # Local game
        print("Starting local game...")
        run_game(
            sc2.maps.get(args.Map),
            [
                bot,
                Computer(Race[args.ComputerRace],
                         Difficulty[args.ComputerDifficulty])
            ],
            realtime=args.Realtime,
            sc2_version=args.Sc2Version,
        )
Example #3
0
                    marine.attack(self.enemy_start_locations[0])
                for helion in self.units(UnitTypeId.HELLION).idle:
                    helion.attack(self.enemy_start_locations[0])
                for bc in self.units(UnitTypeId.BATTLECRUISER).idle:
                    bc.attack(self.enemy_start_locations[0])

            first_attack = True

        elif first_attack == True and self.all_own_units.amount > 5:
            if self.structures(
                    UnitTypeId.FUSIONCORE).ready.idle and self.structures(
                        UnitTypeId.STARPORT).ready.idle:
                for fc in self.structures(UnitTypeId.FUSIONCORE):
                    fc.research(UpgradeId.BATTLECRUISERENABLESPECIALIZATIONS)

            for all_units in self.all_own_units:
                all_units.attack(random.choice(self.enemy_structures))
                all_units.attack(self.enemy_start_locations[0])
                all_units.attack(random.choice(self.all_enemy_units))


run_game(  # run_game is a function that runs the game.
    maps.get("2000AtmospheresAIE"),  # the map we are playing on
    [
        Bot(Race.Terran, VAD3R_Bot()
            ),  # runs our coded bot, terran race, and we pass our bot object 
        Computer(Race.Terran, Difficulty.Hard)
    ],  # runs a pre-made computer agent, zerg race, with a Hard difficulty.
    realtime=
    False,  # When set to True, the agent is limited in how long each step can take to process.
)
Example #4
0
sys.path.insert(1, "sharpy-sc2")
sys.path.insert(1, os.path.join("sharpy-sc2", "python-sc2"))

from chance.chance import Chance
from sc2.player import Bot

from sc2.bot_ai import BotAI


class TestBot(BotAI):
    """A test bot that does nothing. This means we should always win."""
    async def on_step(self, iteration: int):
        pass


# Start game
if __name__ == '__main__':
    for race in Chance.AVAILABLE_STRATS.keys():
        for strat in Chance.AVAILABLE_STRATS[race]:
            print(f'Race {race}. Strat: {strat}.')
            bot: Bot = Bot(race, Chance(strat))
            test_bot: Bot = Bot(Race.Random, TestBot())
            result = run_game(maps.get("2000AtmospheresAIE"), [
                bot,
                test_bot,
            ],
                              realtime=False)
            if result == Result.Defeat:
                raise "Test failed - we were defeated (assumed crash)."
Example #5
0
        run_ladder_game(bot)
    else:
        # Local game
        print("Starting local game...")

        parser = argparse.ArgumentParser()
        parser.add_argument('--ForceRace',
                            type=str,
                            nargs="?",
                            help='Force a specific race')
        parser.add_argument('--ForceStrategy',
                            type=str,
                            nargs="?",
                            help='Force a specific strategy')
        args, _ = parser.parse_known_args()

        bot: Bot
        if args.ForceRace is None:
            bot = Bot(Race.Random, Chance())
        elif args.ForceStrategy is None:
            bot = Bot(race_map[args.ForceRace], Chance())
        else:
            bot = Bot(race_map[args.ForceRace], Chance(args.ForceStrategy))

        run_game(maps.get("2000AtmospheresAIE"), [
            bot,
            Computer(Race.Random, Difficulty.VeryHard),
        ],
                 save_replay_as=f'replays/replay.SC2Replay',
                 realtime=False)