示例#1
0
        static void Main(string[] args)
        {
            //Input
            string input = "3,8,1005,8,329,1106,0,11,0,0,0,104,1,104,0,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1002,8,1,29,2,1102,1,10,1,1009,16,10,2,4,4,10,1,9,5,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,66,2,106,7,10,1006,0,49,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,1002,8,1,95,1006,0,93,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,102,1,8,120,1006,0,61,2,1108,19,10,2,1003,2,10,1006,0,99,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,0,10,4,10,101,0,8,157,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,1001,8,0,179,2,1108,11,10,1,1102,19,10,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,209,2,108,20,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,101,0,8,234,3,8,102,-1,8,10,101,1,10,10,4,10,108,0,8,10,4,10,1002,8,1,256,2,1102,1,10,1006,0,69,2,108,6,10,2,4,13,10,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,294,1,1107,9,10,1006,0,87,2,1006,8,10,2,1001,16,10,101,1,9,9,1007,9,997,10,1005,10,15,99,109,651,104,0,104,1,21101,387395195796,0,1,21101,346,0,0,1105,1,450,21101,0,48210129704,1,21101,0,357,0,1105,1,450,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21101,0,46413147328,1,21102,404,1,0,1106,0,450,21102,179355823323,1,1,21101,415,0,0,1105,1,450,3,10,104,0,104,0,3,10,104,0,104,0,21102,1,838345843476,1,21101,0,438,0,1105,1,450,21101,709475709716,0,1,21101,449,0,0,1105,1,450,99,109,2,22102,1,-1,1,21102,40,1,2,21101,0,481,3,21101,0,471,0,1105,1,514,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,476,477,492,4,0,1001,476,1,476,108,4,476,10,1006,10,508,1101,0,0,476,109,-2,2106,0,0,0,109,4,2101,0,-1,513,1207,-3,0,10,1006,10,531,21101,0,0,-3,21201,-3,0,1,21201,-2,0,2,21101,1,0,3,21101,550,0,0,1105,1,555,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,578,2207,-4,-2,10,1006,10,578,21201,-4,0,-4,1105,1,646,22101,0,-4,1,21201,-3,-1,2,21202,-2,2,3,21101,597,0,0,1105,1,555,22102,1,1,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,616,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,638,22102,1,-1,1,21101,638,0,0,106,0,513,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2106,0,0";

            //Input from string to array
            string[] string_array = input.Split(",");
            int      input_length = CountOfChar(input, ',') + 1;

            Int64[] int_array = new Int64[input_length + 1000];
            for (int i = 0; i < int_array.Length - 1000; i++)
            {
                int_array[i] = Int64.Parse(string_array[i]);
            }

            /* Run Program
             * Each move of robot = 1 input and 2 output
             * Robot - input 0, if robot over BLACK panel
             *         input 1, if robot over WHITE panel
             * Program - 1. output 0, if robot paints panel BLACK
             *                     1, if robot paints panel WHITE
             *           2. output 0, turn LEFT 90 degrees
             *                     1, turn RIGHT 90 degrees
             *  Robot starts facing UP. After turn left/right, robot move FORWARD one step
             */
            Int64 output        = 0;
            Int64 pointer       = 0;
            Int64 relative_base = 0;

            Int64[,] path = new Int64[40, 60];
            int robot_x = 20;
            int robot_y = 10;

            string direction = "^";

            for (int i = 0; i < path.GetLength(0); i++)
            {
                for (int j = 0; j < path.GetLength(1); j++)
                {
                    path[i, j] = 2; // Set black
                }
            }
            path[robot_x, robot_y] = 1;
            while (output != 99)
            {
                int robot_input = GetRobotInput(robot_x, robot_y, path);
                (output, pointer, relative_base) = ProgramIntcode(int_array, robot_input, pointer, relative_base);
                PanelPaint(robot_x, robot_y, output, path);

                (output, pointer, relative_base) = ProgramIntcode(int_array, robot_input, pointer, relative_base);
                (robot_x, robot_y, direction)    = RobotMove(robot_x, robot_y, output, direction);
            }

            Console.WriteLine();
            PrintRegistration(path);

            Console.WriteLine("End of program");
            Console.ReadKey();
        }
