//private ICoordinates TargetMapTile { get; set; } //public CellAction(AvailableActions theAction, ICoordinates targetCell = null) public CellAction(AvailableActions theAction, IOffsetVector targetOffset = null) { this.Action = theAction; this.OffsetToTarget = targetOffset; //this.TargetMapTile = targetCell; }
/// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="coordinates"></param> /// <returns></returns> public Int16? DistanceTo(IOffsetVector offsetVector) { if (offsetVector == null) return null; return (Int16)(Math.Abs(offsetVector.X) + Math.Abs(offsetVector.Y)); }
/// <summary> /// Function returning a cell action indicating in which direction the cell should move to approach the given coordinates /// </summary> /// <param name="coordinates">The target coordinates</param> /// <returns>A cell action indicating how the cell should move to get there</returns> public AvailableActions GetRelativeMovment(IOffsetVector offsetVector) { var actions = new List<AvailableActions>(); if (offsetVector.Y > 0) actions.Add(AvailableActions.MOVEDOWN); if (offsetVector.Y < 0) actions.Add(AvailableActions.MOVEUP); if (offsetVector.X < 0) actions.Add(AvailableActions.MOVELEFT); if (offsetVector.X > 0) actions.Add(AvailableActions.MOVERIGHT); if (actions.Count > 0) return actions[RandomGenerator.GetRandomInt32(actions.Count)]; return AvailableActions.NONE; }
/// <summary> /// Tries to eat ressources present at the given coordinates /// </summary> /// <param name="offsetToTarget"></param> private void Eat(IOffsetVector offsetToTarget) { if (offsetToTarget == null) return; ICoordinates coordinates = new Coordinates(this.Position.X, this.Position.Y); coordinates.X += offsetToTarget.X; coordinates.Y += offsetToTarget.Y; Int16 ressourcesLeft = this.world.GetAmountOfRessourcesLeft(coordinates); Int16 lifeBonus = ressourcesLeft < Settings.Default.MaxEatingPerRoundQuantity ? ressourcesLeft : Settings.Default.MaxEatingPerRoundQuantity; if (lifeBonus > 0) { this.world.ReduceRessources(coordinates, lifeBonus); this.IncreaseLife(lifeBonus); } }
/// <summary> /// Tries to attack a cell in its direct proximity /// </summary> /// <param name="offsetToTarget"></param> private void Attack(IOffsetVector offsetToTarget) { if (offsetToTarget == null) return; ICoordinates coordinates = new Coordinates(this.Position.X, this.Position.Y); coordinates.X += offsetToTarget.X; coordinates.Y += offsetToTarget.Y; IInternalCell target = this.world.GetMap().GetCellAt(coordinates); if (target != null && target.GetLife() > 0) { target.DecreaseLife(Settings.Default.DamageOnOpponent); } }