Esempio n. 1
0
        public PuzzleState(PuzzleState parent, Heuristic_ways tmp) : base(parent)
        {
            this.table = new int[PuzzleSize, PuzzleSize];

            Array.Copy(tmp.Table, this.table, this.table.Length);
            // ciało konstruktora

            this.id = tmp.ID;
            id_list.Add(this.id);

            this.x = tmp.x;
            this.y = tmp.y;

            if (tmp.h != 0)
            {
                Heuristic_vector(x, y);
            }
            this.h = tmp.h;

            //W stanie w ktorym jestesmy droga jest o jeden większa niż w rodzicu
            this.g = parent.g + 1;
        }
Esempio n. 2
0
        public void Heuristic_vector(int x, int y)
        {
            #region Generowanie vektora heurystyk

            Heuristic_ways htmp;

            int x_tmp = x;
            int y_tmp = y;
            int tmp;

            #region gora
            htmp       = new Heuristic_ways(1);
            htmp.Table = (int[, ])Table.Clone();

            if ((x_tmp - 1) >= 0 && (x_tmp - 1) < puzzleSize)
            {
                tmp = htmp.Table[x_tmp, y];
                htmp.Table[x_tmp, y]     = htmp.Table[x_tmp - 1, y];
                htmp.Table[x_tmp - 1, y] = tmp;
                x_tmp--;

                htmp.h = ComputeHeuristicGrade(htmp.Table);
            }
            else
            {
                htmp.h = infinity;
            }

            htmp.x = x_tmp;
            htmp.y = y_tmp;
            htmp.id_generate();
            Heuristic_vetor.Add(htmp);
            #endregion //gora

            #region dol
            x_tmp      = x;
            y_tmp      = y;
            htmp       = new Heuristic_ways(2);
            htmp.Table = (int[, ])Table.Clone();

            if ((x_tmp + 1) >= 0 && (x_tmp + 1) < puzzleSize)
            {
                tmp = htmp.Table[x_tmp, y_tmp];
                htmp.Table[x_tmp, y_tmp]     = htmp.Table[x_tmp + 1, y_tmp];
                htmp.Table[x_tmp + 1, y_tmp] = tmp;
                x_tmp++;

                htmp.h = ComputeHeuristicGrade(htmp.Table);
            }
            else
            {
                htmp.h = infinity;
            }

            htmp.x = x_tmp;
            htmp.y = y_tmp;
            htmp.id_generate();
            Heuristic_vetor.Add(htmp);
            #endregion //dol

            #region lewo
            x_tmp      = x;
            y_tmp      = y;
            htmp       = new Heuristic_ways(3);
            htmp.Table = (int[, ])Table.Clone();

            if ((y - 1) >= 0 && (y - 1) < puzzleSize)
            {
                tmp = htmp.Table[x_tmp, y_tmp];
                htmp.Table[x_tmp, y_tmp]     = htmp.Table[x_tmp, y_tmp - 1];
                htmp.Table[x_tmp, y_tmp - 1] = tmp;
                y_tmp--;

                htmp.h = ComputeHeuristicGrade(htmp.Table);
            }
            else
            {
                htmp.h = infinity;
            }

            htmp.x = x_tmp;
            htmp.y = y_tmp;
            htmp.id_generate();
            Heuristic_vetor.Add(htmp);
            #endregion //lewo

            #region prawo
            x_tmp      = x;
            y_tmp      = y;
            htmp       = new Heuristic_ways(4);
            htmp.Table = (int[, ])Table.Clone();

            if ((y_tmp + 1) >= 0 && (y_tmp + 1) < puzzleSize)
            {
                tmp = htmp.Table[x_tmp, y_tmp];
                htmp.Table[x_tmp, y_tmp]     = htmp.Table[x_tmp, y_tmp + 1];
                htmp.Table[x_tmp, y_tmp + 1] = tmp;
                y_tmp++;

                htmp.h = ComputeHeuristicGrade(htmp.Table);
            }
            else
            {
                htmp.h = infinity;
            }

            htmp.x = x_tmp;
            htmp.y = y_tmp;
            htmp.id_generate();
            Heuristic_vetor.Add(htmp);
            #endregion //prawo

            #endregion //Generowanie vektora heurystyk
        }