From cfb3074158465fd497587b054880319393611d58 Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Thu, 9 Jul 2020 10:14:48 +0200 Subject: [PATCH] Add testing script.py --- dominic/pairingtool.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/dominic/pairingtool.py b/dominic/pairingtool.py index 9db46d7..c626017 100644 --- a/dominic/pairingtool.py +++ b/dominic/pairingtool.py @@ -14,8 +14,10 @@ def unpairZ(z): lookup = [-10, 4, 1, 3, 0, 2] def isDiggingSpot(x, y): - val = lookup[(y % 5) + 1] - return (x % 5) == val + x, y = int(x), int(y) + val = lookup[(((y % 5)+5)%5) + 1] + out = ((x % 5)+ 5) % 5 == val + return out global offset offset = 10 @@ -30,4 +32,33 @@ def ithSpot(i): else: i = i - 1 j = j + 1 + +def adjustToQuadrant(i, x, z): + if i % 4 == 0: + return x, z + elif i % 4 == 1: + return -z-1, x + elif i % 4 == 2: + return z, -x-1 + elif i % 4 == 3: + return -z-1, -x-1 +def iTo2Dcoords(j): + i = j // 4 + quadrantI = j % 4 # 0-3 quadrant + counter = 0 # number of digging spots found + j = 0 # enumerate 2D plane + while True: + x, z = int(unpairX(j)), int(unpairZ(j)) # coords in first quadrant + x, z = adjustToQuadrant(quadrantI, x, z) # map coords correctly into other quadrants + if isDiggingSpot(x, z): + if counter == i: + return (x,z) + break + counter += 1 + j += 1 + +print(iTo2Dcoords(3)) + +# for i in range(10): +# print(iTo2Dcoords(i))