public List <RubikFaceType> GetSubcubeFaces(RubikSubcube subcube) { var faces = new List <RubikFaceType>(); for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Front[i].GetInstanceID()) { faces.Add(RubikFaceType.Front); break; } } for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Left[i].GetInstanceID()) { faces.Add(RubikFaceType.Left); break; } } for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Right[i].GetInstanceID()) { faces.Add(RubikFaceType.Right); break; } } for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Top[i].GetInstanceID()) { faces.Add(RubikFaceType.Top); break; } } for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Back[i].GetInstanceID()) { faces.Add(RubikFaceType.Back); break; } } for (var i = 0; i < 9; i++) { if (subcube.GetInstanceID() == Bottom[i].GetInstanceID()) { faces.Add(RubikFaceType.Bottom); break; } } return(faces); }
public Result <RubikFaceType, int> GetSubcubeFaceAndIndex(RubikSubcube subcube) { var instanceId = subcube.GetInstanceID(); for (var i = 0; i < 9; i++) { if (Front[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Front, i)); } } for (var i = 0; i < 9; i++) { if (Left[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Left, i)); } } for (var i = 0; i < 9; i++) { if (Right[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Right, i)); } } for (var i = 0; i < 9; i++) { if (Top[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Top, i)); } } for (var i = 0; i < 9; i++) { if (Back[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Back, i)); } } for (var i = 0; i < 9; i++) { if (Bottom[i].GetInstanceID() == instanceId) { return(Result <RubikFaceType, int> .Create(RubikFaceType.Bottom, i)); } } throw new ArgumentException("This subcube is not contained in the initial state.", "subcube"); }
private RubikSubcube[] RotateFace(RubikSubcube[] face, RubikFaceType type, bool clockwise) { var newFace = new RubikSubcube[9]; if (clockwise) { newFace[0] = face[2]; newFace[1] = face[5]; newFace[2] = face[8]; newFace[3] = face[1]; newFace[4] = face[4]; newFace[5] = face[7]; newFace[6] = face[0]; newFace[7] = face[3]; newFace[8] = face[6]; var faces = _faces[type]; var newFaces = new List <RubikFace>(9) { faces[2], faces[5], faces[8], faces[1], faces[4], faces[7], faces[0], faces[3], faces[6] }; for (int i = 0; i < 9; i++) { newFaces[i].Index = i; newFaces[i].Type = type; } _faces[type] = newFaces; } else { newFace[0] = face[6]; newFace[1] = face[3]; newFace[2] = face[0]; newFace[3] = face[7]; newFace[4] = face[4]; newFace[5] = face[1]; newFace[6] = face[8]; newFace[7] = face[5]; newFace[8] = face[2]; var faces = _faces[type]; var newFaces = new List <RubikFace>(9) { faces[6], faces[3], faces[0], faces[7], faces[4], faces[1], faces[8], faces[5], faces[2] }; for (int i = 0; i < 9; i++) { newFaces[i].Index = i; } _faces[type] = newFaces; } return(newFace); }