コード例 #1
0
ファイル: Codel_specs.cs プロジェクト: Corniel/piet.net
        public void With_dp(int x, int y, DirectionPointer dp)
        {
            var expected = new Codel(x, y);
            var next     = new Codel(0, 0).Next(dp);

            Assert.AreEqual(expected, next);
        }
コード例 #2
0
ファイル: Codel.cs プロジェクト: Corniel/piet.net
 /// <summary>Moves to the next codel based on the <see cref="DirectionPointer"/>.</summary>
 public Codel Next(DirectionPointer dp)
 {
     return(dp switch
     {
         DirectionPointer.right => /**/ new Codel(X + 1, Y + 0),
         DirectionPointer.left => /* */ new Codel(X - 1, Y + 0),
         DirectionPointer.top => /*  */ new Codel(X + 0, Y - 1),
         DirectionPointer.down => /* */ new Codel(X + 0, Y + 1),
         _ => throw new ArgumentOutOfRangeException(nameof(dp)),
     });
コード例 #3
0
        public void From_1x1_form(DirectionPointer dp, CodelChooser cc)
        {
            var expected = new Codel(9, 0);
            var program  = Runner.Load("fibonacci_numbers.gif");
            var block    = program.SelectBlock(expected);
            var pointer  = Pointer.Initial.Rotate((int)dp).Switch((int)cc);

            var actual = block.Edge(pointer);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void From_complex_form(int x, int y, DirectionPointer dp, CodelChooser cc)
        {
            var expected = new Codel(x, y);
            var program  = Runner.Load("Snippets.edge.png");
            var block    = program.SelectBlock(new Codel(2, 2));
            var pointer  = Pointer.Initial.Rotate((int)dp).Switch((int)cc);

            var actual = block.Edge(pointer);

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
 public static DirectionPointer Rotate(this DirectionPointer dp, long steps)
 {
     return((DirectionPointer)((long)dp + steps).Modulo(4));
 }
コード例 #6
0
        public void With_dp_and_steps(DirectionPointer direction, int steps, DirectionPointer expected)
        {
            var rotated = direction.Rotate(steps);

            Assert.AreEqual(expected, rotated);
        }
コード例 #7
0
ファイル: ColorBlock.cs プロジェクト: Olfi01/PietPad
        public Codel FindFurthestCodel(DirectionPointer dp, CodelChooser cc)
        {
            int xFactor = 0, yFactor = 0;
            switch (dp)
            {
                case DirectionPointer.Right:
                    xFactor = 1;
                    break;
                case DirectionPointer.Down:
                    yFactor = 1;
                    break;
                case DirectionPointer.Left:
                    xFactor = -1;
                    break;
                case DirectionPointer.Up:
                    yFactor = -1;
                    break;
            }

            var edge = Codels.GroupBy(x => x.Position.x * xFactor + x.Position.y * yFactor).OrderBy(x => x.Key).Last();

            xFactor = 0; yFactor = 0;
            switch (dp)
            {
                case DirectionPointer.Right:
                    switch (cc)
                    {
                        case CodelChooser.Left:
                            yFactor = -1;
                            break;
                        case CodelChooser.Right:
                            yFactor = 1;
                            break;
                    }
                    break;
                case DirectionPointer.Down:
                    switch (cc)
                    {
                        case CodelChooser.Left:
                            xFactor = 1;
                            break;
                        case CodelChooser.Right:
                            xFactor = -1;
                            break;
                    }
                    break;
                case DirectionPointer.Left:
                    switch (cc)
                    {
                        case CodelChooser.Left:
                            yFactor = 1;
                            break;
                        case CodelChooser.Right:
                            yFactor = -1;
                            break;
                    }
                    break;
                case DirectionPointer.Up:
                    switch (cc)
                    {
                        case CodelChooser.Left:
                            xFactor = -1;
                            break;
                        case CodelChooser.Right:
                            xFactor = 1;
                            break;
                    }
                    break;
            }

            var codel = edge.OrderBy(x => x.Position.x * xFactor + x.Position.y * yFactor).Last();
            return codel;
        }