Esempio n. 1
0
        public static IEnumerable <SC2APIProtocol.Action> MasterAgent_MainLoop(GameState gameState)
        {
            SC2GameState gs = new SC2GameState(gameState);

            SC2APIProtocol.Action answer = bot.Update(gs);
            yield return(answer);
        }
Esempio n. 2
0
 public void LoadGameState(String fileName)
 {
     currentGameState = new SC2GameState(fileName);
     RefreshPicScreen();
     Console.WriteLine("Score = " + currentGameState.NewObservation.Observation.Score.ToString());
     Console.WriteLine("AIActions = " + currentGameState.AIActions.ToStringEx());
 }
Esempio n. 3
0
 public void SetVariable(SC2GameState gameState)
 {
     this.gameState      = gameState;
     this.newObservation = gameState.NewObservation;
     this.gameLoop       = (int)newObservation.Observation.GameLoop;
     this.allUnits       = newObservation.Observation.RawData.Units.ToList();
     this.upgradeIDs     = newObservation.Observation.RawData.Player.UpgradeIds;
     this.enemyUnit      = GetEnemyUnits();
     this.myUnit         = GetMyUnits();
     this.baseLocations  = allUnits.FindBaseLocation();
 }
Esempio n. 4
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");
        }
Esempio n. 5
0
 public override void OnInit(SC2GameState gameState)
 {
     //Seqarch for ramp
     foreach (TerranBuildPattern tbp in TerranData.rampPattens)
     {
         List <Point2D> ramp = terrainHeightData.imgData.FindPattern(tbp.pattern);
         foreach (Point2D p in ramp)
         {
             Point2D gamePos = p.Clone();
             gamePos.Y         = terrainHeightData.imgData.Size.Y - gamePos.Y;
             rampData[gamePos] = tbp;
             logDebug("OnInit found ramp at " + p.ToString() + " game at " + gamePos.ToString());
         }
     }
 }
Esempio n. 6
0
        public override void Init(SC2GameState gameState)
        {
            logDebug(this.GetType().Name);
            startLocations = gameState.GameInfo.StartRaw.StartLocations.ToArray();


            terrainHeightData = new SC2ImageData(gameState.GameInfo.StartRaw.TerrainHeight);
            terrainHeightData.bmp.Save(@"TerrainHeight.png", ImageFormat.Png);
            terrainHeightData.imgData.Save(@"TerrainHeight.bin");
            terrainHeightData.imgData.ToDebugBitmap().Save(@"TerrainHeightDebug.png", ImageFormat.Png);

            placementData = new SC2ImageData(gameState.GameInfo.StartRaw.PlacementGrid);
            placementData.bmp.Save(@"PlacementGrid.png", ImageFormat.Png);
            placementData.imgData.Save(@"PlacementGrid.bin");
            placementData.imgData.ToDebugBitmap().Save(@"PlacementGridDebug.png", ImageFormat.Png);

            pathingGridData = new SC2ImageData(gameState.GameInfo.StartRaw.PathingGrid);
            pathingGridData.bmp.Save(@"PathingGrid.png", ImageFormat.Png);
            pathingGridData.imgData.Save(@"PathingGrid.bin");
            pathingGridData.imgData.ToDebugBitmap().Save(@"PathingGridDebug.png", ImageFormat.Png);

            OnInit(gameState);
        }
Esempio n. 7
0
 public virtual void OnInit(SC2GameState gameState)
 {
 }
Esempio n. 8
0
        public override SC2APIProtocol.Action Update(SC2GameState gameState)
        {
            SetVariable(gameState);
            SC2APIProtocol.Action answer = NewAction();
            coolDownCommand.Update(this.gameLoop);
            logPrintf("\n{0} Update {1} {2} {3}", this.GetType().Name, this.gameLoop, coolDownCommand.ToString(), this.upgradeIDs.ToString());
            if (gameState.NewObservation.Observation.GameLoop == prevStep)
            {
                logPrintf("Skip same step {0}", prevStep);
                return(answer);
            }
            prevStep = (int)gameState.NewObservation.Observation.GameLoop;
            logDebug(gameState.NewObservation.Observation.PlayerCommon.ToString());

            if (gameState.NewObservation.ActionErrors.Count > 0)
            {
                logDebug("ActionErrors " + gameState.NewObservation.ActionErrors.ToString());
            }
            if (first)
            {
                first = false;
                Init(gameState);
                return(answer);
            }
            if (gameLoop % 5 == 0)
            {
                if (GetBoolProperty("Log"))
                {
                    DumpUnits();
                    //DumpImage();
                }
            }
            //

            /*if (commandQueue.Count > 0)
             * {
             *  SC2Command cmd = commandQueue[0];
             *  commandQueue.RemoveAt(0);
             *  logPrintf("onCommand {0}", cmd.ToString());
             *  SC2APIProtocol.Action action = OnCommand(cmd);
             *  if (action != null)
             *  {
             *      return action;
             *  }
             * }*/
            // Create Tag here
            foreach (Unit a in allUnits)
            {
                if (!unitStates.ContainsKey(a.Tag))
                {
                    unitStates[a.Tag] = new SC2UnitState {
                        unit = a
                    };
                }
                else
                {
                    Unit u = unitStates[a.Tag].unit;
                    // update unit

                    /*if ((a.Health < u.Health) && a.HealthMax == u.HealthMax)
                     * {
                     *  logPrintf("HP DECREASE {0}",a.ToStringEx());
                     *  unitStates[a.Tag].isHPDecrease = true;
                     * }else
                     * {
                     *  unitStates[a.Tag].isHPDecrease = false;
                     * }*/
                    unitStates[a.Tag].unit = a;
                }
            }

            if (GetBoolProperty("Auto"))
            {
                SC2APIProtocol.Action ret = null;
                //DoIdle
                foreach (Unit a in myUnit.all)
                {
                    if (IsIdle(a))
                    {
                        SC2APIProtocol.Action action = DoIdle(a);
                        if (action != null)
                        {
                            logDebug("ACTION " + action.ToStringEx());
                            ret = action;
                        }
                    }
                }

                if (ret == null)
                {
                    ret = Process();
                    if (ret == null)
                    {
                        ret = answer;
                    }
                }
                if (ret.HasCommand())
                {
                    logDebug(ret.ToStringEx());
                }
                if (option.flgReadMode == false)
                {
                    Stream s = new FileStream(String.Format(@"{1}/{0:00000}.json", gameLoop, saveDirName), FileMode.Create);
                    gameState.CurrentAction = ret;
                    gameState.WriteTo(s);
                    s.Flush();
                    s.Close();
                }
                return(ret);
            }
            else
            {
                return(answer);
            }
        }
Esempio n. 9
0
 public abstract SC2APIProtocol.Action Update(SC2GameState gameState);
Esempio n. 10
0
 public abstract void Init(SC2GameState gameState);