void InitializeVariables() { this.troopers = world.Troopers; this.Bonuses = world.Bonuses; this.Cells = world.Cells; this.Width = world.Width; this.Height = world.Height; if (AlivePlayers == null) { AlivePlayers = new ArrayList(); foreach (var pl in world.Players) { AlivePlayers.Add(pl); } } if (map == null) { map = new int[Width, Height]; } if (notFilledMap == null) { notFilledMap = new int[Width, Height]; } for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { map[i, j] = Cells[i][j] == 0 ? 0 : 1; notFilledMap[i, j] = map[i, j]; } } if (CellDanger == null) { CellDanger = new double[Width, Height, 3]; CellDangerFrom = new double[Width, Height, 3]; CellDangerTo = new double[Width, Height, 3]; for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { if (notFilledMap[i, j] == 0) { for (var s = 0; s < 3; s++) { for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { if (notFilledMap[x, y] == 0) { for (var z = 0; z < 3; z++) { if (world.IsVisible(7, i, j, GetStance(s), x, y, GetStance(z))) { CellDangerFrom[i, j, s] += 1; CellDangerTo[x, y, z] += 1; } } } } } CellDanger[i, j, s] = CellDangerTo[i, j, s] / CellDangerFrom[i, j, s]; } } } } } Opponents = new Trooper[0]; Team = new Trooper[0]; Friends = new Trooper[0]; OpponentsMemoryAppearTime = new int[0]; OpponentsMemoryType = new TrooperType[0]; foreach (var tr in troopers) { map[tr.X, tr.Y] = 1; if (tr.IsTeammate) { Team = Append(Team, tr); if (tr.Id != self.Id) { Friends = Append(Friends, tr); } } else { Opponents = Append(Opponents, tr); OpponentsMemoryAppearTime = Append(OpponentsMemoryAppearTime, world.MoveIndex); OpponentsMemoryType = Append(OpponentsMemoryType, self.Type); } } if (MapHash == -1) { MapHash = GetMapHash(); #if DEBUG Console.WriteLine(MapHash); #endif } // Менять радиус в зависимости от количества оставшихся ходов: // Тогда будет возможность отбежать обратно MaxTeamRadius = 2; if (Team.Count() > 3 /* && self.ActionPoints >= 2*GetMoveCost(self)*/) { MaxTeamRadius += 1; } if (Team.Count() > 4) { MaxTeamRadius += 0.5; } if (MapHash == CheeserMap) { MaxTeamRadius += 4; } // Загружаем труперов с прошлого хода, и сохраняем с текущего // past - трупер // when - время, в которое был последний раз виден трупер // who - кто его видел последний раз for (var i = 0; i < PastTroopersInfo.Count; i += 3) { var past = PastTroopersInfo[i] as Trooper; var when = (int)PastTroopersInfo[i + 1]; var who = (TrooperType)PastTroopersInfo[i + 2]; if (world.MoveIndex - when > 2) { continue; } if (!Opponents.Any(trooper => trooper.Id == past.Id) && !IsVisible(past.X, past.Y)) { Opponents = Append(Opponents, past); OpponentsMemoryAppearTime = Append(OpponentsMemoryAppearTime, when); OpponentsMemoryType = Append(OpponentsMemoryType, who); troopers = Append(troopers, past); } } PastTroopersInfo.Clear(); for (var i = 0; i < Opponents.Count(); i++) { PastTroopersInfo.Add(GetClone(Opponents[i], 0)); PastTroopersInfo.Add(OpponentsMemoryAppearTime[i]); PastTroopersInfo.Add(OpponentsMemoryType[i]); } if (changedCommander != -1 && world.MoveIndex - changedCommander >= 3) { ChangeCommander(); } commander = GetCommander(); danger = new int[Width, Height]; foreach (var tr in Opponents) { for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { if (world.IsVisible(GetShootingRange(tr, tr.Stance), tr.X, tr.Y, tr.Stance, i, j, self.Stance)) { danger[i, j]++; } if (world.IsVisible(GetVisionRange(tr, self, self.Stance), tr.X, tr.Y, tr.Stance, i, j, self.Stance)) { danger[i, j]++; } } } } if (queue.Count == 0 || (long)queue[queue.Count - 1] != self.Id) { queue.Add(self.Id); TypeQueue.Add(self.Type); } }