Esempio n. 1
0
        public void Multiply(CoordCube b)
        {
            Tuple <byte[], byte[]> edgeMult   = Multiply(ep, eo, b.ep, b.eo);
            Tuple <byte[], byte[]> cornerMult = Multiply(cp, co, b.cp, b.co);

            ep = edgeMult.Item1;
            eo = edgeMult.Item2;
            cp = cornerMult.Item1;
            co = cornerMult.Item2;
        }
Esempio n. 2
0
        public CoordCube DeepClone()
        {
            CoordCube newCubie = new CoordCube();

            newCubie.co = this.co;
            newCubie.cp = this.cp;
            newCubie.eo = this.eo;
            newCubie.ep = this.ep;
            return(newCubie);
        }
      protected override void Solve(Rubik cube)
      {
        Rubik = cube.DeepClone();
        _coordCube = ToCoordCube(cube);
        this.MaxDepth = 30;
        this.TimeOut = 10000;
        Algorithm = new Algorithm();
        InitStandardCube();

        GetSolution();
        RemoveUnnecessaryMoves();
      }
        protected override void Solve(Rubik cube)
        {
            Rubik         = cube.DeepClone();
            _coordCube    = ToCoordCube(cube);
            this.MaxDepth = 30;
            this.TimeOut  = 10000;
            Algorithm     = new Algorithm();
            InitStandardCube();

            GetSolution();
            RemoveUnnecessaryMoves();
        }
        public override void Solve(Rubik cube)
        {
            this.Rubik    = cube.DeepClone();
            _coordCube    = TwoPhaseHelpers.ToCoordCube(cube);
            this.MaxDepth = 30;
            this.TimeOut  = 10000;
            Algorithm     = new Algorithm(null);
            InitStandardCube();

            GetSolution();
            Algorithm = Algorithm.RemoveUnnecessaryMoves(Algorithm);
        }
Esempio n. 6
0
        private CoordCube ToCoordCube(Rubik rubik)
        {
            // get corner perm and orientation
            string[] corners = new string[N_CORNER] {
                "UFR", "UFL", "UBL", "URB", "DFR", "DFL", "DBL", "DRB"
            };
            byte[] cornerPermutation = new byte[N_CORNER];
            byte[] cornerOrientation = new byte[N_CORNER];
            for (int i = 0; i < N_CORNER; i++)
            {
                CubeFlag pos          = CubeFlagService.Parse(corners[i]);
                Cube     matchingCube = rubik.Cubes.First(c => c.Position.Flags == pos);
                CubeFlag targetPos    = rubik.GetTargetFlags(matchingCube);
                cornerOrientation[i] = (byte)Solvability.GetOrientation(rubik, matchingCube);

                for (int j = 0; j < N_CORNER; j++)
                {
                    if (corners[j] == CubeFlagService.ToNotationString(targetPos))
                    {
                        cornerPermutation[i] = (byte)(j + 1);
                    }
                }
            }

            // get edge perm and orientation
            string[] edges = new string[N_EDGE] {
                "UR", "UF", "UL", "UB", "DR", "DF", "DL", "DB", "FR", "FL", "BL", "RB"
            };
            byte[] edgePermutation = new byte[N_EDGE];
            byte[] edgeOrientation = new byte[N_EDGE];
            for (int i = 0; i < N_EDGE; i++)
            {
                CubeFlag pos          = CubeFlagService.Parse(edges[i]);
                Cube     matchingCube = rubik.Cubes.Where(c => c.IsEdge).First(c => c.Position.Flags.HasFlag(pos));
                CubeFlag targetPos    = rubik.GetTargetFlags(matchingCube);
                edgeOrientation[i] = (byte)Solvability.GetOrientation(rubik, matchingCube);

                for (int j = 0; j < N_EDGE; j++)
                {
                    if (CubeFlagService.ToNotationString(targetPos).Contains(edges[j]))
                    {
                        edgePermutation[i] = (byte)(j + 1);
                    }
                }
            }

            byte[] cornerInv = CoordCube.ToInversions(cornerPermutation);
            byte[] edgeInv   = CoordCube.ToInversions(edgePermutation);

            return(new CoordCube(cornerPermutation, edgePermutation, cornerOrientation, edgeOrientation));
        }