示例#2
0
    public Boolean runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";
        String strBaseLoc;

        short[]   in2Arr  = new Int16[10];
        int[]     in4Arr  = new Int32[5];
        long[]    in8Arr  = new Int64[0];
        String[]  strArr  = new String[6];
        Boolean[] boArr   = new Boolean[3];
        Double[]  dblArr  = new Double[2];
        Single[]  snglArr = new Single[32000];
        Char[]    chArr   = new Char[10000];
        int       rank;

        try {
LABEL_860_GENERAL:
            do
            {
                strLoc = "Loc_819yt";
                rank   = -1;
                in2Arr = new Int16[5];
                iCountTestcases++;
                try {
                    in2Arr.GetLength(rank);
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_499ws! , GetLength==" + in2Arr.Length);
                } catch (IndexOutOfRangeException ioorExc) {}
                catch (Exception exc) {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_758! exc==" + exc);
                }
                strLoc = "Loc_819ee";
                rank   = 1;
                in2Arr = new Int16[5];
                iCountTestcases++;
                try {
                    in2Arr.GetLength(rank);
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_500ws! , GetLength==" + in2Arr.Length);
                } catch (IndexOutOfRangeException ioorExc) {}
                catch (Exception exc) {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_750! exc==" + exc);
                }
                strLoc = "Loc_482wu";
                rank   = 0;
                in2Arr = new Int16[10];
                iCountTestcases++;
                if (in2Arr.GetLength(rank) != 10)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_481ua! , GetLength==" + in2Arr.Length);
                }
                strLoc = "Loc_471ay";
                in4Arr = new Int32[5];
                iCountTestcases++;
                if (in4Arr.GetLength(rank) != 5)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_29qaq! , GetLength==" + in4Arr.Length);
                }
                strLoc = "Loc_982uq";
                in8Arr = new Int64[0];
                iCountTestcases++;
                if (in8Arr.GetLength(rank) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_237sy! , GetLength==" + in8Arr.Length);
                }
                strLoc = "Loc_172ms";
                boArr  = new Boolean[3];
                iCountTestcases++;
                if (boArr.GetLength(rank) != 3)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_382! , GetLength==" + boArr.Length);
                }
                strLoc = "Loc_49su";
                dblArr = new Double[2];
                iCountTestcases++;
                if (dblArr.GetLength(rank) != 2)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_200su! , GetLength==" + dblArr.Length);
                }
                strLoc  = "Loc_371su";
                snglArr = new Single[32000];
                iCountTestcases++;
                if (snglArr.GetLength(rank) != 32000)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_319aw! , GetLength==" + snglArr.Length);
                }
                strLoc    = "Loc_129wi";
                strArr    = new String[5];
                strArr[2] = null;
                iCountTestcases++;
                if (strArr.GetLength(rank) != 5)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_71ahw! , GetLength==" + strArr.Length);
                }
            } while (false);
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general);
        }
        if (iCountErrors == 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#3
0
        static void Main(string[] args)
        {
            AudioEngine.Sequencer sequencer = new AudioEngine.Sequencer();

            bool           quit = false;
            ConsoleKeyInfo cki  = new ConsoleKeyInfo();


            while (quit == false)
            {
                Console.WriteLine("Press 1 to Add a new Track");
                Console.WriteLine("Press 2 to Remove a Track");
                Console.WriteLine("Press 3 to Add an Event to a Track");
                Console.WriteLine("Press 4 to List all Events for a Track");
                Console.WriteLine("Press 5 randomly add events to a Track");
                Console.WriteLine("Press 6 to get a list of the first 100 events in order");
                Console.WriteLine("Press 7 to test sequencer speed");
                Console.WriteLine("Press Q to Exit test");


                cki = Console.ReadKey();
                Console.WriteLine("");
                if (cki.Key == ConsoleKey.Q)
                {
                    quit = true;
                }
                if (cki.Key == ConsoleKey.D1)
                {
                    Console.WriteLine("Enter track name to add");
                    Console.WriteLine("Track number " + sequencer.AddTrack(Console.ReadLine()).ToString() + " was added");
                }
                if (cki.Key == ConsoleKey.D2)
                {
                    Console.WriteLine("Enter a track number to remove");
                    int track = int.Parse(Console.ReadLine());
                    Console.WriteLine("Track " + sequencer.GetTrackName(track) + " was removed: " + sequencer.RemoveTrack(track).ToString());
                }
                if (cki.Key == ConsoleKey.D3)
                {
                    Console.WriteLine("Enter a track number to add an event to");
                    int trackNumber = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter a time code for the event");
                    Int64 eventTimeCode = Int64.Parse(Console.ReadLine());
                    bool  eventAdded    = sequencer.AddEvent(trackNumber, eventTimeCode);
                    Console.WriteLine("Event added:" + eventAdded.ToString() + " to " + sequencer.GetTrackName(trackNumber) + " at time code " + eventTimeCode.ToString());
                }
                if (cki.Key == ConsoleKey.D4)
                {
                    Console.WriteLine("Enter a track number to list all events for");
                    int trackNumber = int.Parse(Console.ReadLine());

                    // Get the time codes
                    Int64[] timeCodes = new Int64[AudioEngineGlobalSettings.TrackEvents];
                    timeCodes = sequencer.GetTrackEventTimeCodes(trackNumber, true);

                    // Print the time codes
                    if (timeCodes != null)
                    {
                        for (int i = 0; i < timeCodes.GetLength(0); i++)
                        {
                            if (timeCodes[i] >= 0)
                            {
                                Console.WriteLine(timeCodes[i]);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please pick a valid track");
                    }
                }
                if (cki.Key == ConsoleKey.D5)
                {
                    Console.WriteLine("Enter a track number to add random events to");
                    int trackNumber = int.Parse(Console.ReadLine());

                    if (sequencer.TrackExists(trackNumber))
                    {
                        Random ran = new Random();

                        for (int i = 0; i < 5000; i++)
                        {
                            sequencer.AddEvent(trackNumber, ran.Next());
                        }

                        Console.WriteLine("Events added");
                    }
                }
                if (cki.Key == ConsoleKey.D6)
                {
                    Int64[] timeCodes = new Int64[AudioEngineGlobalSettings.TrackEvents];
                    timeCodes = sequencer.GetAllTimeCodesOrdered();

                    // Print the time codes
                    if (timeCodes != null)
                    {
                        //for (int i = 0; i < timeCodes.GetLength(0); i++)
                        for (int i = 0; i < 100; i++)
                        {
                            if (timeCodes[i] >= 0)
                            {
                                Console.WriteLine(timeCodes[i]);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please pick a valid track");
                    }
                }
                if (cki.Key == ConsoleKey.D7)
                {
                    sequencer.Play();

                    //Int64 timeCode = sequencer.GetOrderedEvents();
                    //Console.WriteLine(timeCode);
                }


                Console.WriteLine("");
            }
        }