Exemplo n.º 1
0
 /// <summary>
 /// True, if the item accomplishes the equality conditions
 /// </summary>
 /// <param name="obj">Layer move to be compared</param>
 public override bool Equals(object obj)
 {
     if (obj is LayerMove)
     {
         LayerMove move = (LayerMove)obj;
         return(this.Direction == move.Direction && this.Layer == move.Layer && this.Twice == move.Twice);
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Transforms the layer move
        /// </summary>
        /// <param name="rotationLayer">Transformation layer</param>
        /// <returns>Transformed layer move</returns>
        public IMove Transform(CubeFlag rotationLayer)
        {
            bool switchDir = CubeFlagService.IsYFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleSlice) ||
                             CubeFlagService.IsXFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleLayer) ||
                             CubeFlagService.IsZFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleSliceSides);

            LayerMove newMove = new LayerMove(CubeFlagService.NextCubeFlag(this.Layer, rotationLayer, true), this.Direction ^ switchDir, this.Twice);

            return(newMove);
        }
Exemplo n.º 3
0
 /// <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");
         }
     }
 }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
    /// <summary>
    /// Transforms the layer move
    /// </summary>
    /// <param name="rotationLayer">Transformation layer</param>
    /// <returns>Transformed layer move</returns>
    public IMove Transform(CubeFlag rotationLayer)
    {
      bool switchDir = CubeFlagService.IsYFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleSlice) ||
        CubeFlagService.IsXFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleLayer) ||
        CubeFlagService.IsZFlag(rotationLayer) && this.Layer.HasFlag(CubeFlag.MiddleSliceSides);

      LayerMove newMove = new LayerMove(CubeFlagService.NextCubeFlag(this.Layer, rotationLayer, true), this.Direction ^ switchDir, this.Twice);
      return newMove;
    }
Exemplo n.º 6
0
    /// <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;
    }
    /// <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;
      var layer = notation[0].ToString();
      var rotationLayer = CubeFlagService.Parse(layer);

      var ccwChars = new[] { '\'', 'i' };
      var direction = !ccwChars.Any(notation.Contains);

      var twice = notation.Contains("2");
      if (CubeFlagService.CountFlags(rotationLayer) == 1)
      {
        move = new LayerMove(rotationLayer, direction, twice);
        return true;
      }
      else return false;
    }