Esempio n. 7
0
 private void InitMergeURtoULandUBtoDF()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath, "merge_move.file"), 336, 336, out mergeURtoULandUBtoDF))
     {
         for (short uRtoUL = 0; uRtoUL < 336; uRtoUL++)
         {
             for (short uBtoDF = 0; uBtoDF < 336; uBtoDF++)
             {
                 mergeURtoULandUBtoDF[uRtoUL, uBtoDF] = (short)CoordCube.GetURtoDF(uRtoUL, uBtoDF);
             }
         }
         SaveMoveTable(Path.Combine(this.TablePath, "merge_move.file"), mergeURtoULandUBtoDF);
     }
 }
 private void InitFlipMoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath,"flip_move.file"), N_MOVE, N_FLIP, out flipMove))
       {
     CoordCube a = new CoordCube();
     for (short i = 0; i < N_FLIP; i++)
     {
       for (int j = 0; j < N_MOVE; j++)
       {
     a.Flip = i;
     a.Multiply(moves[j]);
     flipMove[i, j] = a.Flip;
       }
     }
     SaveMoveTable(Path.Combine(this.TablePath,"flip_move.file"), twistMove);
       }
 }
 private void InitTwistMoveTable()
 {
   if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath,"twist_move.file"), N_MOVE, N_TWIST, out twistMove))
   {
     CoordCube a = new CoordCube();
     for (short i = 0; i < N_TWIST; i++)
     {
       for (int j = 0; j < N_MOVE; j++)
       {
         a.Twist = i;
         a.Multiply(moves[j]);
         twistMove[i, j] = a.Twist;
       }
     }
     SaveMoveTable(Path.Combine(this.TablePath,"twist_move.file"), twistMove);
   }
 }
Esempio n. 10
0
 private void InitFRtoBR_MoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath, "fr_to_br_move.file"), N_MOVE, N_FRtoBR, out FRtoBR_Move))
     {
         CoordCube a = new CoordCube();
         for (short i = 0; i < N_FRtoBR; i++)
         {
             for (int j = 0; j < N_MOVE; j++)
             {
                 a.FRtoBR = i;
                 a.Multiply(moves[j]);
                 FRtoBR_Move[i, j] = a.FRtoBR;
             }
         }
         SaveMoveTable(Path.Combine(this.TablePath, "fr_to_br_move.file"), FRtoBR_Move);
     }
 }
Esempio n. 11
0
 private void InitURtoDF_MoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath, "ur_to_df_move.file"), N_MOVE, N_URtoDF, out URtoDF_Move))
     {
         CoordCube a = new CoordCube();
         for (short i = 0; i < N_URtoDF; i++)
         {
             for (int j = 0; j < N_MOVE; j++)
             {
                 a.URtoDF = i;
                 a.Multiply(moves[j]);
                 URtoDF_Move[i, j] = (short)a.URtoDF;
             }
         }
         SaveMoveTable(Path.Combine(this.TablePath, "ur_to_df_move.file"), URtoDF_Move);
     }
 }
Esempio n. 12
0
 private void InitTwistMoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath, "twist_move.file"), N_MOVE, N_TWIST, out twistMove))
     {
         CoordCube a = new CoordCube();
         for (short i = 0; i < N_TWIST; i++)
         {
             for (int j = 0; j < N_MOVE; j++)
             {
                 a.Twist = i;
                 a.Multiply(moves[j]);
                 twistMove[i, j] = a.Twist;
             }
         }
         SaveMoveTable(Path.Combine(this.TablePath, "twist_move.file"), twistMove);
     }
 }
