Example #1
0
 public InfluenceMap(ProxyBot pData)
 {
     data = pData;
     groundInfluence = new float[data.Map.MapWidth, data.Map.MapHeight];
     flyingInfluence = new float[data.Map.MapWidth, data.Map.MapHeight];
     populateGroundInfluence();
 }
Example #2
0
        private void buildBarracksIfNeeded(ProxyBot bot, Dictionary<int, IUnitAgent> agents)
        {
            var barracks = (from b in buildings
                            where b.Type.ID == Constants.Terran_Barracks &&
                            b.PlayerID == bot.PlayerID
                            select b).ToList();
            if (barracks.Count == 0 &&
                !currentlyBuilding.Contains(Constants.Terran_Barracks))
            {
                //Check if we have enough resources for a barracks
                if (bot.Player.Race == Constants.Terran)
                {
                    if (bot.Player.Minerals > bot.unitTypes[Constants.Terran_Barracks].MineralsCost)
                    {
                        //Find the nearest minerals and build 15 tiles toward
                        //the centre
                        Unit nearestResource = null;
                        foreach (Unit u in bot.Units)
                        {
                            if (u.Type.ID != Constants.Resource_Mineral_Field)
                            {
                                continue;
                            }
                            if (nearestResource == null)
                            {
                                nearestResource = u;
                            }
                            else
                            {
                                if (center.distance(u) < center.distance(nearestResource))
                                {
                                    nearestResource = u;
                                }
                            }
                        }

                        int x = 0;
                        int y = center.Y;

                        if (center.X < bot.Map.MapWidth / 2)
                        {
                            x = nearestResource.X + 15;
                        }
                        else
                        {
                            x = nearestResource.X - 15;
                        }

                        if (bot.Map.isBuildable(x, y))
                        {
                            Unit u = getNearestWorker();
                            Worker workerAI = agents[u.ID] as Worker;
                            Console.Out.WriteLine("[Commander] Building barracks");
                            workerAI.Build(Constants.Terran_Barracks, x, y);
                            currentlyBuilding.Add(Constants.Terran_Barracks);
                        }
                    }
                }
            }
        }
Example #3
0
        public InfluenceMapGUI(float[,] pInfluence, ProxyBot bot)
        {
            InitializeComponent();

            influence = pInfluence;

            int width = influence.GetLength(0);
            int height = influence.GetLength(1);

            this.Width = width * tileSize;
            this.Height = height * tileSize;

            //Draw heat map
            // Create new memory bitmap the same size as the picture box
            Bitmap bMap = new Bitmap(this.Width, this.Height);

            // Call CreateIntensityMask, give it the memory bitmap, and store the result back in the memory bitmap
            bMap = CreateIntensityMask(bMap);

            int[,] influenceMap = new int[this.Width, this.Height];
            for (var x = 0; x < this.Width; x++)
            {
                for (var y = 0; y < this.Height; y++)
                {
                    influenceMap[x, y] = (int)Math.Floor(bMap.GetPixel(x, y).GetBrightness() * this.Width);
                }
            }

            // Colorize the memory bitmap and assign it as the picture boxes image
            this.BackgroundImage = bMap;//Colorize(bMap, 255);
        }
