public void Run(string[] args)
        {
            //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt
            if (args.Length < 1)
            {
                Console.WriteLine("input file name is missing");
                return;
            }
            Vector <int> vector = null;

            DataSerializer <int> .LoadVectorFromTextFile(args[0], ref vector);

            if (vector == null)
            {
                Console.WriteLine("Failed to load data from input file");
                return;
            }

            //let's check the capacity & count now
            Console.WriteLine("Vector Capacity is {0}", vector.Capacity);
            Console.WriteLine("Vector Count is {0}", vector.Count);

            //let's check how many numbers between 1 and 10000 exist in the input dataset
            //Can you calculate the T(n) & O(n)
            //Can you optimise the running time?
            int count = 0;

            for (int i = 1; i < 10000; i++)
            {
                if (vector.Contains(i) == true)
                {
                    count++;
                }
            }
            Console.WriteLine("{0} numbers between 1 and 10,000 have been used in the dataset (duplicates counted)", count);

            Console.Read();
        }
        public void Run(string[] args)
        {
            //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt
            if (args.Length < 1)
            {
                Console.WriteLine("input file name is missing");
                return;
            }
            Vector <int> vector = null;

            string inputFileName  = args[0];
            string outputFileName = "S_1H.txt";

            DataSerializer <int> .LoadVectorFromTextFile(inputFileName, ref vector);

            if (vector == null)
            {
                Console.WriteLine("Failed to load data from input file");
                return;
            }

            //let's check the capacity & count now
            Console.WriteLine("Vector Capacity is {0}", vector.Capacity);
            Console.WriteLine("Vector Count is {0}", vector.Count);

            //Let's sort Vector elements ascending?
            // Task 1 c
            vector.Sort();


            Console.WriteLine("Data has been sorted");
            DataSerializer <int> .SaveVectorToTextFile(outputFileName, vector);

            Console.WriteLine(string.Format("Data has been stored to {0}", outputFileName));

            Console.Read();
        }
        public void Run(string[] args)
        {
            //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt
            if (args.Length < 2)
            {
                Console.WriteLine("input and/or output file name(s) is(are) missing");
                return;
            }

            Vector <int> vector = null;

            string inputFileName  = args[0];
            string outputFileName = args[1];

            DataSerializer <int> .LoadVectorFromTextFile(inputFileName, ref vector);

            if (vector == null)
            {
                Console.WriteLine("Failed to load data from input file");
                return;
            }

            // check the state of capacity and count properties
            Console.WriteLine("Vector Capacity is {0}", vector.Capacity);
            Console.WriteLine("Vector Count is {0}", vector.Count);

            Console.WriteLine(vector);

            vector.Sort();

            Console.WriteLine(vector);
            DataSerializer <int> .SaveVectorToTextFile(outputFileName, vector);

            Console.WriteLine(string.Format("Data has been stored to {0}", outputFileName));

            Console.Read();
        }
Beispiel #4
0
 public void exitGame()
 {
     DataSerializer.Serialize("Stats", stats.genData());
     Exit();
 }
Beispiel #5
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferredBackBufferWidth  = 1920;
            Window.IsBorderless      = false;
            Window.AllowUserResizing = true;


            graphics.ApplyChanges();


            // level settings
            levelSettingsDict["Old"] = new LevelSettings {
                playerStartPos = new Vector2(30, 40)
            };
            levelSettingsDict["Sam"] = new LevelSettings {
                playerStartPos = new Vector2(10, 70)
            };
            levelSettingsDict["Gravity"] = new LevelSettings {
                playerStartPos = new Vector2(15, 94)
            };

            foreach (var level in levels)
            {
                if (!levelSettingsDict.Keys.Contains(level))
                {
                    levelSettingsDict[level] = new LevelSettings();
                }
            }


            base.Initialize();

            Textures.loadTextures();
            Tile.exportTilePalette();
            SoundPlayer.loadEffects();

            calm  = SoundPlayer.getEffect("CalmSong");
            chaos = SoundPlayer.getEffect("ChaosSong");

            calmI  = calm.CreateInstance();
            chaosI = chaos.CreateInstance();

            calmI.IsLooped  = true;
            chaosI.IsLooped = true;

            calmI.Play();
            calmI.Volume = 1.0F;
            chaosI.Play();
            chaosI.Volume = 0.0F;

            camera = new Camera(Vector2.Zero, 5);
            player = new Player(playerStartPos());

            for (int i = 0; i < particles.Length; i++)
            {
                particles[i] = new List <Particle>();
            }

            resetLevel();

            renderTarget = new RenderTarget2D(
                GraphicsDevice,
                GraphicsDevice.PresentationParameters.BackBufferWidth,
                GraphicsDevice.PresentationParameters.BackBufferHeight,
                false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24);

            // UI
            pauseUI.Add(new UIButton(unPauseClicked, new Vector2(200, 200), new Vector2(300, 100), "Resume"));
            pauseUI.Add(new UIButton(() => {
                restartRun();
                unPauseClicked();
            }, new Vector2(250, 310), new Vector2(300, 100), "Restart"));
            pauseUI.Add(new UIButton(() => uiScreen = new MainMenuScreen(), new Vector2(300, 420), new Vector2(300, 100), "Main Menu"));
            pauseUI.Add(new UIButton(() => uiScreen = new LevelSelectScreen(), new Vector2(350, 530), new Vector2(300, 100), "Level Select"));
            pauseUI.Add(new UIButton(exitGame, new Vector2(400, 640), new Vector2(300, 100), "Exit Game"));

            pauseUI.Add(new PauseStats(new Vector2(1920 - 250, 1080 / 2F), new Vector2(400, 1080 - 400)));

            // stats
            try {
                stats = new Stats(DataSerializer.Deserialize <StatData>("Stats"));
            }
            catch (Exception e) {
                stats = new Stats();
                Logger.warn("Found no pre-existing stats!, making new instance");
            }
        }
