Example #1
0
        public async Task RunLadder(BotFactory botFactory, Race myRace, int gamePort, int startPort)
        {
            await Connect(gamePort);

            uint playerId = await JoinGameLadder(myRace, startPort);

            await Run(botFactory, playerId);
            await RequestLeaveGame();
        }
Example #2
0
        public async Task Run(BotFactory botFactory, uint playerId)
        {
            Request gameInfoReq = new Request();

            gameInfoReq.GameInfo = new RequestGameInfo();

            Response gameInfoResponse = await proxy.SendRequest(gameInfoReq);

            Request dataReq = new Request();

            dataReq.Data            = new RequestData();
            dataReq.Data.UnitTypeId = true;
            dataReq.Data.AbilityId  = true;
            dataReq.Data.BuffId     = true;
            dataReq.Data.EffectId   = true;
            dataReq.Data.UpgradeId  = true;

            Response dataResponse = await proxy.SendRequest(dataReq);

            var bot = botFactory.GetBot(gameInfoResponse.GameInfo, dataResponse.Data);

            while (true)
            {
                Request observationRequest = new Request();
                observationRequest.Observation = new RequestObservation();
                Response response = await proxy.SendRequest(observationRequest);

                if (response.Observation == null)
                {
                    continue;
                }
                ResponseObservation observation = response.Observation;

                if (response.Status == Status.Ended || response.Status == Status.Quit)
                {
                    break;
                }
                IEnumerable <SC2APIProtocol.Action> actions = bot.OnFrame(observation, playerId);

                Request actionRequest = new Request();
                actionRequest.Action = new RequestAction();
                actionRequest.Action.Actions.AddRange(actions);
                if (actionRequest.Action.Actions.Count > 0)
                {
                    await proxy.SendRequest(actionRequest);
                }

                Request stepRequest = new Request();
                stepRequest.Step       = new RequestStep();
                stepRequest.Step.Count = 1;
                await proxy.SendRequest(stepRequest);
            }
        }
Example #3
0
        public async Task RunSinglePlayer(BotFactory botFactory, string map, Race myRace, Race opponentRace, Difficulty opponentDifficulty)
        {
            var port = 5678;

            Logger.Info("Starting SinglePlayer Instance");
            StartSC2Instance(port);
            Logger.Info("Connecting to port: {0}", port);
            await Connect(port);

            Logger.Info("Creating game");
            await CreateGame(map, opponentRace, opponentDifficulty);

            Logger.Info("Joining game");
            uint playerId = await JoinGame(myRace);

            await Run(botFactory, playerId);
        }
Example #4
0
        public async Task RunLadder(BotFactory botFactory, Race myRace, string[] args)
        {
            CLArgs clargs = new CLArgs(args);

            await RunLadder(botFactory, myRace, clargs.GamePort, clargs.StartPort);
        }