public static CubeState Clone(this CubeState state) { // Don't serialize a null object, simply return the default for that object if (ReferenceEquals(state, null)) { return(default(CubeState)); } IFormatter formatter = new BinaryFormatter(); using (Stream stream = new MemoryStream()) { formatter.Serialize(stream, state); stream.Seek(0, SeekOrigin.Begin); return((CubeState)formatter.Deserialize(stream)); } }
public static bool EqualsState(this CubeState stateOne, CubeState stateTwo) { var stateOneFaces = stateOne.GetAllFaces(); var stateTwoFaces = stateTwo.GetAllFaces(); //If any squares do not match, the cubes have differing states for (var currentFace = 0; currentFace < CubeState.NUMBER_OF_FACES; currentFace++) { for (var currentSquare = 0; currentSquare < CubeState.CUBITS_PER_FACE; currentSquare++) { if (stateOneFaces[currentFace][currentSquare] != stateTwoFaces[currentFace][currentSquare]) { return(false); } } } //Otherwise, return true return(true); }
private void initializeState() { state = new CubeState(); }