//Create empty document public static void Reset() { CurrentPath.Clear(); Document.Clear(); FileName = "untitled.md"; FilePath = null; }
public void CalculatePath() { List <Piece> tilesPath = new List <Piece>(); Dictionary <Piece, Piece> cameFrom = BreadthFirstSearch(); if (CurrentTarget == null) { return; } Piece current = Map[CurrentTarget.Y].Where(p => p.X == CurrentTarget.X).FirstOrDefault(); Piece start = Map[Head.Y].Where(p => p.X == Head.X).FirstOrDefault(); while (current != start) { tilesPath.Add(current); if (current != null) { cameFrom.TryGetValue(current, out current); } else { //Console.WriteLine("AI Snake can't find a way"); CurrentTarget = null; CurrentPath.Clear(); break; } } tilesPath.Append(start); tilesPath.Reverse(); CurrentPath = tilesPath; }
public void SimplePath() { // A simple heuristic that is engaged when there is no evident direct way to the target // If it detects an obstacle directly ahead, it tries to turn left or right //Console.WriteLine("SIMPLE PATH MODE ENGAGED"); CurrentTarget = null; CurrentPath.Clear(); int x = Head.X; int y = Head.Y; TranslateOnce(Head.MoveDirection, ref x, ref y); Direction headRight = ClockwiseDirection(Head.MoveDirection); Direction headLeft = InverseDirection(headRight); if (x < 0 || y < 0 || y >= Map.Count || x >= Map[0].Count || Map[y].Any(p => p.X == x && (p.Type == PieceType.Wall || p.Type == PieceType.SnakePiece))) { x = Head.X; y = Head.Y; TranslateOnce(ClockwiseDirection(Head.MoveDirection), ref x, ref y); if ((x < 0 || y < 0 || y >= Map.Count || x >= Map[0].Count) || Map[y].Any(p => p.X == x && (p.Type == PieceType.Wall || p.Type == PieceType.SnakePiece))) { ChangeDirection(InverseDirection(ClockwiseDirection(Head.MoveDirection))); //Console.WriteLine("TURNING LEFT"); } else { ChangeDirection(ClockwiseDirection(Head.MoveDirection)); //Console.WriteLine("TURNING RIGHT"); } } }
public void Reset() { if (CurrentPath == null) { CurrentPath = new Queue <Vector3>(); } Acceleration = new Vector3(0, 0, 0); CurrentPath.Clear(); }
public static void BuildPathToNote(Markdown.Item newCurrentNote) { CurrentPath.Clear(); while (newCurrentNote.Parent != null) { int i = newCurrentNote.Parent.Childs.IndexOf(newCurrentNote); if (i >= 0) { CurrentPath.Insert(0, i); } else { break; } newCurrentNote = newCurrentNote.Parent; } }
public void Relocate(IHexCell newLocation) { if (!CanRelocate(newLocation)) { throw new InvalidOperationException("CanRelocate must return true on the given arguments"); } if (CurrentPath != null) { CurrentPath.Clear(); } PositionCanon.ChangeOwnerOfPossession(this, newLocation); if (RelocationCoroutine != null) { StopCoroutine(RelocationCoroutine); } RelocationCoroutine = StartCoroutine(PlaceUnitOnGridCoroutine(newLocation.AbsolutePosition)); }
private IEnumerator PerformMovementCoroutine(bool ignoreMoveCosts, Action postMovementCallback) { Animator.SetTrigger("Moving Requested"); IHexCell startingCell = PositionCanon.GetOwnerOfPossession(this); IHexCell currentCell = startingCell; Vector3 currentLocation = Grid.PerformIntersectionWithTerrainSurface(currentCell.AbsolutePosition); Vector3 a, b, c = currentLocation; yield return(LookAt(CurrentPath.First().AbsolutePosition)); float t = Time.deltaTime * Config.TravelSpeedPerSecond; while ((ignoreMoveCosts || CurrentMovement > 0) && CurrentPath != null && CurrentPath.Count > 0) { var nextCell = CurrentPath.FirstOrDefault(); Vector3 nextLocation = Grid.PerformIntersectionWithTerrainSurface(nextCell.AbsolutePosition); if (!PositionCanon.CanChangeOwnerOfPossession(this, nextCell) || nextCell == null) { CurrentPath.Clear(); break; } if (!ignoreMoveCosts) { CurrentMovement = Math.Max(0, CurrentMovement - PositionCanon.GetTraversalCostForUnit(this, currentCell, nextCell, false) ); } PositionCanon.ChangeOwnerOfPossession(this, nextCell); CurrentPath.RemoveAt(0); a = c; b = currentLocation; c = (b + nextLocation) * 0.5f; for (; t < 1f; t += Time.deltaTime * Config.TravelSpeedPerSecond) { transform.position = BezierQuadratic.GetPoint(a, b, c, t); Vector3 d = BezierQuadratic.GetFirstDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } t -= 1f; currentCell = nextCell; currentLocation = Grid.PerformIntersectionWithTerrainSurface(currentCell.AbsolutePosition); } if (currentCell != startingCell) { a = c; b = currentLocation; c = b; for (; t < 1f; t += Time.deltaTime * Config.TravelSpeedPerSecond) { transform.position = BezierQuadratic.GetPoint(a, b, c, t); Vector3 d = BezierQuadratic.GetFirstDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } } postMovementCallback(); Animator.SetTrigger("Idling Requested"); }
public override void Exit() { CurrentPath.Clear(); }