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); } }