Ejemplo n.º 1
0
        public override LinkedList <State> GetPossibleMoves()
        {
            LinkedList <State> list = new LinkedList <State>();

            int[, ,] tempSquare = new int[4, 4, 4];
            int b = expand(tempSquare);

            for (int i = 0; i < b; i++)
            {
                int[,] ts = new int[4, 4];

                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        ts[j, k] = tempSquare[i, j, k];
                    }
                }

                Puzzle15State state = new Puzzle15State(ts);

                state.Parent   = this;
                state.Distance = g + ManhattanDistance(ts);
                list.AddLast(state);
            }

            g++;

            return(list);
        }
Ejemplo n.º 2
0
        private void GetMove()
        {
            int           m    = 0;
            Puzzle15State next = null;

            foreach (State s in moves)
            {
                next = (Puzzle15State)s;

                if (m == move)
                {
                    break;
                }

                m++;
            }

            move++;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    positions[4 * i + j] = FromIntToString(next.Square[i, j]);
                }
            }
        }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            Puzzle15State s = (Puzzle15State)obj;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (square[i, j] != s.square[i, j])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }