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); }
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(); }
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(); }
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(); }
protected override Cell CellAtPosition(RectangularPosition position) { return(cells[Cantor.Pairing(position.x, position.y)]); }
protected override Cell CellAtPosition(TriangularPosition position) { return(cells[Cantor.Tuple(position.q, position.r, position.s)]); }
protected override bool ContainsAtPosition(TriangularPosition position) { return(cells.ContainsKey(Cantor.Tuple(position.q, position.r, position.s))); }
public override int GetHashCode() { return((int)Cantor.Tuple(q, r, s)); }
public void CanTuple() { var z = Cantor.Tuple(1, 2, 3); Assert.AreEqual(z, 69); }
public void CanPair() { var z = Cantor.Pair(1, 2); Assert.AreEqual(z, 8); }
public void CanInvertPair() { (int x, int y) = Cantor.Inverse(8); Assert.AreEqual(x, 1); Assert.AreEqual(y, 2); }
public override int GetHashCode() { return((int)Cantor.Pairing(q, r)); }
protected override Cell CellAtPosition(HexagonalPosition position) { return(cells[Cantor.Pairing(position.q, position.r)]); }
protected override bool ContainsAtPosition(HexagonalPosition position) { return(cells.ContainsKey(Cantor.Pairing(position.q, position.r))); }