Beispiel #6
0
 public void saveWiring(string levelName)
 {
     DataSerializer.Serialize(levelName + "Wiring", this);
 }
Beispiel #7
0
        public void Run(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Expected two params");
                return;
            }

            string           inputFilename    = "../../Data/Project01/" + args[0];
            SortingAlgorithm sortingAlgorithm = (SortingAlgorithm)Enum.Parse(typeof(SortingAlgorithm), args[1]);
            string           outputFilename   = "../../Data/Project01/" + "S_" + args[0];

            Vector <int> vector = null;

            DataSerializer <int> .LoadVectorFromTextFile(inputFilename, ref vector);

            if (vector == null)
            {
                Console.WriteLine("Failed to load data from input file");
                return;
            }

            //let's check the capacity & count now
            Console.WriteLine("Vector Capacity is {0}", vector.Capacity);
            Console.WriteLine("Vector Count is {0}", vector.Count);


            /////
            var       averageMemory = 0;
            var       totalMemory   = 0;
            Stopwatch s             = new Stopwatch();

            s.Start();
            long memBefore = 0;
            long memAfter  = 0;

            for (int i = 0; i < 5; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();

                memBefore = Process.GetCurrentProcess().WorkingSet64;
                vector.Sort(sortingAlgorithm);                 //This is the same as calling vector.Sort with an ascending order comparer
                memAfter     = Process.GetCurrentProcess().WorkingSet64;
                totalMemory += (int)memAfter - (int)memBefore;
            }
            s.Stop();
            averageMemory = totalMemory / 5;

            Console.WriteLine("execution time = " + s.ElapsedMilliseconds + ", and memory =" + averageMemory / 1024.0);
            ///

            //Let's sort Vector elements ascending?
            memBefore = Process.GetCurrentProcess().WorkingSet64;
            GC.Collect();
            memAfter = Process.GetCurrentProcess().WorkingSet64;

            Console.WriteLine("memory =" + (memAfter - memBefore) / 1024.0);

            memBefore = Process.GetCurrentProcess().WorkingSet64;             //100M
            s         = new Stopwatch();
            s.Start();

            vector.Sort(sortingAlgorithm);             //This is the same as calling vector.Sort with an ascending order comparer
            //GC clean 80M
            s.Stop();
            memAfter = Process.GetCurrentProcess().WorkingSet64;             //102M
            //102-100
            //102 - 80 not very accurate!!!!
            Console.WriteLine("execution time = " + s.ElapsedMilliseconds + ", and memory =" + (memAfter - memBefore) / 1024.0);

            DataSerializer <int> .SaveVectorToTextFile(outputFilename, vector);
        }
