コード例 #1
0
        public static string SaveAs(Bitmap image, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = GetFileNameFromSaveDialog(mapInput, fileSettings);

            image.Save(fileName, fileSettings.Format);
            return(fileName);
        }
コード例 #2
0
 public byte[,] GenerateSpectralSynthesisFractioalBrownianMotionMap(MapGeneratorInput input)
 {
     _input   = input;
     _byteMap = new byte[_input.Width, _input.Height];
     _generateSpectralSynthesisFractioalBrownianMotionMap();
     return(_byteMap);
 }
コード例 #3
0
        // returns a file name with the specified prefix and auto increased number postfix as the filename
        public static string GenerateAutoSaveFileName(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            // Get files that start with fileNamePrefix
            string[] fileList = Directory.GetFiles(Directory.GetCurrentDirectory(), fileSettings.FileNamePrefix + "*");
            // Filter out only the files matching prefix+"0000"
            // Get largest postfix number
            int postfixNum = -1;

            foreach (string file in fileList)
            {
                Match match = Regex.Match(file, fileSettings.FileNamePrefix + @"\[.+\].(\d\d\d\d).\w+");
                if (match.Success)
                {
                    int num = Int32.Parse(match.Groups[1].ToString());
                    if (num > postfixNum)
                    {
                        postfixNum = num;
                    }
                }
            }
            postfixNum++;
            string postfix = postfixNum.ToString("0000");

            return(fileSettings.FileNamePrefix + "[" + mapInput.FillRate.ToString("0.00") + " " + mapInput.FillAlgorithm + " " + mapInput.Width + " " + mapInput.Height + "]." + postfix + "." + fileSettings.Extention);
        }
コード例 #4
0
 public byte[,] GenerateRandomCountMap(MapGeneratorInput input)
 {
     _input   = input;
     _byteMap = new byte[_input.Width, _input.Height];
     _generateRandomCountMap();
     return(_byteMap);
 }
コード例 #5
0
        public void ReadProgress()
        {
            StreamReader streamReaderProgress = File.OpenText("progress.txt");
            string       header = streamReaderProgress.ReadLine();

            _mapInput                  = new MapGeneratorInput();
            _mapInput.Width            = Convert.ToInt32(streamReaderProgress.ReadLine());
            _mapInput.Height           = Convert.ToInt32(streamReaderProgress.ReadLine());
            _mapInput.FillRate         = Convert.ToDouble(streamReaderProgress.ReadLine());
            _mapInput.FillAlgorithm    = Convert.ToInt32(streamReaderProgress.ReadLine());
            _mapInput.H                = Convert.ToDouble(streamReaderProgress.ReadLine());
            _pathInput                 = new PathSearcherInput();
            _pathInput.SearchAlgorithm = Convert.ToInt32(streamReaderProgress.ReadLine());
            _pathInput.SearchType      = Convert.ToInt32(streamReaderProgress.ReadLine());
            _pathInput.Jump            = Convert.ToInt32(streamReaderProgress.ReadLine());
            _taskInput                 = new SearchTaskInput();
            _taskInput.OuterIterations = Convert.ToInt32(streamReaderProgress.ReadLine());
            _taskInput.InnerIterations = Convert.ToInt32(streamReaderProgress.ReadLine());
            _taskInput.DisplayImage    = Convert.ToBoolean(streamReaderProgress.ReadLine());
            _taskInput.ThreadNum       = Convert.ToInt32(streamReaderProgress.ReadLine());
            _taskInput.SaveProgress    = Convert.ToBoolean(streamReaderProgress.ReadLine());

            _totalTime = Convert.ToInt64(streamReaderProgress.ReadLine());
            _results   = new Result[_taskInput.OuterIterations];
            for (int i = 0; i < _taskInput.OuterIterations; i++)
            {
                _results[i]       = new Result();
                _results[i].Found = Convert.ToInt32(streamReaderProgress.ReadLine());
                _results[i].Total = Convert.ToInt32(streamReaderProgress.ReadLine());
            }
            streamReaderProgress.Close();
        }
