private void UseTorpedo(Instruction instruction) { var _useTorpedo = "0"; var associatedMessage = string.Empty; Console.Error.Write($"UseTorpedo"); MapCell cellToAttack = null; if (Enemy.CurrentPosition.Known) { _useTorpedo = "1"; var distance = Me.CurrentPosition.Distance(Enemy.CurrentPosition); if (distance <= Torpedo.Range) { cellToAttack = Map[Enemy.CurrentPosition]; } associatedMessage = $"[A] Position know - distance:{distance}"; } else if (Enemy.LastEstimatedPosition.Known) { _useTorpedo = "2"; var distance = Me.CurrentPosition.Distance(Enemy.LastEstimatedPosition); if (distance <= Torpedo.Range) { _useTorpedo = "2.1"; cellToAttack = Map[Enemy.LastEstimatedPosition]; } else if (distance > Torpedo.Range && distance < Torpedo.Range + 2) { _useTorpedo = "2.2"; var idealTarget = Enemy.LastEstimatedPosition; var actualPosition = Me.CurrentPosition; var lastPath = PathFinderHelpers.FindPath(actualPosition, idealTarget, Map, false); if (lastPath.Count >= Torpedo.Range) { cellToAttack = lastPath[Torpedo.Range - 2]; } } associatedMessage = $"[A] Estimated Position know - distance:{distance}"; } else { _useTorpedo = "3"; } // On se se tire pas dessus ! // On tire pas sur les iles if ( cellToAttack != null && ( cellToAttack.Position == Me.CurrentPosition || cellToAttack.Position.Distance(Me.CurrentPosition) <= 2 || cellToAttack.CellType == CellType.Island ) ) //&& Me.HealthPoint < Enemy.HealthPoint) { _useTorpedo = "4"; cellToAttack = null; associatedMessage = $"[A] Canceled shoot"; } if (cellToAttack != null) { instruction.Commands.Add(new Torpedo { Position = cellToAttack.Position }); associatedMessage += $" -- Me: {Me.CurrentPosition} shoot -> {cellToAttack.Position}"; // Console.Error.WriteLine($"Me: {Me.Position} shoot -> {cellToAttack.Position}"); } Console.Error.Write($"-> _useTorpedo: {_useTorpedo} - msg: {associatedMessage}"); }
private Direction MoveRandom(Instruction instruction) { var direction = Direction.None; var adjs = PathFinderHelpers.GetWalkableAdjacentSquares(Me.CurrentPosition, Map, null, true); if (adjs.Count > 0) { var p = adjs.First().Position; var d = Me.CurrentPosition.DirectionToTake(p); direction = d; } #region Poubelle //var section = Me.Position.Section; //switch (section) //{ // case 1: // case 2: // case 3: // // on est trop en haut // if (CanSouth) // direction = Direction.South; // else if (section == 1 && CanEst) // direction = Direction.Est; // else if (section == 3 && CanWest) // direction = Direction.West; // break; // case 4: // if (CanEst) // direction = Direction.Est; // else if (CanSouth) // direction = Direction.South; // break; // case 6: // if (CanWest) // direction = Direction.West; // else if (CanSouth) // direction = Direction.South; // break; // case 7: // case 8: // case 9: // // on est trop en bas // if (CanNorth) // direction = Direction.North; // else if (section == 7 && CanEst) // direction = Direction.Est; // else if (section == 9 && CanWest) // direction = Direction.West; // break; //} #endregion if (direction == Direction.None) { if (CanNorth) { direction = Direction.North; } else if (CanEst) { direction = Direction.Est; } else if (CanSouth) { direction = Direction.South; } else if (CanWest) { direction = Direction.West; } else { Console.Error.WriteLine("Will surface ..."); direction = Direction.None; instruction.Commands.Add(new Surface()); ResetVisitedCells(); Map[Me.CurrentPosition].Visited = true; } } // Je suppose que si je peux y aller je vais y aller Console.Error.WriteLine($"myPosition: {Me.CurrentPosition} - sector: {Me.CurrentPosition.Section} move to {direction.ToMove()}"); var newPosition = Me.CurrentPosition.NewPosition(direction); instruction.Commands.Add(new Move { Direction = direction, X = newPosition.X, Y = newPosition.Y }); return(direction); }