aboutsummaryrefslogtreecommitdiff
path: root/isrock.py
diff options
context:
space:
mode:
authorFeynman's Fedora <hdawg7797@yahoo.com>2019-06-29 23:06:59 -0400
committerFeynman's Fedora <hdawg7797@yahoo.com>2019-06-29 23:09:54 -0400
commitcf642ffb90f15495100b107582f11a7a0bae412f (patch)
treea7addbd7a2d4c7200d826c625d52a340fed4c83a /isrock.py
final commit
Diffstat (limited to 'isrock.py')
-rw-r--r--isrock.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/isrock.py b/isrock.py
new file mode 100644
index 0000000..085b25b
--- /dev/null
+++ b/isrock.py
@@ -0,0 +1,55 @@
+from hashlib import md5
+from sorter import Sorter
+
+rockmodp = Sorter() #positions of rockmod
+rockmodv = [] #values of rockmod
+rockmodt = [] #rock type (to include portals)
+
+def modrock(dim, state, type='n'): #type is by default normal; p is portal
+ if state and type == 'n':
+ type = 'n'
+ if dim in rockmodp:
+ loc = rockmodp.index(dim)
+ rockmodv[loc] = state
+ rockmodt[loc] = type
+ else:
+ loc = rockmodp.insert(dim)
+ rockmodv.insert(loc, state)
+ rockmodt.insert(loc, type)
+
+
+def isrock(density, dim, typereq=False): #if typereq, returns if a rock or portal
+ x, y = dim[0], dim[1]
+ m = md5()
+ m.update(intbyt(x))
+ m.update(intbyt(y))
+ rockpres = (bytint(m.digest()[:2])/(256**2) < density)
+ if dim in rockmodp:
+ loc = rockmodp.index(dim)
+ rockpres = rockmodv[loc]
+ if typereq:
+ return (rockpres, rockmodt[loc])
+ if typereq:
+ return (rockpres, 'n')
+ return rockpres
+
+def intbyt(num):
+ return int(num).to_bytes(8, 'big', signed=True)
+
+def bytint(byt):
+ return int.from_bytes(byt, byteorder='big')
+
+def save():
+ outtext = ''
+ for mvind in range(len(rockmodp)):
+ outtext += str(rockmodp[mvind][0]) + ' ' + str(rockmodp[mvind][1]) + ' ' + str(rockmodv[mvind]) + ' ' + str(rockmodt[mvind]) + '\n'
+ return outtext
+
+def load(data):
+ global rockmodp, rockmodv, rockmodt
+ rockmodp, rockmodv, rockmodt = Sorter(), [], []
+ for line in data:
+ line = line.split(' ')
+ ind = rockmodp.insert((int(line[0]), int(line[1])))
+ rockmodv.insert(ind, line[2] == 'True')
+ rockmodt.insert(ind, line[3])