public Board(Config conf) { this.CurrentTick = 0; this.conf = conf; BoardObjects = new BoardObjects(conf); Diagonal = Convert.ToInt32(Math.Sqrt(Math.Pow(conf.BoardHeight, 2) + Math.Pow(conf.BoardWidth, 2))); }
private void nullTick(Player player, Coordinates baseCoords) { Base b = new Base(player); b.Coords = baseCoords; if (!BoardObjects.add(b)) { throw new RuntimeException("Could not add base"); } player.AI.nextTick(); }
private void merge(int x, int y, ref BoardObject[] result) { if (!BoardObjects.isValidCoords(x, y)) { return; } BoardObject[] boardObjectsFromCoords = BoardObjects.getBoardObjectsFromCoords(x, y); if (boardObjectsFromCoords.Length != 0) { ArrayUtils.merge(ref result, boardObjectsFromCoords); } }
internal void killBoardObject(ControllableBoardObject obj) { Ant ant = (obj as Ant); if (obj.isAnt() && ant.Inventory > 0) { Sugar s = new Sugar(); s.Coords = ant.Coords; s.Amount = ant.Inventory; BoardObjects.add(s); } BoardObjects.remove(obj); }
/// <summary> /// Ruft die AI auf und die AI jeder Ameise. /// </summary> public void nextTick() { CurrentTick++; foreach (Base playerbase in BoardObjects.getBases()) { playerbase.Player.AI.nextTick(); } IList <Ant> antList = BoardObjects.getRandomAnts(); for (int i = 0; i < antList.Count; i++) { Ant ant = antList[i]; ant.TookAction = false; ant.AI.antTick(getBoardObjectsInView(ant)); } }
private void mergeWithoutAnt(int x, int y, ref BoardObject[] result) { BoardObject[] boardObjectsFromCoords = BoardObjects.getBoardObjectsFromCoords(x, y).Clone() as BoardObject[]; if (boardObjectsFromCoords.Length - 1 != 0) { for (int i = 0; i < boardObjectsFromCoords.Length; i++) { BoardObject obj = boardObjectsFromCoords[i]; if (obj.isAnt()) { ArrayUtils.remove(ref boardObjectsFromCoords, obj); break; } } ArrayUtils.merge(ref result, boardObjectsFromCoords); } }
private void generateSugar(int min, int max) { Random rand = new Random(); int boardArea = conf.BoardHeight * conf.BoardWidth; double factor = Convert.ToDouble(rand.Next(min, max + 1)) / 100; int count = Convert.ToInt32(Math.Round(boardArea * factor)); for (int i = 0; i < count; i++) { Sugar s = new Sugar(); s.Coords = Utils.generateCoords(conf.BoardWidth, conf.BoardHeight); if (BoardObjects.hasBaseOnCoords(s.Coords) || BoardObjects.hasSugarOnCoords(s.Coords)) { i--; continue; } s.Amount = rand.Next(conf.SugarAmountMin, conf.SugarAmountMax + 1); BoardObjects.add(s); SugarAmount += s.Amount; } }