Example #1
0
        public static PathSet GetPathSet(ShapeOrientationCollection pieceDefinition)
        {
            var pieceLookup = pieceDefinition.ToString();

            if (!_pieceMoves.ContainsKey(pieceLookup))
            {
                _pieceMoves[pieceLookup] = new PathSet(PathGenerator(pieceDefinition).ToArray());
            }
            return(_pieceMoves[pieceLookup].DeepClone());
        }
Example #2
0
        public static IEnumerable <Orientation> GetUniqueOrientations(ShapeOrientationCollection pieceDefinition)
        {
            yield return(Orientation.Original);

            for (var targetOrientation = Orientation.Flip; targetOrientation <= Orientation.LeftFlip; targetOrientation++)
            {
                var targetRotation = Piece.GetRotation(Orientation.Original, targetOrientation);
                //For each adjusted orientation I'll try to map oriented paths to
                //original paths and see if the orientation is equivalent or not.
                var originalPathSet = MoveGenerator.GetPathSet(pieceDefinition);
                var adjustedShape   = new ShapeOrientationCollection(pieceDefinition.Select(so => new ShapeOrientation(so.Shape, Piece.RotateOrientation(so.Orientation, targetRotation))).ToArray(), true);
                var adjustedPathSet = MoveGenerator.GetPathSet(adjustedShape);

                var mismatch = false;

                while (originalPathSet.Count > 0 && adjustedPathSet.Count > 0)
                {
                    var nextVector      = originalPathSet.Keys.First();
                    var nextVectorPaths = originalPathSet[nextVector];
                    if (!adjustedPathSet.ContainsKey(nextVector))
                    {
                        yield return(targetOrientation);

                        break;
                    }
                    var adjustedVectorPaths = adjustedPathSet[nextVector];
                    if (nextVectorPaths.Count != adjustedVectorPaths.Count)
                    {
                        mismatch = true;
                    }
                    else
                    {
                        foreach (var path in nextVectorPaths.Keys)
                        {
                            if (!adjustedVectorPaths.Any(x => x.Key.ToString() == path.ToString()))
                            {
                                mismatch = true;
                                break;
                            }
                        }
                    }
                    if (mismatch)
                    {
                        yield return(targetOrientation);

                        break;
                    }
                    originalPathSet.Remove(nextVector);
                    adjustedPathSet.Remove(nextVector);
                }
            }
        }
Example #3
0
 private static IEnumerable <MovementPath> PathGenerator(ShapeOrientationCollection pieceDefinition)
 {
     foreach (var shapeOrientationSequence in PermuteShapeOrientations(pieceDefinition).ToArray())
     {
         var indices = shapeOrientationSequence.Select(i => 0).ToList();
         indices[0] = -1;
         var pieces = shapeOrientationSequence.Select(so => Piece.OrientVectors(Piece.GetNonOrientedVectors(so.Shape), so.Orientation).ToList()).ToList();
         while (IncrementIndexList(indices, pieces))
         {
             yield return(new MovementPath(pieces.Select((piece, idx) => piece[indices[idx]]).ToArray()));
         }
     }
 }
Example #4
0
 public Piece(Side owner, int stackLimit, params ShapeOrientation[] shapes)
 {
     Owner      = owner;
     StackLimit = stackLimit;
     Shapes     = new ShapeOrientationCollection(shapes, true);
 }
Example #5
0
 public Piece(Side owner, int stackLimit, ShapeOrientationCollection shapes)
 {
     Owner      = owner;
     StackLimit = stackLimit;
     Shapes     = shapes;
 }