protected Solver(Cube cube, ICubeLayerRotator cubeLayerRotator) { Cube = cube; Query = new CubeQuery(cube); Rotator = new CubeRotator(cube); SetFrontDirection(Directions.Front, Directions.Up); _cubeLayerRotator = cubeLayerRotator; }
public void Print(TextWriter writer, Cube cube) { Clear(); PrintFace(GetFacelets(cube, Direction.Up, Direction.Back, Direction.Left), 1, 0); PrintFace(GetFacelets(cube, Direction.Left, Direction.Up, Direction.Back), 0, 1); PrintFace(GetFacelets(cube, Direction.Front, Direction.Up, Direction.Left), 1, 1); PrintFace(GetFacelets(cube, Direction.Right, Direction.Up, Direction.Front), 2, 1); PrintFace(GetFacelets(cube, Direction.Back, Direction.Up, Direction.Right), 3, 1); PrintFace(GetFacelets(cube, Direction.Down, Direction.Front, Direction.Left), 1, 2); var text = new String(_page); writer.WriteLine(text); }
public void Print1(TextWriter writer, Cube cube) { Clear(); PrintFace(cube, 3, 1, 0); PrintFace(cube, 2, 1, 1); PrintFace(cube, 1, 1, 2); PrintFace(cube, 0, 1, 3); PrintFace(cube, 1, 0, 4); PrintFace(cube, 1, 2, 5); var text = new String(_page); writer.WriteLine(text); }
public Cube BuildCube() { var numberOfFaces = 6; var facelets = new List<Facelet>(3 * 3 * numberOfFaces); facelets.AddRange(BuildFacelets("Orange", Colors.Orange)); facelets.Rotate(Directions.Right, 90); facelets.AddRange(BuildFacelets("Green", Colors.Green)); facelets.Rotate(Directions.Right, 90); facelets.AddRange(BuildFacelets("Red", Colors.Red)); facelets.Rotate(Directions.Right, 90); facelets.AddRange(BuildFacelets("Blue", Colors.Blue)); facelets.Rotate(Directions.Up, 90); facelets.AddRange(BuildFacelets("White", Colors.White)); facelets.Rotate(Directions.Up, 180); facelets.AddRange(BuildFacelets("Yellow", Colors.Yellow)); facelets.Rotate(Directions.Right, -90); var cube = new Cube(facelets); facelets.ForEach(f => f.Build(cube)); return cube; }
private IEnumerable<Facelet> GetFacelets(Cube cube, Vector3D normal, Vector3D topNormal, Vector3D leftNormal) { var top = cube.GetFace(topNormal); var bottom = cube.GetFace(-topNormal); var left = cube.GetFace(leftNormal); var right = cube.GetFace(-leftNormal); var facelets = cube.GetFacelets(normal).ToList(); var center = facelets.Single(i => i.Type == FaceletType.Center); var corners = facelets.Where(i => i.Type == FaceletType.Corner).ToList(); var edges = facelets.Where(i => i.Type == FaceletType.Edge).ToList(); yield return corners.Single(i => i.IsCoplanar(left) && i.IsCoplanar(top)); yield return edges.Single(i => i.IsCoplanar(top)); yield return corners.Single(i => i.IsCoplanar(right) && i.IsCoplanar(top)); yield return edges.Single(i => i.IsCoplanar(left)); yield return center; yield return edges.Single(i => i.IsCoplanar(right)); yield return corners.Single(i => i.IsCoplanar(left) && i.IsCoplanar(bottom)); yield return edges.Single(i => i.IsCoplanar(bottom)); yield return corners.Single(i => i.IsCoplanar(right) && i.IsCoplanar(bottom)); }
public override void Build(Cube cube) { CenterFacelet = cube.CenterFacelets.First(f => Normal.IsSame(f.Normal)); OtherEdgeFacelet = cube.EdgeFacelets.Single(f => !ReferenceEquals(this, f) && f.CubieCenter.IsSame(CubieCenter)); }
private static void Solve(CubeRotator rotator, Cube cube, CubeQuery query) { using (var movesText = File.CreateText("Moves.txt")) { MoveCounter bestMoveCounter = null; var moveCounter = new MoveCounter(); var rotators = new CubeLayerRotatorList( new MoveWriter(movesText), moveCounter, rotator); var solver = new FirstLayerEdgeSolver(cube, query.GetCenterFacelet(Colors.White), rotators); var faceletsToSolveCount = solver.GetCountOfFaceletsToSolve(); if (faceletsToSolveCount == 0) return; var permutations = Permutations.Instance.GetPermutations(faceletsToSolveCount); foreach (var permutation in permutations) { var cubeState = cube.GetState(); SolveHelper(cube, solver, permutation); facelets to solve is out of sync. if (bestMoveCounter == null || bestMoveCounter.MoveCount > moveCounter.MoveCount) bestMoveCounter = moveCounter; cubeState.Restore(); movesText.WriteLine(moveCounter.ToString()); moveCounter = new MoveCounter(); rotators = new CubeLayerRotatorList( new MoveWriter(movesText), moveCounter, rotator); solver = new FirstLayerEdgeSolver(cube, query.GetCenterFacelet(Colors.White), rotators); } movesText.WriteLine(bestMoveCounter.ToString()); } }
private static void SolveHelper(Cube cube, Solver solver, IReadOnlyList<int> faceletIndexsToSolve) { int iterations = 0; do { if (iterations >= 10) throw new Exception("Too many iterations"); foreach (var indexOfFaceletToSolve in faceletIndexsToSolve) { solver.SolveFacelet(indexOfFaceletToSolve); cube.PrintAsCutout("cubeasCutout1.txt"); } var faceletsToSolveCount = solver.GetCountOfFaceletsToSolve(); if (faceletsToSolveCount == 0) break; faceletIndexsToSolve = Permutations.Instance.GetPermutations(faceletsToSolveCount).First(); iterations++; } while (faceletIndexsToSolve.Any()); }
public void Build(Cube cube) { OppositeCenterFacelet = cube.CenterFacelets.Single(f => (Normal + f.Normal).IsZero()); AdjacentCenterFacelets = cube.CenterFacelets.Where(f => Normal.Dot(f.Normal).IsZero()).ToList(); }
public CubeState(Cube cube) { _faceletStates = cube.Facelets.Select(f => f.GetState()).ToList(); }
public CubeRotator(Cube cube) : this(new CubeQuery(cube)) { }
public void Print2(TextWriter writer, Cube cube) { foreach (var facelet in cube.Facelets) writer.WriteLine(facelet.ToString()); }
private void PrintFace(Cube cube, int x, int y, int face) { var faces = Enumerable.Range(face * 9, 9).Select(i => cube.Facelets[i]).ToList(); PrintFace(faces, x, y); }
private void PrintFace(Cube cube, int x, int y, Vector3D normal) { var faces = cube.Facelets.Where(i => i.Normal.IsSame(normal)).ToList(); PrintFace(faces, x, y); }
public abstract void Build(Cube cube);
public CubePrinter(Cube cube) { _cube = cube; _cubeQuery = new CubeQuery(cube); _page = new char[_height * _length]; }
public FirstLayerEdgeSolver(Cube cube, ICenterFacelet topCenterFacelet, ICubeLayerRotator cubeLayerRotator) : base(cube, cubeLayerRotator) { _topCenterFacelet = topCenterFacelet; _faceletsToSolve = new IEdgeFacelet[0]; }
public CubeRotator(CubeQuery cubeQuery) { _cube = cubeQuery.Cube; _cubeQuery = cubeQuery; }
public FirstLayerCornerSolver(Cube cube, ICenterFacelet topCenterFacelet, IMachine machine) : base(cube, machine) { _topCenterFacelet = topCenterFacelet; }