Example #1
0
        private void Shuffle_btn(object sender, RoutedEventArgs e)
        {
            RandomShuffler r = new RandomShuffler();

            r.Shuffler(8);
            Solve.IsEnabled = true;
        }
Example #2
0
        public static void WriteMovesToFile(LinkedList <State> moves)
        {
            List <int[, ]> matrices = new List <int[, ]>();

            foreach (State s in moves)
            {
                matrices.Add(((Puzzle15State)s).Square);
            }

            using (StreamWriter file = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "/Moves.txt"))
            {
                for (int k = 1; k < matrices.Count; k++)
                {
                    int[]  firstZero  = RandomShuffler.SearchZero(matrices[k - 1]);
                    int[]  secondZero = RandomShuffler.SearchZero(matrices[k]);
                    string move       = "";
                    int    ele        = 0;
                    if (firstZero[0] > secondZero[0])
                    {
                        move = "↓"; ele = matrices[k][firstZero[0], firstZero[1]];
                    }
                    else if (firstZero[0] < secondZero[0])
                    {
                        move = "↑"; ele = matrices[k][firstZero[0], firstZero[1]];
                    }
                    else if (firstZero[1] < secondZero[1])
                    {
                        move = "←"; ele = matrices[k][firstZero[0], firstZero[1]];
                    }
                    else if (firstZero[1] > secondZero[1])
                    {
                        move = "→"; ele = matrices[k][firstZero[0], firstZero[1]];
                    }
                    string line = $"{ele}, {move}";
                    file.WriteLine(line);
                }
            }
        }