// *** CONSTRUCTORS *** /// <summary> /// Constructor /// </summary> /// <param name="layer">Defines the layer to be moved</param> /// <param name="direction">Defines the direction (true == clockwise and false == counter-clockwise)</param> /// <param name="twice">Defines whether this layer will be turned twice or not</param> /// <exception cref="System.Exception">Thrown when layer contains more than one flag</exception> public LayerMove(CubeFlag layer, bool direction = true, bool twice = false) { if (CubeFlagService.CountFlags(layer) == 1) { this.Layer = layer; this.Direction = direction; this.Twice = twice; } else { throw new Exception("Impossible movement"); } }
/// <summary> /// Parses a notation string into a layer move /// </summary> /// <param name="notation">String to be parsed</param> /// <param name="move">The resulting layer move</param> /// <returns>True, if the string was successfully parsed into a layermove</returns> public static bool TryParse(string notation, out LayerMove move) { move = null; string layer = notation[0].ToString(); CubeFlag rotationLayer = CubeFlagService.Parse(layer); char[] ccwChars = new char[] { '\'', 'i' }; bool direction = !ccwChars.Any(c => notation.Contains(c)); bool twice = notation.Contains("2"); if (CubeFlagService.CountFlags(rotationLayer) == 1) { move = new LayerMove(rotationLayer, direction, twice); return(true); } else { return(false); } }