double GetTeamBonusProfit(Bonus bonus, ref Trooper trooper, bool allowTakeBonus) { // нужен минимальный вес double bestWeight = Inf; foreach (var tr in Team) { double weight = GetShoterPath(tr, bonus, notFilledMap, beginFree: true, endFree: false) * (1 + 0.5 * GetQueuePlace(tr, self.Id == tr.Id && self.ActionPoints >= self.InitialActionPoints)); if (tr.Id != commander.Id || !allowTakeBonus) { var L = GetShoterPath(tr, bonus, map, beginFree: true, endFree: false); weight = L <= 2 && (self.Id != tr.Id || self.ActionPoints/GetMoveCost() >= 2*L) ? weight : Inf; } if (!IsHaveBonus(tr, bonus) && weight < bestWeight) { bestWeight = weight; trooper = tr; } } if (bestWeight >= Inf) return -1; return 1.0 / bestWeight; }
public World(int moveIndex, int width, int height, Player[] players, Trooper[] troopers, Bonus[] bonuses, CellType[][] cells, bool[] cellVisibilities) { this.moveIndex = moveIndex; this.width = width; this.height = height; this.players = new Player[players.Length]; Array.Copy(players, this.players, players.Length); this.troopers = new Trooper[troopers.Length]; Array.Copy(troopers, this.troopers, troopers.Length); this.bonuses = new Bonus[bonuses.Length]; Array.Copy(bonuses, this.bonuses, bonuses.Length); this.cells = new CellType[width][]; for (int x = 0; x < width; ++x) { this.cells[x] = new CellType[cells[x].Length]; Array.Copy(cells[x], this.cells[x], cells[x].Length); } this.cellVisibilities = cellVisibilities; }
private Bonus[] ReadBonuses() { int bonusCount = ReadInt(); if (bonusCount < 0) { return null; } Bonus[] bonuses = new Bonus[bonusCount]; for (int bonusIndex = 0; bonusIndex < bonusCount; ++bonusIndex) { if (ReadBoolean()) { bonuses[bonusIndex] = new Bonus(ReadLong(), ReadInt(), ReadInt(), (BonusType) ReadEnum()); } } return bonuses; }
bool IsHaveBonus(Trooper self, Bonus bonus) { return bonus != null && IsHaveBonus(self, bonus.Type); }