Beispiel #8
0
        public void Run(string[] args)
        {
            SetClass <SetClass <int> > ps = new SetClass <SetClass <int> >(new Vector <SetClass <int> >());

            ps.Data.Add(new SetClass <int>(new Vector <int>()));
            ps.Data[0].Data.Add(1);
            ps.Data[0].Data.Add(2);

            ps.Data.Add(new SetClass <int>(new Vector <int>()));
            ps.Data[1].Data.Add(3);
            ps.Data[1].Data.Add(4);

            ps.Data.Add(new SetClass <int>(new Vector <int>()));
            ps.Data[2].Data.Add(5);

            string s = ps.ToString();


            Vector <Tuple <int, int> > abc = new Vector <Tuple <int, int> >();

            abc.Add(new Tuple <int, int>(3, 4));

            if (args.Length < 2)
            {
                Console.WriteLine("Expected at least two params");
                return;
            }

            string        opName = args[0];
            OperationEnum op     = (OperationEnum)Enum.Parse(typeof(OperationEnum), opName);

            string         setAPath = "../../Data/Project01/" + args[1];
            SetClass <int> setB     = null;
            int            element  = 0;

            if (op == OperationEnum.MEMBERSHIP)
            {
                element = int.Parse(args[2]);
            }
            else if (args.Length == 3)
            {
                string       setBPath = "../../Data/Project01/" + args[2];
                Vector <int> setBData = null;
                DataSerializer <int> .LoadVectorFromTextFile(setBPath, ref setBData);

                if (setBData == null)
                {
                    Console.WriteLine("Failed to load data from input file");
                    return;
                }


                setB = new SetClass <int>(setBData);
            }


            Vector <int> setAData = null;

            DataSerializer <int> .LoadVectorFromTextFile(setAPath, ref setAData);

            if (setAData == null)
            {
                Console.WriteLine("Failed to load data from input file");
                return;
            }
            SetClass <int> setA = new SetClass <int>(setAData);



            switch (op)
            {
            case OperationEnum.CARTESIAN:
                Console.WriteLine(
                    string.Format("Cartesian of SetA- {0}, Set B- {1}, is = {2} ",
                                  setA.Data.ToString(),
                                  setB.Data.ToString(),
                                  setA.CartesianProduct <int>(setB).Data.ToString()
                                  )
                    ); break;

            case OperationEnum.MEMBERSHIP:
                Console.WriteLine(string.Format("Check membership of {0}, is {1}", element, setA.Membership(element))); break;

            case OperationEnum.SUBSET:
                Console.WriteLine(string.Format("Check subset of {0} in {1}, and result = {2}",
                                                setA.Data.ToString(),
                                                setB.Data.ToString(),
                                                setA.IsSubsetOf(setB)
                                                )
                                  ); break;

            case OperationEnum.INTERESECTION:
                var setC = setA.IntersectionWith(setB);
                Console.WriteLine(string.Format("Interesection of A- {0}, with B- {1} is {2}",
                                                setA.Data.ToString(),
                                                setB.Data.ToString(),
                                                setC.Data.ToString()

                                                ));

                DataSerializer <int> .SaveVectorToTextFile("f1.txt", setC.Data);   break;

            case OperationEnum.SUPERSET:
                Console.WriteLine(string.Format("Check power of {0}, result = {1}",
                                                setA.Data.ToString(),

                                                setA.Powerset()

                                                )); break;
            }
        }
Beispiel #9
0
        public void Run(string[] args)
        {
            string inputFileName   = "../../Data/Project02/" + args[0];
            string encodedFileName = "../../Data/Project02/" + args[1];
            string decodedFileName = "../../Data/Project02/" + args[2];

            // load input data
            Vector <char> inputData = null;

            DataSerializer <char> .LoadVectorFromTextFile(inputFileName, ref inputData);

            // create a coder
            HuffmanCoding coder = new HuffmanCoding();

            // encode input data
            Vector <string> encodedData = null;

            encodedData = coder.Encode(inputData);

            // calculate the total number of bits (code length) used for encoding data
            int nBits = 0;

            for (int i = 0; i < encodedData.Count; i++)
            {
                nBits += encodedData[i].Length;
            }
            Console.WriteLine(String.Format("The total number of bits is {0}", nBits));

            // write the encoded data to file
            DataSerializer <string> .SaveVectorToTextFile(encodedFileName, encodedData);

            // reload the encoded data from file
            DataSerializer <string> .LoadVectorFromTextFile(encodedFileName, ref encodedData);

            // decode the encoded data
            Vector <char> decodedData = null;

            decodedData = coder.Decode(encodedData);

            // write the decoded data to file
            DataSerializer <char> .SaveVectorToTextFile(decodedFileName, decodedData);

            // reload the decodedData from file
            DataSerializer <char> .LoadVectorFromTextFile(decodedFileName, ref decodedData);

            // validating the coding result, i.e. checking whether inputData = decodedData
            if (inputData.Count != decodedData.Count)
            {
                Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!");
            }
            else
            {
                int i;
                for (i = 0; i < inputData.Count; i++)
                {
                    if (!inputData[i].Equals(decodedData[i]))
                    {
                        Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!");
                        break;
                    }
                }
                if (i == inputData.Count)
                {
                    Console.WriteLine("Coding method works accurately!");
                }
            }

            Console.Read();
        }