Example #4
0
        public virtual void Start(ProxyBot pProxy)
        {
            this.proxyBot = pProxy;

            int playerID = proxyBot.PlayerID;

            while (true)
            {
                try
                {
                    //UPGRADE_TODO: Method 'java.lang.Thread.sleep' was converted to 'System.Threading.Thread.Sleep' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangThreadsleep_long'"
                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 250));
                }
                catch (System.Exception)
                {
                }

                foreach(Unit unit in proxyBot.Units)
                {

                    // make idle works mine
                    if (unit.PlayerID == playerID && unit.Type.Worker)
                    {

                        if (unit.Order == Convert.ToInt32(Order.PlayerGuard))
                        {
                            int closestID = - 1;
                            //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MAX_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                            double closest = System.Double.MaxValue;

                            foreach(Unit patch in proxyBot.Units)
                            {

                                if (patch.Type.ID == Constants.Resource_Mineral_Field)
                                {

                                    double distance = (0.5 + new Random().NextDouble()) * unit.distance(patch);
                                    if (distance < closest)
                                    {
                                        closest = distance;
                                        closestID = patch.ID;
                                    }
                                }
                            }

                            if (closestID != - 1)
                            {
                                //System.Console.Out.WriteLine("Right on patch: " + unit.ID + " " + closestID);
                                proxyBot.rightClick(unit.ID, closestID);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public SpeedFrame(ProxyBot pProxy)
        {
            InitializeComponent();

            proxyBot = pProxy;

            //Init the track bar
            tbSpeed.SetRange(slowest, fastest);
            tbSpeed.Value = initialSpeed;

            tbSpeed.ValueChanged += new EventHandler(tbSpeed_ValueChanged);
        }
Example #6
0
        public StarCraftFrame(ProxyBot pProxy)
        {
            InitializeComponent();

            proxyBot = pProxy;

            this.Paint += new System.Windows.Forms.PaintEventHandler(StarCraftFrame_Paint);
            this.Load += new EventHandler(StarCraftFrame_Load);
            //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.MinimizeBox = true;
            this.MaximizeBox = false;
            this.ControlBox = false;
        }
Example #7
0
        public virtual void Start(ProxyBot pProxy)
        {
            this.proxyBot = pProxy;

            int playerID = proxyBot.PlayerID;

            //AI List
            Dictionary<int, IUnitAgent> agents = new Dictionary<int, IUnitAgent>();

            //Create the commander
            Commander commander = new Commander();

            while (true)
            {
                try
                {
                    //System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 250));
                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64)10000 * 500));
                }
                catch (System.Exception)
                {
                }

                foreach(Unit unit in proxyBot.Units)
                {
                    //Attach an AI to any new unit
                    foreach (Unit u in proxyBot.Units)
                    {
                        if (u.PlayerID == playerID)
                        {
                            if (!agents.Keys.Contains(u.ID))
                            {
                                agents.Add(u.ID, AgentFactory.AttachAgent(u, commander));
                            }
                        }
                    }

                    //Update from command centre
                    commander.Update(proxyBot, agents);

                    //Update the unit agents
                    foreach (KeyValuePair<int, IUnitAgent> kvp in agents)
                    {
                        if (kvp.Value != null)
                        {
                            kvp.Value.Update(proxyBot);
                        }
                    }
                }
            }
        }
Example #8
0
        public Toolbar(ProxyBot pProxyBot, StarCraftAgent pAgent)
        {
            InitializeComponent();

            proxyBot = pProxyBot;
            agent = pAgent;

            //Subscribe to events
            proxyBot.OnStarcraftConnected += new ProxyBot.ProxyBotDelegate(proxyBot_OnStarcraftConnected);

            //Set up status bar
            proxyStatus = new ToolStripStatusLabel("Proxy Bot: Waiting for Starcraft...");
            ssMainStatus.Items.Add(proxyStatus);
        }
Example #9
0
        public void Update(ProxyBot bot, Dictionary<int, IUnitAgent> agents)
        {
            //Track units
            updateUnits(bot);

            //Assign the center if we haven't done so
            if (center == null)
            {
                center = (from b in buildings
                          where b.Type.Center
                          select b).Single();
            }

            //If we have no barracks, build one
            buildBarracksIfNeeded(bot, agents);

            //If we have a barracks, and can affort marines, build some
            buildMarines(bot);
        }
Example #10
0
        public static void Main(System.String[] args)
        {
            StarCraftAgent agent = new StarCraftAgent();
            ProxyBot proxyBot = new ProxyBot(agent);
            proxyBot.showGUI = false;

            try
            {
                proxyBot.start();
            }
            catch (SocketException e)
            {
                e.WriteStackTrace(Console.Error);
                System.Environment.Exit(0);
            }
            catch (System.Exception e)
            {
                e.WriteStackTrace(Console.Error);
            }
        }
Example #11
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            StarCraftAgent agent = new StarCraftAgent();
            ProxyBot proxyBot = new ProxyBot(agent);
            proxyBot.showGUI = true;

            //Start the agent in it's own thread
            BackgroundWorker proxyBotBg = new BackgroundWorker();
            proxyBotBg.DoWork += new DoWorkEventHandler((object sender, DoWorkEventArgs e) =>
            {
                proxyBot.start();
            });
            proxyBotBg.RunWorkerAsync();

            //Sign up for the proxy bot connected event
            Toolbar toolbar = new Toolbar(proxyBot, agent);
            Application.Run(toolbar);
        }
Example #12
0
        private void updateUnits(ProxyBot bot)
        {
            //Reset the units
            units = new List<Unit>();
            buildings = new List<Unit>();

            foreach (Unit u in bot.Units)
            {
                if (u.PlayerID == bot.PlayerID)
                {
                    if (!u.Type.Building &&
                        u.Type.ID != Constants.Resource_Mineral_Field &&
                        u.Type.ID != Constants.Resource_Vespene_Geyser)
                    {
                        units.Add(u);
                    }

                    if (u.Type.Building)
                    {
                        buildings.Add(u);
                    }
                }
            }
        }
Example #13
0
 private void buildMarines(ProxyBot bot)
 {
     if (bot.Player.SupplyUsed < bot.Player.SupplyTotal &&
         bot.Player.Minerals > bot.unitTypes[Constants.Terran_Marine].MineralsCost + 100 &&
         !currentlyBuilding.Contains(Constants.Terran_Marine))
     {
         int barracksCount = (from b in buildings
                              where b.Type.ID == Constants.Terran_Barracks
                              select b).Count();
         if (barracksCount > 0 &&
             !currentlyBuilding.Contains(Constants.Terran_Barracks))
         {
             int barracksID = (from b in buildings
                               where b.Type.ID == Constants.Terran_Barracks
                               select b.ID).Single();
             currentlyBuilding.Add(Constants.Terran_Marine);
             bot.train(barracksID, Constants.Terran_Marine);
         }
     }
 }
Example #14
0
        public void Update(ProxyBot pBot)
        {
            //Update data
            bot = pBot;
            int updatedCount = 0;
            foreach (Unit u in bot.Units)
            {
                if (u.ID == unitID)
                {
                    unit = u;
                }
                if (buildingType > 0 && u.Type.ID == buildingType)
                {
                    updatedCount++;
                }
            }

            checkIfFinishedBuilding(updatedCount);

            if (currentState == State.IDLE)
            {
                //Figure out what to do, considering where the unit is
                //what's going on in the game, and what units are near it
                //For now, hard code it to mine
                Console.Out.WriteLine("[Worker] Mining");
                Mine();
            }
            else if (currentState == State.MOVING)
            {
                //If we're moving, we're on our way to build something.
                updateStateForBuilding();
            }
        }
Example #15
0
 public Map(ProxyBot pProxy)
 {
     proxyBot = pProxy;
 }