示例#1
0
文件: Form1.cs 项目: ewgraf/HBMET
        private void buttonPrepareNeironet_Click(object sender, EventArgs e)
        {
            string[] strings = File.ReadAllLines(stats[0]);
            Dictionary<string, string> configs = new Dictionary<string, string>(strings.Length);
            int map_line = -1;
            foreach (var s in strings)
            {
                map_line++;

                if (s.StartsWith("[map]"))
                    break;

                configs.Add(s.Split(':')[0], s.Split(':')[1]);
            }
            /*
                map_ip:Карты\карта-15x15_19.txt
                start:1,10
                bonuses:10
                up:13
                right:17
                down:7
                left:5
             */
            map_name = configs["map_id"];
            int start_x = Int32.Parse(configs["start"].Split(',')[0]);
            int start_y = Int32.Parse(configs["start"].Split(',')[1]);

            string[] current_map = new string[15];

            for (int i = ++map_line; i < strings.Length; i++)
            {
                current_map[i - map_line] = strings[i];
            }

            m_g_i.max_steps = max_steps;
            m_g_i.things = targets;

            m_g_i.map_width = (int)current_map[0].Length;
            m_g_i.map_heigth = (int)current_map.Length;

            map = new int[m_g_i.map_width, m_g_i.map_heigth];
            #region String-map-to-int-map
            for (int j = 0; j < m_g_i.map_heigth; j++)
            {
                for (int i = 0; i < m_g_i.map_width; i++)
                {
                    map[i, j] = Int32.Parse(current_map[j][i].ToString());
                }
            }
            #endregion

            x = start_x; y = start_y;
            m_g_i.things = targets;

            #region Statistic-staff
            // При каждом пуске инициализируем обект, хранящий статитику эксперимента
            global_stat_object = new Statistica();

            // Запоминаем начальные координаты оператора в начале эксперимента
            global_stat_object.X = x;
            global_stat_object.Y = y;
            #endregion

            map[x, y] = 3;

            gathered_bonuses = 0;
            rememberSteps = remember_steps;
            memory = new string[rememberSteps, 1 + 5 * 5 + 1];
            bonuses = new int[rememberSteps, 1];

            int block = 0;
            int[] template = new int[25];
            for (int i = 0; i < template.Length; i++) { template[i] = 0; }  // Заполняем стенами
            //
            // Сохраняем видимую область в memory на нулевом шаге
            // при генерации карты
            //
            // Поле зрения - 5х5
            // , и если ходим по краю карты, то за пределами карты мы должны видеть стены
            #region Save-vision-to-memory[0, i]
            for (int j = y - 2; j <= y + 2; j++)
            {
                for (int i = x - 2; i <= x + 2; i++)
                {
                    try
                    {
                        template[block] = map[i, j];  // Если отрицателен один из координат
                    }
                    catch
                    {
                        template[block] = 0;          // То пишем стену
                    }
                    block++;
                }
            }
            for (int i = 0; i < template.Length; i++)
            {
                memory[0, i] = template[i].ToString();
            }
            #endregion

            global_stat_object = new Statistica();

            pictureBox1.Invalidate();
            this.KeyPreview = true;
            this.Focus();
            neironet_steps = new uint[15, 15];
            //this.buttonGenerate_Click(new Object(), new EventArgs());
            //this.buttonNextStep.Focus();
        }
示例#2
0
文件: Form1.cs 项目: ewgraf/HBMET
        //========================
        // Кнопка "Получить карту"
        //========================
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            textBox1.Enabled = false;
            pictureBox1.Focus();
            buttonGenerate.Enabled = false;
            //buttonGenerate.Focus();
            if(maps == null)
            {
                MessageBox.Show("Загрузите карты!");
                открытьКартыToolStripMenuItem_Click(new Object(), new EventArgs());
                return;
            }
            Random r = new Random();
            map_id = r.Next(0, maps.Length);
            m_g_i.max_steps = max_steps;
            m_g_i.things = targets;
            this.Text = "Лабиринт, " + maps[map_id];
            string[] current_map = System.IO.File.ReadAllLines(maps[map_id]);
            m_g_i.map_width = (int)current_map[0].Length;
            m_g_i.map_heigth = (int)current_map.Length;
            // Инициализация большой расширяемой памяти-карты чувака
            MemoryMap = new int[m_g_i.map_width, m_g_i.map_heigth];
            Initialize(ref MemoryMap, 8);
            map = ParseStringArrayToInt(current_map);
            x = 0; y = 0;
            int destination = -1;
            if(checkBox3.Checked)
                destination = r.Next(1, m_g_i.map_width * m_g_i.map_heigth / 2);

            //===========================
            // Распределяем цели по карте
            //===========================
            map = CoverMapWithBonusesAndSelectStartPoint(m_g_i.things, map, destination, r);
            global_current_map = ParseIntArrayToString(map);

            m_g_i.things = targets;
            #region Statistic-staff
            // При каждом пуске инициализируем обект, хранящий статитику эксперимента
            global_stat_object = new Statistica();

            // Запоминаем начальные координаты оператора в начале эксперимента
            global_stat_object.X = x;
            global_stat_object.Y = y;
            #endregion
            map[x, y] = 3;
            labelSteps.Text = "0";
            labelGathered.Text = "0";
            gathered_bonuses = 0;
            rememberSteps = remember_steps;

            //=======================================
            // Память о видимой области на i-том шагу
            //=======================================
            memory = new string[rememberSteps, 25 + 1];

            bonuses = new int[rememberSteps, 1];

            //===================================================
            // Сохраняем видимую область в memory на нулевом шаге
            // при генерации карты
            //===================================================
            memory = SaveVisibleAreaAtStep(map, 0, memory);
            string[] tmp = ParseIntArrayToString(MemoryMap);
            pictureBox1.Invalidate();

            Common.FindBestWayAndTarget(ref MemoryMap, ref x, ref y, ref currentTargetPoint, ref currentTargetPath);

            this.KeyPreview = true;
            this.Focus();
        }