/// <summary> /// Parses a notation string into a LayerMoveCollection /// </summary> /// <param name="notation">Defines to string to be parsed</param> public static LayerMoveCollection Parse(string notation) { string layer = notation[0].ToString(); LayerMoveCollection moves = new LayerMoveCollection(); char[] ccwChars = new char[] { '\'', 'i' }; bool direction = !ccwChars.All(c => notation.Contains(c)); bool twice = notation.Contains("2"); switch (layer) { case "r": moves = new LayerMove(CubeFlag.RightSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, direction, twice); break; case "l": moves = new LayerMove(CubeFlag.LeftSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, !direction, twice); break; case "u": moves = new LayerMove(CubeFlag.TopLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, direction, twice); break; case "d": moves = new LayerMove(CubeFlag.BottomLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, !direction, twice); break; case "f": moves = new LayerMove(CubeFlag.FrontSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, direction, twice); break; case "b": moves = new LayerMove(CubeFlag.BackSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, !direction, twice); break; case "x": moves = new LayerMove(CubeFlag.RightSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, direction, twice) & new LayerMove(CubeFlag.LeftSlice, !direction, twice); break; case "y": moves = new LayerMove(CubeFlag.TopLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, direction, twice) & new LayerMove(CubeFlag.BottomLayer, !direction, twice); break; case "z": moves = new LayerMove(CubeFlag.FrontSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, direction, twice) & new LayerMove(CubeFlag.BackSlice, !direction, twice); break; } return(moves); }
/// <summary> /// Adds multiple items at the end of the collection /// </summary> /// <param name="items">Defines the items which are meant to be added</param> public void AddRange(LayerMoveCollection items) { foreach (LayerMove m in items) { Add(m); } }
/// <summary> /// Adds a collection of LayerMoves to the given collection /// </summary> /// <param name="collection1">Defines the collection to be expanded</param> /// <param name="collection2">Defines the collection to be added</param> /// <returns></returns> public static LayerMoveCollection operator &(LayerMoveCollection collection1, LayerMoveCollection collection2) { LayerMoveCollection lmc = new LayerMoveCollection(); lmc.AddRange(collection1); lmc.AddRange(collection2); return(lmc); }
// *** OPERATORS *** /// <summary> /// Adds a single LayerMove to the given collection /// </summary> /// <param name="collection">Defines the collection to be expanded</param> /// <param name="newMove">Defines the additional LayerMove</param> /// <returns></returns> public static LayerMoveCollection operator &(LayerMoveCollection collection, LayerMove newMove) { LayerMoveCollection lmc = new LayerMoveCollection(); lmc.AddRange(collection); lmc.Add(newMove); return(lmc); }
// *** OPERATORS *** /// <summary> /// Combines two LayerMoves into a LayerMoveCollection /// </summary> public static LayerMoveCollection operator &(LayerMove first, LayerMove second) { LayerMoveCollection moves = new LayerMoveCollection(); moves.Add(first); moves.Add(second); return(moves); }
/// <summary> /// True, if the item accomplishes the equality conditions /// </summary> /// <param name="obj">LayerMoveCollection to be compared</param> public override bool Equals(object obj) { if (obj is LayerMoveCollection) { LayerMoveCollection coll = (LayerMoveCollection)obj; return(coll._moves.SequenceEqual(this._moves)); } return(false); }
/// <summary> /// Transforms the layer move collection /// </summary> /// <param name="rotationLayer">Transformation layer</param> /// <returns>The transformed layer move collection</returns> public IMove Transform(CubeFlag rotationLayer) { LayerMoveCollection newMoves = new LayerMoveCollection(); foreach (LayerMove move in _moves) { LayerMove newMove = new LayerMove(move.Layer, move.Direction, move.Twice); // deep clone newMoves &= (LayerMove)newMove.Transform(rotationLayer); } return(newMoves); }
/// <summary> /// Converts the notation of an algorithm in a collection of layer moves /// </summary> /// <param name="algorithm">Notation: separator = " " (space); counter-clockwise = any character (', i)</param> /// public Algorithm(string algorithm) { this.Moves = new List <IMove>(); foreach (string s in algorithm.Split(' ')) { LayerMove move; LayerMoveCollection collection; if (LayerMove.TryParse(s, out move)) { this.Moves.Add(move); } else if (LayerMoveCollection.TryParse(s, out collection)) { this.Moves.Add(collection); } else { throw new Exception("Invalid notation"); } } }