Esempio n. 13
0
 private void InitFlipMoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath, "flip_move.file"), N_MOVE, N_FLIP, out flipMove))
     {
         CoordCube a = new CoordCube();
         for (short i = 0; i < N_FLIP; i++)
         {
             for (int j = 0; j < N_MOVE; j++)
             {
                 a.Flip = i;
                 a.Multiply(moves[j]);
                 flipMove[i, j] = a.Flip;
             }
         }
         SaveMoveTable(Path.Combine(this.TablePath, "flip_move.file"), twistMove);
     }
 }
 private void InitFRtoBR_MoveTable()
 {
     if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath,"fr_to_br_move.file"), N_MOVE, N_FRtoBR, out FRtoBR_Move))
       {
     CoordCube a = new CoordCube();
     for (short i = 0; i < N_FRtoBR; i++)
     {
       for (int j = 0; j < N_MOVE; j++)
       {
     a.FRtoBR = i;
     a.Multiply(moves[j]);
     FRtoBR_Move[i, j] = a.FRtoBR;
       }
     }
     SaveMoveTable(Path.Combine(this.TablePath,"fr_to_br_move.file"), FRtoBR_Move);
       }
 }
    private void InitMoves()
    {
      moves[0] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 1, 1, 1, 0, 0, 0, 0 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }),
        new byte[N_CORNER] { 0, 0, 0, 0, 0, 0, 0, 0 },
        new byte[N_EDGE] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

      moves[3] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 1, 1, 3, 0, 1, 1, 4 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 1, 1, 1, 0, 2, 2, 2, 5, 1, 1, 11 }),
        new byte[N_CORNER] { 2, 0, 0, 1, 1, 0, 0, 2 },
        new byte[N_EDGE] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

      moves[6] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 0, 1, 1, 4, 1, 0, 0 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 0, 1, 1, 1, 1, 2, 2, 7, 4, 0, 0 }),
        new byte[N_CORNER] { 1, 2, 0, 0, 2, 1, 0, 0 },
        new byte[N_EDGE] { 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0 });

      moves[9] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 0, 0, 0, 0, 0, 0, 3 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0 }),
        new byte[N_CORNER] { 0, 0, 0, 0, 0, 0, 0, 0 },
        new byte[N_EDGE] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

      moves[12] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 0, 0, 1, 1, 4, 1, 0 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 0, 0, 1, 1, 1, 1, 2, 2, 7, 4, 0 }),
        new byte[N_CORNER] { 0, 1, 2, 0, 0, 2, 1, 0 },
        new byte[N_EDGE] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

      moves[15] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] { 0, 0, 0, 0, 1, 1, 4, 1 }),
        CoordCube.FromInversions(new byte[N_EDGE] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 7, 4 }),
        new byte[N_CORNER] { 0, 0, 1, 2, 0, 0, 2, 1 },
        new byte[N_EDGE] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1 });

      for (int i = 0; i < N_MOVE; i += 3)
      {
        CoordCube move = moves[i].DeepClone();
        for (int j = 1; j < 3; j++)
        {
          move.Multiply(moves[i]);
          moves[i + j] = move.DeepClone();
        }
      }
    }
Esempio n. 16
0
        public static int GetURtoDF(short idx1, short idx2)
        {
            CoordCube a = new CoordCube();
            CoordCube b = new CoordCube();

            a.URtoUL = idx1;
            b.UBtoDF = idx2;
            for (int i = 0; i < 8; i++)
            {
                if (a.ep[i] != 12)
                {
                    if (b.ep[i] != 12)
                    {
                        return(-1);
                    }
                    else
                    {
                        b.ep[i] = a.ep[i];
                    }
                }
            }
            return(b.URtoDF);
        }
 private void InitFlipMoveTable()
 {
     if (LoadMoveTableSuccessful(
         Path.Combine(this.TablePath, "flip_move.file"),
         N_MOVE,
         N_FLIP,
         out this.flipMove))
     {
         return;
     }
     var a = new CoordCube();
     for (short i = 0; i < N_FLIP; i++)
     {
         for (var j = 0; j < N_MOVE; j++)
         {
             a.Flip = i;
             a.Multiply(this.moves[j]);
             this.flipMove[i, j] = a.Flip;
         }
     }
     SaveMoveTable(Path.Combine(this.TablePath, "flip_move.file"), this.twistMove);
 }
 private void InitURtoDF_MoveTable()
 {
   if (!this.LoadMoveTableSuccessful(Path.Combine(this.TablePath,"ur_to_df_move.file"), N_MOVE, N_URtoDF, out URtoDF_Move))
   {
     CoordCube a = new CoordCube();
     for (short i = 0; i < N_URtoDF; i++)
     {
       for (int j = 0; j < N_MOVE; j++)
       {
         a.URtoDF = i;
         a.Multiply(moves[j]);
         URtoDF_Move[i, j] = (short)a.URtoDF;
       }
     }
     SaveMoveTable(Path.Combine(this.TablePath,"ur_to_df_move.file"), URtoDF_Move);
   }
 }
