当前位置: 首页>>代码示例>>C#>>正文


C# MoveDirection.TurnClockwise方法代码示例

本文整理汇总了C#中MoveDirection.TurnClockwise方法的典型用法代码示例。如果您正苦于以下问题:C# MoveDirection.TurnClockwise方法的具体用法?C# MoveDirection.TurnClockwise怎么用?C# MoveDirection.TurnClockwise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoveDirection的用法示例。


在下文中一共展示了MoveDirection.TurnClockwise方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LookInDirection


//.........这里部分代码省略.........
        //                 * BrrMrr.
        //                 *  .....
        //                 *   ...
        //                 *    X
        //                 *
        //                 * X — the initial point
        //                 * M — rangeMiddle
        //                 * B — beginning point of iteration
        //                 *
        //                 * (in this example, distance == 3 and direction == MoveDirection.Up)
        //                 *
        //                 */
        //                
        //                Point rangeMiddle = this.MoveInDirection (direction, distance);
        //                Point newPoint = rangeMiddle.MoveInDirection (direction.TurnCounterClockwise(), distance);
        //                
        //                result.Add (newPoint);
        //                MoveDirection aroundDirection = direction.TurnClockwise();
        //                
        //                for (int i=0; i<distance*2 - 1; i++) {
        //                    newPoint = newPoint.MoveInDirection (aroundDirection);
        //                    result.Add (newPoint);
        //                }
        //                
        //            }
        //            
        //            return result;
        //        }
        /*
         * Here's how the return looks:
         *
         *     8
         *    678
         *   45678
         *  2345678
         * x12345678
         *  .345678
         *   .5678
         *    .78
         *     .
         *
         * x — the initial point
         * i — the points in result[i]
         *
         * notice that the return isn't symmetrical — so that LookInDirection for 4 directions don't intersect
         *
         * recursiveResult is the result of the same function with distance-1
         * unless you want some optimizations, it's safe to leave it at null
         *
         */
        public Point[][] LookInDirection(MoveDirection direction, int distance, Point[][] recursiveResult = null)
        {
            Point[][] result = new Point [distance + 1][];

            if (direction == MoveDirection.Stay || distance == 0) {

                result [0] = new Point[1];
                result [0] [0] = new Point (x, y);

            } else {

                if (recursiveResult == null)
                    LookInDirection (direction, distance - 1).CopyTo (result, 0);
                else
                    recursiveResult.CopyTo (result, 0);

                Point[] pointsAtDistance = new Point[distance];
                Point[] pointsAtPreviousDistance = result [distance - 1];

                if (distance == 1) {

                    pointsAtDistance [0] = pointsAtPreviousDistance [0].MoveInDirection (direction);

                } else {

                    bool evenDistance = (distance % 2) == 0;
                    int d = 0;

                    if (evenDistance && distance > 1) {
                        pointsAtDistance [0] =
                        pointsAtPreviousDistance [0].MoveInDirection (direction.TurnCounterClockwise ());
                        d = 1;
                    }

                    for (int i=0; i<distance-1; i++)
                        pointsAtDistance [i + d] =
                        pointsAtPreviousDistance [i].MoveInDirection (direction);

                    if (!evenDistance && distance > 1)
                        pointsAtDistance [distance - 1] =
                        pointsAtPreviousDistance [distance - 2].MoveInDirection (direction.TurnClockwise ());

                }

                result [distance] = pointsAtDistance;

            }

            return result;
        }
开发者ID:golergka,项目名称:genetic-ants,代码行数:101,代码来源:Point.cs


注:本文中的MoveDirection.TurnClockwise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。