public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); IStrategy[] strategies = new IStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(); } PlayerContext playerContext; while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } remoteProcessClient.WriteMovesMessage(moves); } } //catch (Exception e) //{ // File.WriteAllText("G:\\log.txt", e.Message + "\n" + e.StackTrace); //} finally { remoteProcessClient.Close(); } }
public void Run() { try { _remoteProcessClient.WriteTokenMessage(_token); _remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = _remoteProcessClient.ReadTeamSizeMessage(); Game game = _remoteProcessClient.ReadGameContextMessage(); IStrategy[] strategies = new IStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(); } PlayerContext playerContext; while ((playerContext = _remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } _remoteProcessClient.WriteMovesMessage(moves); } } finally { _remoteProcessClient.Close(); } }
public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); ExtendedRunnerModel extendedRunner = new ExtendedRunnerModel(game); VisualizerHost host = new VisualizerHost(extendedRunner); host.Start(); MyStrategy[] strategies = new MyStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(host.Visualizer); } PlayerContext playerContext; while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } extendedRunner.UpdatePlayerContext(playerContext); extendedRunner.OnBeforeMove(); Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } remoteProcessClient.WriteMovesMessage(moves); extendedRunner.OnAfterMove(); } host.Stop(); } finally { remoteProcessClient.Close(); } }
public static void RecheckNearestTrees() { #if DEBUG if (MyStrategy.World.TickIndex % 1000 == 999) { _prevSegments.Clear(); int found = 0; int errors = 0; for (var i = 0; i < GridSize; i++) { for (var j = 0; j < GridSize; j++) { var pt = new Point(i * CellLength, j * CellLength); var tr = GetNearestTree(pt); if (tr == null) { continue; } found++; var dst = pt.GetDistanceToCircle(tr); var trees = Trees.ToArray(); for (var k = 0; k < trees.Length; k++) { if (pt.GetDistanceToCircle(trees[k]) < dst) { _prevSegments.Add(new object[] { new List <Point> { pt, tr }, Pens.DarkOrange, 3 }); errors++; } } } } MyStrategy.Log("GetNearestTree errors " + errors + "/" + found); } Visualizer.Visualizer.SegmentsDrawQueue.AddRange(_prevSegments); #endif }
public static void Update() { MyStrategy.TimerStart(); CellLength = Const.MapSize / GridSize; var newState = new Dictionary <long, ATree>(); NewTrees.Clear(); DisappearedTrees.Clear(); foreach (var tree in MyStrategy.World.Trees) { var a = new ATree(tree); if (!_prevState.ContainsKey(tree.Id)) { // новое дерево NewTrees.Add(a); } newState[tree.Id] = a; } foreach (var it in _prevState) { if (!MyStrategy.IsPointVisible(it.Value)) { // его не видно, считаем что осталось newState[it.Key] = it.Value; } else if (!newState.ContainsKey(it.Key)) { // видно, но исчезло DisappearedTrees.Add(it.Value); } } _prevState = newState; _updateGrid(); MyStrategy.TimerEndLog("Update trees", 1); }
public static void Update() { foreach (var b in Bonuses) { for (var t = MyStrategy.PrevTickIndex + 1; t < MyStrategy.World.TickIndex; t++) // это если убили { b.SkipTick(); } } var interval = MyStrategy.Game.BonusAppearanceIntervalTicks; var newDict = new Dictionary <int, ABonus>(); var curStage = (MyStrategy.World.TickIndex - 1) / interval; foreach (var b in MyStrategy.World.Bonuses) { var visibleBonus = new ABonus(b); newDict[visibleBonus.Order] = visibleBonus; _lastVisibleStage[visibleBonus.Order] = curStage; } foreach (var oldBonus in _bonuses.Values) { if (!MyStrategy.IsPointVisible(oldBonus)) { // он точно не прилетел в World, т.к. не виден // остается на текущей тик oldBonus.SkipTick(); newDict[oldBonus.Order] = oldBonus; } else { _lastVisibleStage[oldBonus.Order] = curStage; if (!oldBonus.Exists && !newDict.ContainsKey(oldBonus.Order)) { // вижу, но он ещё не появился oldBonus.SkipTick(); if (!oldBonus.Exists) // если он не должен был появиться только что { newDict[oldBonus.Order] = oldBonus; } } } } for (var i = 0; i < 2; i++) { if (!newDict.ContainsKey(i)) { var remains = curStage > _lastVisibleStage[i] ? 0 : (MyStrategy.World.TickIndex == 0 ? interval + 1 : (interval - MyStrategy.World.TickIndex % interval) % interval + 1 ); if (MyStrategy.World.TickIndex + remains >= MyStrategy.Game.TickCount) { remains = 100500; } newDict[i] = new ABonus { X = Const.BonusAppearencePoints[i].X, Y = Const.BonusAppearencePoints[i].Y, Id = i - 2, RemainingAppearanceTicks = remains, Radius = MyStrategy.Game.BonusRadius, }; } } _bonuses = newDict; }
public static void Update() { var newState = new Dictionary <long, ABuilding>(); NewBuildings.Clear(); DisappearedBuildings.Clear(); foreach (var bld in MyStrategy.World.Buildings) { var a = new ABuilding(bld); var key = _getCoordinatesKey(a); if (!_prevState.ContainsKey(key)) { // новое здание NewBuildings.Add(a); } newState[key] = a; if (MyStrategy.World.TickIndex == 0) { var opposit = new ABuilding(bld); opposit.X = Const.MapSize - opposit.X; opposit.Y = Const.MapSize - opposit.Y; opposit.Faction = opposit.Faction == Faction.Academy ? Faction.Renegades : Faction.Academy; opposit.Id *= -1; // temp Id opposit.IsTeammate = false; var oppositKey = _getCoordinatesKey(opposit); if (!_prevState.ContainsKey(oppositKey)) { // новое здание NewBuildings.Add(opposit); } newState[oppositKey] = opposit; } } foreach (var it in _prevState) { var bld = it.Value; var key = _getCoordinatesKey(bld); if (!MyStrategy.IsPointVisible(bld)) { // его не видно, считаем что осталось if (bld.RemainingActionCooldownTicks == 0) { // значит, если кто-то был поблизости, башня 100% выстрелила if (MyStrategy.Combats.Any(x => x.IsTeammate && bld.GetDistanceTo2(x) <= Geom.Sqr(bld.CastRange))) { bld.RemainingActionCooldownTicks = (bld.IsBase ? MyStrategy.Game.FactionBaseCooldownTicks : MyStrategy.Game.GuardianTowerCooldownTicks) - 1; } } else { bld.RemainingActionCooldownTicks--; } newState[key] = bld; } else if (!newState.ContainsKey(key)) { // видно, но исчезло DisappearedBuildings.Add(bld); } } _prevState = newState; OpponentBase = Buildings.FirstOrDefault(x => x.IsBase && x.IsOpponent); MyBase = Buildings.FirstOrDefault(x => x.IsBase && x.IsTeammate); foreach (var building in Buildings) { if (building.IsBase) { building._isAssailable = Buildings.Count(x => x.Faction == building.Faction && x.Order == 1) < 3; } else { building._isAssailable = Buildings.Count( x => x.Faction == building.Faction && x.Order + 1 == building.Order && x.Lane == building.Lane) == 0; } } }