コード例 #6
0
        public static string Save(Bitmap image, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = GenerateAutoSaveFileName(mapInput, fileSettings);

            image.Save(fileName, fileSettings.Format);
            return(fileName);
        }
コード例 #7
0
 public MapGenerator(MapGeneratorInput input)
 {
     _input   = input;
     _byteMap = new byte[_input.Width, _input.Height];
     _rand    = new Random(unchecked ((int)DateTime.Now.Ticks));
     fBm      = new FractionalBrownianMotion(_input.Width, _input.Height, _input.H);
 }
コード例 #8
0
 public MapGenerator(int width, int height, double fillRate, int fillAlgorithm, double h)
 {
     _input   = new MapGeneratorInput(width, height, fillRate, fillAlgorithm, h);
     _byteMap = new byte[_input.Width, _input.Height];
     _rand    = new Random(unchecked ((int)DateTime.Now.Ticks));
     fBm      = new FractionalBrownianMotion(_input.Width, _input.Height, _input.H);
 }
コード例 #9
0
 public FormDisplay(GifGenerator gifGen, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
 {
     // Windows Form 設計工具支援的必要項
     InitializeComponent();
     //Initialize variables
     GifGen       = gifGen;
     MapInput     = mapInput;
     FileSettings = fileSettings;
     // Show bitmap
     Display();
 }
コード例 #10
0
 public byte[][] GenerateSpectralSynthesisFractioalBrownianMotionMap(MapGeneratorInput input)
 {
     _input   = input;
     _byteMap = new byte[_input.Width][];
     for (int i = 0; i < _input.Width; i++)
     {
         _byteMap[i] = new byte[_input.Height];
     }
     _generateSpectralSynthesisFractioalBrownianMotionMap();
     return(_byteMap);
 }
コード例 #11
0
 public byte[][] GenerateRandomCountMap(MapGeneratorInput input)
 {
     _input   = input;
     _byteMap = new byte[_input.Width][];
     for (int i = 0; i < _input.Width; i++)
     {
         _byteMap[i] = new byte[_input.Height];
     }
     _generateRandomCountMap();
     return(_byteMap);
 }
コード例 #12
0
 public MapGenerator(int width, int height, double fillRate)
 {
     _input   = new MapGeneratorInput(width, height, fillRate);
     _byteMap = new byte[_input.Width][];
     for (int i = 0; i < _input.Width; i++)
     {
         _byteMap[i] = new byte[_input.Height];
     }
     _rand = new Random(unchecked ((int)DateTime.Now.Ticks));
     fBm   = new FractionalBrownianMotion(_input.Width, _input.Height, _input.H);
 }
コード例 #13
0
        // returns a file name with the specified prefix and auto increased number postfix as the filename
        public static string GenerateAutoSaveFileName(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = "";

            if (mapInput.FromFile == "")
            {
                string algo = "";
                switch (mapInput.FillAlgorithm)
                {
                case 0:
                    algo = "FixedCount";
                    break;

                case 1:
                    algo = "RandomCount";
                    break;

                case 2:
                    algo = string.Format("Fractal-H{0}", mapInput.H);
                    break;

                default:
                    break;
                }
                fileName = fileSettings.FileNamePrefix + algo + "-F" + mapInput.FillRate.ToString("0.00") + "-S" + mapInput.Width + "x" + mapInput.Height;
            }
            else
            {
                fileName = mapInput.FromFile.Replace(".txt", "");
            }
            // Get files that start with fileNamePrefix
            string[] fileList = Directory.GetFiles(Directory.GetCurrentDirectory(), fileName + "*");
            // Filter out only the files matching prefix+"0000"
            // Get largest postfix number
            int postfixNum = -1;

            foreach (string file in fileList)
            {
                Match match = Regex.Match(file, fileName + @"\.(\d\d\d\d)\.\w+");
                if (match.Success)
                {
                    int num = Int32.Parse(match.Groups[1].ToString());
                    if (num > postfixNum)
                    {
                        postfixNum = num;
                    }
                }
            }
            postfixNum++;
            string postfix = postfixNum.ToString("0000");

            return(fileName + "." + postfix);
        }
コード例 #14
0
        public byte[][] Generate(MapGeneratorInput input)
        {
            switch (input.FillAlgorithm)
            {
            case 0:
                return(GenerateFixedCountMap(input));

            case 1:
                return(GenerateRandomCountMap(input));

            case 2:
                return(GenerateSpectralSynthesisFractioalBrownianMotionMap(input));
            }
            return(new byte[1][]);
        }
コード例 #15
0
        public static string GetFileNameFromSaveDialog(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            // Set default file name
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = fileSettings.Extention;
            saveFileDialog.Filter     = fileSettings.Filter;
            saveFileDialog.FileName   = GenerateAutoSaveFileName(mapInput, fileSettings);
            if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
            {
                if (saveFileDialog.FileName == "" || saveFileDialog.FileName == null)
                {
                    MessageBox.Show("Invalid File Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    return(Regex.Match(saveFileDialog.FileName, @".+\\(\w+\.\w+)").Groups[1].ToString());
                }
            }
            return("");
        }
コード例 #16
0
 public Task(SearchTaskInput taskInput, PathSearcherInput pathInput, MapGeneratorInput mapInput)
 {
     _taskInput = taskInput;
     _pathInput = pathInput;
     _mapInput  = mapInput;
 }
コード例 #17
0
 public PathSearcher(PathSearcherInput pathInput, MapGeneratorInput mapInput)
 {
     _mapInput  = mapInput;
     _pathInput = pathInput;
     _mapGen    = new MapGenerator(_mapInput);
 }
コード例 #18
0
 public PathSearcher()
 {
     _mapInput  = new MapGeneratorInput();
     _pathInput = new PathSearcherInput();
     _mapGen    = new MapGenerator(_mapInput);
 }
コード例 #19
0
        public FormSearchResults(SearchTaskInput taskInput, PathSearcherInput pathInput, MapGeneratorInput mapInput)
        {
            //
            // Windows Form 設計工具支援的必要項
            //
            InitializeComponent();

            // Input
            _taskInput = taskInput;
            _pathInput = pathInput;
            _mapInput  = mapInput;

            // Write input values to textBoxOutput
            textBoxOutput.AppendText(String.Format("Matrix: {0} x {1}, {2}\r\n", _mapInput.Width, _mapInput.Height, _mapInput.FillRate));
            string fillAlgorithm = "Error";

            switch (_mapInput.FillAlgorithm) // 0 = Fixed Count, 1 = Random Count, 2 = Fractal
            {
            case 0:
                fillAlgorithm = "Fixed Count";
                break;

            case 1:
                fillAlgorithm = "Random Count";
                break;

            case 2:
                fillAlgorithm = "Fractal, H " + _mapInput.H.ToString();
                break;
            }
            textBoxOutput.AppendText(String.Format("Fill: {0}\r\n", fillAlgorithm));
            string pathAlgorithm = "Error";

            /*
             * switch (_pathInput.SearchAlgorithm) // 1 = Priority Queue Search, 2 = DepthFirstSearch
             * {
             *  case 1:
             *      pathAlgorithm = "Priority Queue Search";
             *      break;
             *  case 2:
             *      pathAlgorithm = "Depth First Search";
             *      break;
             * }
             */
            switch (_pathInput.SearchType) // 1 = 4 way, 2 = 8 way
            {
            case 1:
                pathAlgorithm = "4 way";
                break;

            case 2:
                pathAlgorithm = "8 way";
                break;
            }
            pathAlgorithm += ", Jump " + _pathInput.Jump.ToString();
            textBoxOutput.AppendText(String.Format("Path: {0}\r\n", pathAlgorithm));

            // Initialize progress display interface
            progressBar.Maximum = _taskInput.InnerIterations * _taskInput.OuterIterations;

            // Start task
            _task = new Task(taskInput, pathInput, mapInput);
            _task.Start();

            // Enable UI progress timer
            timerUpdateDisplay.Enabled = true;
            if (_taskInput.SaveProgress)
            {
                timerSaveProgress.Enabled = true;
            }
        }