コード例 #1
0
        public void CanInvertTuple()
        {
            var ints = Cantor.Inverse(69, 3);

            Assert.AreEqual(ints.Length, 3);
            Assert.AreEqual(ints[0], 1);
            Assert.AreEqual(ints[1], 2);
            Assert.AreEqual(ints[2], 3);
        }
コード例 #2
0
        public override void Init()
        {
            cells = new Dictionary <ulong, Cell>();
            uint rings = parameters.rings;

            for (int q = (int)(-rings); q <= rings; q++)
            {
                int r1 = (int)Math.Max(-rings, -q - rings);
                int r2 = (int)Math.Min(rings, -q + rings);

                for (int r = r1; r <= r2; r++)
                {
                    cells.Add(Cantor.Pairing(q, r), CreateCellAtPosition(new HexagonalPosition(q, r)));
                }
            }

            base.Init();
        }
コード例 #3
0
        public override void Init()
        {
            cells = new Dictionary <ulong, Cell>();

            for (int i = 0; i < parameters.shape.Width; i++)
            {
                for (int j = 0; j < parameters.shape.Height; j++)
                {
                    RectangularPosition pos = new RectangularPosition(i, j);

                    if (parameters.shape.ContainsAtPosition(pos))
                    {
                        cells.Add(Cantor.Pairing(i, j), CreateCellAtPosition(pos));
                    }
                }
            }

            base.Init();
        }
コード例 #4
0
        public override void Init()
        {
            cells = new Dictionary <ulong, Cell>();
            int side = (int)parameters.side;

            for (int q = 0; q < side; q++)
            {
                int r2 = side - q;

                for (int r = 0; r < r2; r++)
                {
                    int s1 = -q - r;
                    cells.Add(Cantor.Tuple(q, r, s1), CreateCellAtPosition(new TriangularPosition(q, r, s1)));

                    if ((q + r) < side - 1)
                    {
                        int s2 = s1 - 1;
                        cells.Add(Cantor.Tuple(q, r, s2), CreateCellAtPosition(new TriangularPosition(q, r, s2)));
                    }
                }
            }

            base.Init();
        }
コード例 #5
0
 protected override Cell CellAtPosition(RectangularPosition position)
 {
     return(cells[Cantor.Pairing(position.x, position.y)]);
 }
コード例 #6
0
 protected override Cell CellAtPosition(TriangularPosition position)
 {
     return(cells[Cantor.Tuple(position.q, position.r, position.s)]);
 }
コード例 #7
0
 protected override bool ContainsAtPosition(TriangularPosition position)
 {
     return(cells.ContainsKey(Cantor.Tuple(position.q, position.r, position.s)));
 }
コード例 #8
0
 public override int GetHashCode()
 {
     return((int)Cantor.Tuple(q, r, s));
 }
コード例 #9
0
        public void CanTuple()
        {
            var z = Cantor.Tuple(1, 2, 3);

            Assert.AreEqual(z, 69);
        }
コード例 #10
0
        public void CanPair()
        {
            var z = Cantor.Pair(1, 2);

            Assert.AreEqual(z, 8);
        }
コード例 #11
0
 public void CanInvertPair()
 {
     (int x, int y) = Cantor.Inverse(8);
     Assert.AreEqual(x, 1);
     Assert.AreEqual(y, 2);
 }
コード例 #12
0
 public override int GetHashCode()
 {
     return((int)Cantor.Pairing(q, r));
 }
コード例 #13
0
 protected override Cell CellAtPosition(HexagonalPosition position)
 {
     return(cells[Cantor.Pairing(position.q, position.r)]);
 }
コード例 #14
0
 protected override bool ContainsAtPosition(HexagonalPosition position)
 {
     return(cells.ContainsKey(Cantor.Pairing(position.q, position.r)));
 }