Exemplo n.º 1
0
 //Create empty document
 public static void Reset()
 {
     CurrentPath.Clear();
     Document.Clear();
     FileName = "untitled.md";
     FilePath = null;
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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");
                }
            }
        }
Exemplo n.º 4
0
        public void Reset()
        {
            if (CurrentPath == null)
            {
                CurrentPath = new Queue <Vector3>();
            }

            Acceleration = new Vector3(0, 0, 0);
            CurrentPath.Clear();
        }
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
 public override void Exit()
 {
     CurrentPath.Clear();
 }