Пример #1
0
        public static void RunMarineMicroGame(SynchronousApiClient client)
        {
            if (!client.InitiateSinglePlayerGame(MARINE_MICRO_MAP_PATH, Race.Terran))
            {
                return;
            }

            var gameState = client.GetGameState();

            IBot bot = new SimpleMarineBot();

            while (true)
            {
                if (exit)
                {
                    client.LeaveGame();
                    break;
                }
                else
                {
                    var commands = bot.Act(gameState);
                    client.SendCommands(commands);
                    client.Step();
                    gameState = client.GetGameState();
                }

                // Exit once all of our units are dead - probably not going to be what we do in the long run,
                // but it works for the example map we're currently on.
                if (gameState.RawUnits.All(unit => unit.Alliance == Alliance.Enemy))
                {
                    exit = true;
                }
            }
        }
Пример #2
0
        public static void RunEmptyMapGame(SynchronousApiClient client)
        {
            if (!client.InitiateSinglePlayerGame(EMPTY_MAP_PATH, Race.Terran))
            {
                return;
            }

            var gameState = client.GetGameState();

            var playerId = gameState.GameInfo.PlayerInfo[0].PlayerId;

            var debugRequest = new Request {
                Debug = new RequestDebug()
            };

            debugRequest.Debug.Debug.Add(new DebugCommand {
                GameState = DebugGameState.Minerals
            });
            debugRequest.Debug.Debug.Add(
                new DebugCommand
            {
                CreateUnit = new DebugCreateUnit
                {
                    Owner = (int)playerId,
                    Pos   = new Point2D {
                        X = 15f, Y = 15f
                    },
                    Quantity = 1,
                    UnitType = gameState.UnitTypes.Values.Single(unit => string.Equals(unit.Name, "SCV")).UnitId
                }
            });

            var debugResponse = client.Call(debugRequest);

            for (var i = 0; i < 20; i++)
            {
                client.Step();
            }

            gameState = client.GetGameState();

            // Broke this, probably not much point in fixing it
            //client.SendCommands(new[] { new BuildCommand(gameState.RawUnits[0], TerranBuildingType.SupplyDepot, 15, 15) });

            while (true)
            {
                client.Step();
                gameState = client.GetGameState();
            }
        }