public override Direction CalculateMoveDirection() { //Set current cell Visit MapInfo.SetVisitTime(position); //Check visible user. If can see user "inform" all other tanks Vector2 userPos = MapInfo.GetUserVisiblePosition(position); if (userPos != Vector2.Zero) { MapInfo.SetUserPosition(userPos); UserVisibleDirection = AIUtils.GetMaxDirection(GetPosition - userPos); } else { UserVisibleDirection = Direction.None; } //Get User position. if == current lost user Vector2 userTankPosition = MapInfo.GetUserPosition(); if (userTankPosition == position) { LostUserPosition(); } if (MapInfo.UserDetected) { Vector2 difference = this.GetPosition - userTankPosition; if (SpriteUtils.IsYAxisFromDirection(_MoveDirection) && SpriteUtils.CoordinateEqualToZero((int)difference.Y) || !SpriteUtils.IsYAxisFromDirection(_MoveDirection) && SpriteUtils.CoordinateEqualToZero((int)difference.X)) { _MoveDirection = Direction.None; } if (!AllowedDirections.Contains(_MoveDirection)) { //Smart Algo Start Direction maxD = AIUtils.GetMaxDirection(this.GetPosition - userTankPosition); if (AllowedDirections.Contains(maxD)) { _MoveDirection = maxD; } else { Direction minD = AIUtils.GetMinDirection(this.GetPosition - userTankPosition); if (AllowedDirections.Contains(minD)) { _MoveDirection = minD; } else { if (CurrentMissle == null || CurrentMissle.State == SpriteState.Destroyed) { _MoveDirection = maxD; } else { if (AllowedDirections.Count > 0) { do { _MoveDirection = RandomUtils.GetRandomDirection(); } while (!AllowedDirections.Contains(_MoveDirection)); } else { _MoveDirection = Direction.None; } } } } } //Smart Algo End } else { if (!AllowedDirections.Contains(_MoveDirection) || movedDistance > Default.CellSetting.CellSize.X) { movedDistance = 0; _MoveDirection = MapInfo.GetOldestDirection(position, AllowedDirections); } movedDistance += speedValue; } return(_MoveDirection); }