Example #1
0
        private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ResponseObservation obs = new ResponseObservation();

            obs.Load(@"NewObservation.bin");

            List <Unit> allUnits  = obs.Observation.RawData.Units.ToList();
            ImageData   heightMap = new ImageData();

            heightMap.Load(@"TerrainHeight.bin");
            ImageData placeMap = new ImageData();

            placeMap.Load(@"PlacementGrid.bin");
            placeMap = SC2Bot.CreatePlaceableImageData(placeMap, allUnits);
            // collect base expansion
            List <Unit> gas = allUnits.GetUnits(UNIT_TYPEID.NEUTRAL_VESPENEGEYSER);

            //List<Point2D> points = allUnits.FindBaseLocation();
            Console.WriteLine("" + gas.Count);
            double[][] data = new double[gas.Count][];
            for (int i = 0; i < gas.Count; i++)
            {
                data[i] = new double[] { gas[i].Pos.X, gas[i].Pos.Y };
            }
            KMeans kmeans = new KMeans(k: gas.Count / 2);
            KMeansClusterCollection clusters = kmeans.Learn(data);
        }
Example #2
0
        public void RefreshPicScreen()
        {
            SC2GameState gs        = currentGameState;
            Bitmap       bmpHeight = gs.GameInfo.StartRaw.TerrainHeight.ToDebugBitmap(
                picScreenScale, gs.NewObservation.Observation.RawData.Units.ToList(), new ToDebugBitmapOption
            {
                flgDrawGrid    = chkDrawGrid.Checked,
                flgDrawGridPos = chkDrawPosition.Checked,
                flgDrawValue   = chkDrawValue.Checked,
                flgDrawTarget  = chkDrawTarget.Checked,
                flgColor       = true
            }
                );

            currentBot = new TerranBot();
            //bot.SetBoolProperty("Log", true);
            currentBot.SetVariable(currentGameState);
            if (currentBot.enemyUnit.all.Count() > 0)
            {
                List <Unit> units = currentBot.enemyUnit.all.GetUnitInRange(currentBot.myUnit.armyUnit);
                if (units.Count > 0)
                {
                    Console.WriteLine(units.ToString());
                    DrawUnit(bmpHeight, units, picScreenScale);
                }
            }
            // Draw action
            if (gs.CurrentAction.HasCommand())
            {
                foreach (ulong tag in gs.CurrentAction.ActionRaw.UnitCommand.UnitTags)
                {
                    Unit u = currentBot.allUnits.GetUnit(tag);
                    if (u != null)
                    {
                        DrawUnitAction(bmpHeight, u, picScreenScale, currentBot.allUnits, gs.CurrentAction.ActionRaw.UnitCommand);
                    }
                }
            }
            // Draw AI Action
            if (gs.AIActions.Count > 0)
            {
                foreach (SC2UnitAction aiAction in gs.AIActions)
                {
                    Unit u = currentBot.allUnits.GetUnit(aiAction.Tag);
                    if (u != null)
                    {
                        DrawUnitAction(bmpHeight, u, picScreenScale, currentBot.allUnits, aiAction.action.ActionRaw.UnitCommand, true);
                    }
                }
            }
            picScreen.Image = bmpHeight;
            //bmpHeight.Save("test.png");
        }