public OffSetCoordinate(int q, int r, OffsetCoordinateType offsetType) { Q = q; R = r; OffsetType = offsetType; }
/// <summary> /// Moves the in offset corrdinates. /// </summary> /// <returns>The in offset corrdinates.</returns> /// <param name="cooridinates">Cooridinates.</param> /// <param name="offsetType">Offset type.</param> /// <param name="direction">Direction.</param> public OffSetCoordinate MoveInOffsetCorrdinates(OffSetCoordinate cooridinates, OffsetCoordinateType offsetType, int direction) { Dictionary <int, Dictionary <int, int[]> > neighbors = new Dictionary <int, Dictionary <int, int[]> >(); int parity = 0; if (offsetType.Equals(OffsetCoordinateType.OddR)) { neighbors = new Dictionary <int, Dictionary <int, int[]> > { { 0, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 0, -1 } }, { 2, new int[] { -1, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } } } }, { 1, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { 0, 1 } }, { 5, new int[] { 1, 1 } } } } }; parity = cooridinates.R & 1; } if (offsetType.Equals(OffsetCoordinateType.EvenR)) { neighbors = new Dictionary <int, Dictionary <int, int[]> > { { 0, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { 0, 1 } }, { 5, new int[] { 1, 1 } } } }, { 1, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 0, -1 } }, { 2, new int[] { -1, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } } } } }; parity = cooridinates.R & 1; } if (offsetType.Equals(OffsetCoordinateType.OddQ)) { neighbors = new Dictionary <int, Dictionary <int, int[]> > { { 0, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, -1 } }, { 4, new int[] { -1, 0 } }, { 5, new int[] { 0, 1 } } } }, { 1, new Dictionary <int, int[]> { { 0, new int[] { 1, 1 } }, { 1, new int[] { 1, 0 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } } } } }; parity = cooridinates.Q & 1; } if (offsetType.Equals(OffsetCoordinateType.EvenQ)) { neighbors = new Dictionary <int, Dictionary <int, int[]> > { { 0, new Dictionary <int, int[]> { { 0, new int[] { 1, 1 } }, { 1, new int[] { 1, 0 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } } } }, { 1, new Dictionary <int, int[]> { { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } }, { 3, new int[] { -1, -1 } }, { 4, new int[] { -1, 0 } }, { 5, new int[] { 0, 1 } } } } }; parity = cooridinates.Q & 1; } int[] d = neighbors[parity][direction]; return(new OffSetCoordinate(cooridinates.Q + d[0], cooridinates.R + d[1], offsetType)); }