Esempio n. 19
0
        private void InitMoves()
        {
            moves[0] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 1, 1, 1, 0, 0, 0, 0
            }),
                                     CoordCube.FromInversions(new byte[N_EDGE] {
                0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0
            }),
                                     new byte[N_CORNER] {
                0, 0, 0, 0, 0, 0, 0, 0
            },
                                     new byte[N_EDGE] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            });

            moves[3] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 1, 1, 3, 0, 1, 1, 4
            }),
                                     CoordCube.FromInversions(new byte[N_EDGE] {
                0, 1, 1, 1, 0, 2, 2, 2, 5, 1, 1, 11
            }),
                                     new byte[N_CORNER] {
                2, 0, 0, 1, 1, 0, 0, 2
            },
                                     new byte[N_EDGE] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            });

            moves[6] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 0, 1, 1, 4, 1, 0, 0
            }),
                                     CoordCube.FromInversions(new byte[N_EDGE] {
                0, 0, 1, 1, 1, 1, 2, 2, 7, 4, 0, 0
            }),
                                     new byte[N_CORNER] {
                1, 2, 0, 0, 2, 1, 0, 0
            },
                                     new byte[N_EDGE] {
                0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0
            });

            moves[9] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 0, 0, 0, 0, 0, 0, 3
            }),
                                     CoordCube.FromInversions(new byte[N_EDGE] {
                0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0
            }),
                                     new byte[N_CORNER] {
                0, 0, 0, 0, 0, 0, 0, 0
            },
                                     new byte[N_EDGE] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            });

            moves[12] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 0, 0, 1, 1, 4, 1, 0
            }),
                                      CoordCube.FromInversions(new byte[N_EDGE] {
                0, 0, 0, 1, 1, 1, 1, 2, 2, 7, 4, 0
            }),
                                      new byte[N_CORNER] {
                0, 1, 2, 0, 0, 2, 1, 0
            },
                                      new byte[N_EDGE] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            });

            moves[15] = new CoordCube(CoordCube.FromInversions(new byte[N_CORNER] {
                0, 0, 0, 0, 1, 1, 4, 1
            }),
                                      CoordCube.FromInversions(new byte[N_EDGE] {
                0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 7, 4
            }),
                                      new byte[N_CORNER] {
                0, 0, 1, 2, 0, 0, 2, 1
            },
                                      new byte[N_EDGE] {
                0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1
            });

            for (int i = 0; i < N_MOVE; i += 3)
            {
                CoordCube move = moves[i].DeepClone();
                for (int j = 1; j < 3; j++)
                {
                    move.Multiply(moves[i]);
                    moves[i + j] = move.DeepClone();
                }
            }
        }
 public static int GetURtoDF(short idx1, short idx2)
 {
     CoordCube a = new CoordCube();
     CoordCube b = new CoordCube();
     a.URtoUL = idx1;
     b.UBtoDF = idx2;
     for (int i = 0; i < 8; i++)
         if (a.ep[i] != 12)
         {
             if (b.ep[i] != 12)
                 return -1;
             else b.ep[i] = a.ep[i];
         }
     return b.URtoDF;
 }
 public CoordCube DeepClone()
 {
     CoordCube newCubie = new CoordCube();
     newCubie.co = this.co;
     newCubie.cp = this.cp;
     newCubie.eo = this.eo;
     newCubie.ep = this.ep;
     return newCubie;
 }
 private void InitUBtoDF_MoveTable()
 {
     if (LoadMoveTableSuccessful(
         Path.Combine(this.TablePath, "ub_to_df_move.file"),
         N_MOVE,
         N_UBtoDF,
         out this.UBtoDF_Move))
     {
         return;
     }
     var a = new CoordCube();
     for (short i = 0; i < N_UBtoDF; i++)
     {
         for (var j = 0; j < N_MOVE; j++)
         {
             a.UBtoDF = i;
             a.Multiply(this.moves[j]);
             this.UBtoDF_Move[i, j] = a.UBtoDF;
         }
     }
     SaveMoveTable(Path.Combine(this.TablePath, "ub_to_df_move.file"), this.UBtoDF_Move);
 }
 public void Multiply(CoordCube b)
 {
     Tuple<byte[], byte[]> edgeMult = Multiply(ep, eo, b.ep, b.eo);
     Tuple<byte[], byte[]> cornerMult = Multiply(cp, co, b.cp, b.co);
     ep = edgeMult.Item1;
     eo = edgeMult.Item2;
     cp = cornerMult.Item1;
     co = cornerMult.Item2;
 }