public bool Run(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke)
        {
            bool buildPass = true;

            if (tracks.Last().Orientation.Pitch != 90)
            {
                buildPass = BuildToPitch.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 90);
            }
            else
            {
                CommandHandeler commandHandeler = new CommandHandeler();
                List <Command>  commands        = new List <Command>();

                commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0)));

                for (int i = 0; i < 3; i++)
                {
                    buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke);
                    if (buildPass == false)
                    {
                        break;
                    }
                }
            }

            return(buildPass);
        }
        static bool GoToX(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke, float XPosition, float withIn, TrackType type, float yawGoal)
        {
            CommandHandeler commandHandeler = new CommandHandeler();
            List <Command>  commands        = new List <Command>();
            bool            buildPass       = true;

            bool  firstStrightTrack = true;
            float lastX             = 0;
            float lastDiffernce     = 0;


            buildPass = BuildToPitch.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 0);
            if (!buildPass)
            {
                return(false);
            }

            while (!((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2))) && buildPass)
            {
                if (tracks.Last().Orientation.Yaw == yawGoal)
                {
                    commands.Clear();
                    commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0)));
                    buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke);

                    float differnce = Math.Abs(tracks.Last().Position.X - lastX);
                    if (!firstStrightTrack)
                    {
                        //This Means You Passed The Goal Point, This could have been done by turning, Or After the Fact. But You Are now going the wrong way.
                        if (differnce > lastDiffernce)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        firstStrightTrack = true;
                    }

                    lastX         = tracks.Last().Position.X;
                    lastDiffernce = differnce;
                }
                else
                {
                    commands.Clear();
                    commands.Add(new Command(true, type, new Orientation(0, 0, 0)));
                    buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke);
                }
            }
            if (tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        static bool GoToXY(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke, float XPosition, float YPosition, float withIn)
        {
            CommandHandeler commandHandeler = new CommandHandeler();
            List <Command>  commands        = new List <Command>();
            bool            buildPass       = true;

            bool  firstStrightTrack = true;
            float last          = 0;
            float lastDiffernce = 0;
            float yawGoal       = 0;

            buildPass = BuildToPitch.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 0);
            if (!buildPass)
            {
                return(false);
            }

            while (!((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2)) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2))) && buildPass)
            {
                float x = XPosition - tracks.Last().Position.X;
                float y = YPosition - tracks.Last().Position.Y;

                //Determine Best Yaw
                yawGoal = Convert.ToSingle(Math.Atan2((double)y, (double)x) * 180 / Math.PI);

                if (yawGoal < 0)
                {
                    yawGoal = yawGoal + 360;
                }

                //Get YawGoal To Nearest Angle Game Can Handle
                int totalAdjustments = (int)(yawGoal / Globals.STANDARD_ANGLE_CHANGE);

                if ((yawGoal % 15) > Globals.STANDARD_ANGLE_CHANGE / 2)
                {
                    totalAdjustments++;
                }

                yawGoal = totalAdjustments * Globals.STANDARD_ANGLE_CHANGE;

                if (tracks.Last().Orientation.Yaw == yawGoal)
                {
                    commands.Clear();
                    commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0)));
                    buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke);

                    float xDistance = tracks.Last().Position.X - XPosition;
                    float YDistance = tracks.Last().Position.Y - YPosition;

                    float differnce = Math.Abs(xDistance + xDistance);
                    if (!firstStrightTrack)
                    {
                        //This Means You Passed The Goal Point, This could have been done by turning, Or After the Fact. But You Are now going the wrong way.
                        if (differnce > lastDiffernce)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        firstStrightTrack = true;
                    }

                    last          = tracks.Last().Position.X + tracks.Last().Position.Y;
                    lastDiffernce = differnce;
                }
                else
                {
                    TrackType type = new TrackType();

                    if (tracks.Last().Orientation.Yaw - yawGoal > 0)
                    {
                        if (Math.Abs(tracks.Last().Orientation.Yaw - yawGoal) < 180)
                        {
                            type = TrackType.Right;
                        }
                        else
                        {
                            type = TrackType.Left;
                        }
                    }
                    else
                    {
                        if (Math.Abs(yawGoal - tracks.Last().Orientation.Yaw) < 180)
                        {
                            type = TrackType.Left;
                        }
                        else
                        {
                            type = TrackType.Right;
                        }
                    }

                    commands.Clear();
                    commands.Add(new Command(true, type, new Orientation(0, 0, 0)));
                    buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke);
                }
            }
            if (tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }