diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..dc1502ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,110 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +#csv files +*.csv + +#png files +# *.png + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..d46cd3e9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\mrste\\.virtualenvs\\CS-Build-Week-2-_lfTzCd4\\Scripts\\python.exe" +} \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..637e1c4f --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +python-decouple = "*" +requests = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 00000000..c1b96a73 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,64 @@ +{ + "_meta": { + "hash": { + "sha256": "40ca981d597ce7f3965016abfbb4f4db88df55b1f70a8c5f6fc1c1992fdba2f3" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "certifi": { + "hashes": [ + "sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50", + "sha256:fd7c7c74727ddcf00e9acd26bba8da604ffec95bf1c2144e67aff7a8b50e6cef" + ], + "version": "==2019.9.11" + }, + "chardet": { + "hashes": [ + "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", + "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" + ], + "version": "==3.0.4" + }, + "idna": { + "hashes": [ + "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", + "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" + ], + "version": "==2.8" + }, + "python-decouple": { + "hashes": [ + "sha256:55c546b85b0c47a15a47a4312d451a437f7344a9be3e001660bccd93b637de95" + ], + "index": "pypi", + "version": "==3.3" + }, + "requests": { + "hashes": [ + "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", + "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" + ], + "index": "pypi", + "version": "==2.22.0" + }, + "urllib3": { + "hashes": [ + "sha256:a8a318824cc77d1fd4b2bec2ded92646630d7fe8619497b142c84a9e6f5a7293", + "sha256:f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745" + ], + "version": "==1.25.7" + } + }, + "develop": {} +} diff --git a/auto.py b/auto.py new file mode 100644 index 00000000..858a98bf --- /dev/null +++ b/auto.py @@ -0,0 +1,4 @@ +from utils import * +mappy = mapper() +mappy.create_starting_map() +mappy.auto_coins(acc=True,fly=True) \ No newline at end of file diff --git a/basic_utils.py b/basic_utils.py new file mode 100644 index 00000000..5276f57f --- /dev/null +++ b/basic_utils.py @@ -0,0 +1,186 @@ +class Queue(): + def __init__(self): + self.queue = [] + + def __repr__(self): + return f'{self.queue}' + + def enqueue(self, value): + self.queue.append(value) + + def dequeue(self): + if self.size() > 0: + return self.queue.pop(0) + else: + return None + + def size(self): + return len(self.queue) + + +class Stack(): + def __init__(self): + self.stack = [] + + def push(self, value): + self.stack.append(value) + + def pop(self): + if self.size() > 0: + return self.stack.pop() + else: + return None + + def size(self): + return len(self.stack) + + +class Graph: + """Represent a graph as a dictionary of vertices mapping labels to edges.""" + + def __init__(self): + self.vertices = {} + + def add_vertex(self, vertex): + """ + Add a vertex to the graph. + """ + if vertex not in self.vertices.keys(): + self.vertices[vertex] = set() + else: + pass + + def add_edge(self, v1, v2): + """ + Add a directed edge to the graph. + """ + if v1 and v2 in self.vertices.keys(): + # self.vertices[v2].add(v1) + self.vertices[v1].add(v2) + + def bft(self, starting_vertex): + """ + Print each vertex in breadth-first order + beginning from starting_vertex. + """ + ret_list = [] + if starting_vertex is None: + return None + my_q = Queue() + visited = [starting_vertex] + my_q.enqueue(starting_vertex) + while len(my_q.queue) > 0: + point = my_q.queue[0] + joins = self.vertices[point] + for j in joins: + if j not in visited: + my_q.enqueue(j) + visited.append(j) + # print(my_q.dequeue()) + ret = my_q.dequeue() + ret_list.append(ret) + return ret_list + + def dft(self, starting_vertex, chooser=None): + """ + Print each vertex in depth-first order + beginning from starting_vertex. + """ + ret_list = [] + if starting_vertex is None: + return None + my_s = Stack() + visited = [starting_vertex] + my_s.push(starting_vertex) + while len(my_s.stack) > 0: + point = my_s.stack[-1] + joins = self.vertices[point] + r = my_s.pop() # new code + ret_list.append(r) # new code + # print(r) ##changed to r from pop + if chooser is None: + pass + elif chooser == 'random': + joins = random.sample(joins, len(joins)) + elif chooser == 'shortest': + joins = find_longest_clique(point, self, visited) + for j in joins: + if j not in visited: + my_s.push(j) + visited.append(j) + return ret_list + + def dft_recursive(self, starting_vertex, visited=[]): + """ + Print each vertex in depth-first order + beginning from starting_vertex. + This should be done using recursion. + """ + print(starting_vertex) + visited.append(starting_vertex) + joins = self.vertices[starting_vertex] + if joins is None: + return None + for j in joins: + if j in visited: + pass + else: + self.dft_recursive(j, visited) + + def bfs(self, starting_vertex, destination_vertex): + """ + Return a list containing the shortest path from + starting_vertex to destination_vertex in + breath-first order. + """ + print('Starting BFS') + q = Queue() + visited = set() + q.enqueue([starting_vertex]) + print(f'Starting vertex: {starting_vertex}') + print(f'End Room: {destination_vertex}') + + while destination_vertex not in q.queue[0]: + # while q.queue[0][-1] != destination_vertex: + # print(q) + current_point = q.queue[0][-1] + # print(f'current point: {current_point}') + joins = self.vertices[current_point].values() + # print(joins) + for j in joins: + # print(f'J: {j}') + if j != '?' and j not in visited: + visited.add(j) + _ = [x for x in q.queue[0]] + _.append(j) + q.enqueue(_) + q.dequeue() + + return q.queue[0] + + def dfs(self, starting_vertex, destination_vertex): + """ + Return a list containing a path from + starting_vertex to destination_vertex in + depth-first order. + """ + s = Stack() + s.push([starting_vertex]) + + while destination_vertex not in s.stack[-1]: + current_point = s.stack[-1][-1] + + joins = self.vertices[current_point] + if joins is None: + s.pop() + else: + temp_list = [] + for j in joins: + _ = [x for x in s.stack[-1]] + _.append(j) + temp_list.append(_) + for tl in temp_list: + s.push(tl) + # s.pop() + + return s.stack[-1] diff --git a/cpu2.py b/cpu2.py new file mode 100644 index 00000000..3ca4f0bb --- /dev/null +++ b/cpu2.py @@ -0,0 +1,271 @@ +import sys +from datetime import datetime # for timer interrupt +ret_list = [] +# Opcodes: +ADD = 0b10100000 +AND = 0b10101000 +CALL = 0b01010000 +CMP = 0b10100111 +DEC = 0b01100110 +DIV = 0b10100011 +HLT = 0b00000001 +INC = 0b01100101 +IRET = 0b00010011 +JEQ = 0b01010101 +JLE = 0b01011001 +JLT = 0b01011000 +JMP = 0b01010100 +JNE = 0b01010110 +LD = 0b10000011 +LDI = 0b10000010 +MUL = 0b10100010 +OR = 0b10101010 +POP = 0b01000110 +PRA = 0b01001000 +PRN = 0b01000111 +PUSH = 0b01000101 +RET = 0b00010001 +SHL = 0b10101100 +ST = 0b10000100 +SUB = 0b10100001 +XOR = 0b10101011 +# Reserved general-purpose register numbers: +IM = 5 +IS = 6 +SP = 7 +# CMP flags: +FL_LT = 0b100 +FL_GT = 0b010 +FL_EQ = 0b001 +# IS flags +IS_TIMER = 0b00000001 +IS_KEYBOARD = 0b00000010 +class CPU: + def __init__(self): + self.pc = 0 # program counter + self.fl = 0 # flags + self.ie = 1 + self.halted = False + self.last_timer_int = None + self.inst_set_pc = False # True if this instruction set the PC + self.ram = [0] * 256 + self.reg = [0] * 8 + self.reg[SP] = 0xf4 + self.bt = { # branch table + ADD: self.op_add, + AND: self.op_and, + CALL: self.op_call, + CMP: self.op_cmp, + DEC: self.op_dec, + DIV: self.op_div, + HLT: self.op_hlt, + INC: self.op_inc, + IRET: self.op_iret, + JEQ: self.op_jeq, + JLE: self.op_jle, + JLT: self.op_jlt, + JMP: self.op_jmp, + JNE: self.op_jne, + LD: self.op_ld, + LDI: self.op_ldi, + MUL: self.op_mul, + OR: self.op_or, + POP: self.op_pop, + PRA: self.op_pra, + PRN: self.op_prn, + PUSH: self.op_push, + RET: self.op_ret, + SHL: self.op_shl, + ST: self.op_st, + SUB: self.op_sub, + XOR: self.op_xor, + } + def load(self, filename): + address = 0 + with open(filename) as fp: + for line in fp: + comment_split = line.split("#") + num = comment_split[0].strip() + if num == '': # ignore blanks + continue + val = int(num, 2) + self.ram[address] = val + address += 1 + def ram_write(self, mdr, mar): + self.ram[mar] = mdr + def ram_read(self, mar): + return self.ram[mar] + def push_val(self, val): + self.reg[SP] -= 1 + self.ram_write(val, self.reg[7]) + def pop_val(self): + val = self.ram_read(self.reg[7]) + self.reg[SP] += 1 + return val + def alu(self, op, reg_a, reg_b): + if op == "ADD": + self.reg[reg_a] += self.reg[reg_b] + elif op == "AND": + self.reg[reg_a] &= self.reg[reg_b] + elif op == "SUB": + self.reg[reg_a] -= self.reg[reg_b] + elif op == "MUL": + self.reg[reg_a] *= self.reg[reg_b] + elif op == "DIV": + self.reg[reg_a] /= self.reg[reg_b] + elif op == "DEC": + self.reg[reg_a] -= 1 + elif op == "INC": + self.reg[reg_a] += 1 + elif op == "CMP": + self.fl &= 0x11111000 # clear all CMP flags + if self.reg[reg_a] < self.reg[reg_b]: + self.fl |= FL_LT + elif self.reg[reg_a] > self.reg[reg_b]: + self.fl |= FL_GT + else: + self.fl |= FL_EQ + elif op == "OR": + self.reg[reg_a] |= self.reg[reg_b] + elif op == "SHL": + self.reg[reg_a] <<= self.reg[reg_b] + elif op == "XOR": + self.reg[reg_a] ^= self.reg[reg_b] + else: + raise Exception("Unsupported ALU operation") + def check_for_timer_int(self): + """Check the time to see if a timer interrupt should fire.""" + if self.last_timer_int == None: + self.last_timer_int = datetime.now() + now = datetime.now() + diff = now - self.last_timer_int + if diff.seconds >= 1: # OK, fire! + self.last_timer_int = now + self.reg[IS] |= IS_TIMER + def handle_ints(self): + if not self.ie: # see if interrupts enabled + return + # Mask out interrupts + masked_ints = self.reg[IM] & self.reg[IS] + for i in range(8): + # See if the interrupt triggered + if masked_ints & (1 << i): + self.ie = 0 # disable interrupts + self.reg[IS] &= ~(1 << i) # clear bit for this interrupt + # Save all the work on the stack + self.push_val(self.pc) + self.push_val(self.fl) + for r in range(7): + self.push_val(self.reg[r]) + # Look up the address vector and jump to it + self.pc = self.ram_read(0xf8 + i) + break # no more processing + def trace(self): + print(f"TRACE: %02X | %02X | %d | %02X %02X %02X |" % ( + self.pc, + self.fl, + self.ie, + self.ram_read(self.pc), + self.ram_read(self.pc + 1), + self.ram_read(self.pc + 2) + ), end='') + for i in range(8): + print(" %02X" % self.reg[i], end='') + print() + def run(self): + + while not self.halted: + # Interrupt cod + self.check_for_timer_int() # timer interrupt check + #self.check_for_keyboard_int() # keyboard interrupt check + self.handle_ints() # see if any interrupts occurre + # Normal instruction processing + #self.trace() + ir = self.ram[self.pc] + operand_a = self.ram_read(self.pc + 1) + operand_b = self.ram_read(self.pc + 2) + inst_size = ((ir >> 6) & 0b11) + 1 + self.inst_set_pc = ((ir >> 4) & 0b1) == 1 + if ir in self.bt: + self.bt[ir](operand_a, operand_b) + else: + raise Exception(f"Invalid instruction {hex(ir)} at address {hex(self.pc)}") + # If the instruction didn't set the PC, just move to the next instruction + if not self.inst_set_pc: + self.pc += inst_size + return ret_list + def op_ldi(self, operand_a, operand_b): + self.reg[operand_a] = operand_b + def op_prn(self, operand_a, operand_b): + print(self.reg[operand_a]) + def op_pra(self, operand_a, operand_b): + print(chr(self.reg[operand_a]), end='') + ret_list.append(chr(self.reg[operand_a])) + sys.stdout.flush() + def op_add(self, operand_a, operand_b): + self.alu("ADD", operand_a, operand_b) + def op_and(self, operand_a, operand_b): + self.alu("AND", operand_a, operand_b) + def op_sub(self, operand_a, operand_b): + self.alu("SUB", operand_a, operand_b) + def op_mul(self, operand_a, operand_b): + self.alu("MUL", operand_a, operand_b) + def op_div(self, operand_a, operand_b): + self.alu("DIV", operand_a, operand_b) + def op_dec(self, operand_a, operand_b): + self.alu("DEC", operand_a, None) + def op_inc(self, operand_a, operand_b): + self.alu("INC", operand_a, None) + def op_or(self, operand_a, operand_b): + self.alu("OR", operand_a, operand_b) + def op_xor(self, operand_a, operand_b): + self.alu("XOR", operand_a, operand_b) + def op_pop(self, operand_a, operand_b): + self.reg[operand_a] = self.pop_val() + def op_push(self, operand_a, operand_b): + self.push_val(self.reg[operand_a]) + def op_call(self, operand_a, operand_b): + self.push_val(self.pc + 2) + self.pc = self.reg[operand_a] + def op_ret(self, operand_a, operand_b): + self.pc = self.pop_val() + def op_ld(self, operand_a, operand_b): + self.reg[operand_a] = self.ram_read(self.reg[operand_b]) + def op_shl(self, operand_a, operand_b): + self.alu("SHL", operand_a, operand_b) + def op_st(self, operand_a, operand_b): + self.ram_write(self.reg[operand_b], self.reg[operand_a]) + def op_jmp(self, operand_a, operand_b): + self.pc = self.reg[operand_a] + def op_jeq(self, operand_a, operand_b): + if self.fl & FL_EQ: + self.pc = self.reg[operand_a] + else: + self.inst_set_pc = False + def op_jle(self, operand_a, operand_b): + if self.fl & FL_LT or self.fl & FL_EQ: + self.pc = self.reg[operand_a] + else: + self.inst_set_pc = False + def op_jlt(self, operand_a, operand_b): + if self.fl & FL_LT: + self.pc = self.reg[operand_a] + else: + self.inst_set_pc = False + def op_jne(self, operand_a, operand_b): + if not self.fl & FL_EQ: + self.pc = self.reg[operand_a] + else: + self.inst_set_pc = False + def op_cmp(self, operand_a, operand_b): + self.alu("CMP", operand_a, operand_b) + def op_iret(self, operand_a, operand_b): + # restore work from stack + for i in range(6, -1, -1): + self.reg[i] = self.pop_val() + self.fl = self.pop_val() + self.pc = self.pop_val() + # enable interrupts + self.ie = 1 + def op_hlt(self, operand_a, operand_b): + self.halted = True \ No newline at end of file diff --git a/explore.py b/explore.py new file mode 100644 index 00000000..a861b541 --- /dev/null +++ b/explore.py @@ -0,0 +1,9 @@ +from utils import * + +mappy = mapper() +mappy.accumulate=True #set pick up items to false +mappy.import_text_map=True +mappy.create_starting_map() + +# mappy.explore_random(150) +mappy.get_treasure() diff --git a/explorer_guide.md b/explorer_guide.md new file mode 100644 index 00000000..046fb2b3 --- /dev/null +++ b/explorer_guide.md @@ -0,0 +1,59 @@ +# Explorer guide + +either run from command line with + +``` +python explore.py +``` + +or load up python from command line and import * from utils + +basic_utils.py is just all the old graphs, stack, queue and search funtions from our assignments + +## to initialize from python + +```python +mappy = mapper() +mappy.create_starting_map() +``` + +## set your custom variables +```python +mappy.accumulate = True # auto pick up items +mappy.save_map_to_text = True #overwrite current map.txt with fresh map.txt +mappy.import_text_map = True #load current map.txt as starting map #MUST BE DONE BEFORE create_starting_map + #if you don't want fresh map +``` +## show your latest map +```python +mappy.my_map.vertices +``` + +## randomly explore + +```python +mappy.explore_random(50) #exploring 50 unkown rooms (not including backtracking) +``` + +## take action in current room given lastest info from server + +```python +mappy.room_check() #given how you have set certain variables like pray or accumulate will automate actions + # given certain cues from the server json responses +``` + +## examples of working commands +```python +mappy.get_info('init') # initialize and get current room details +mappy.get_info('move','n') # move north +mappy.get_info('backtrack','e','254') # back track specifying room and direction + +mappy.action('take','tiny treasure') # pick up some treasure +mappy.action('drop','tiny treasure') # drop some treasure in your inventory +mappy.action('sell','tiny treasure') # sell some treasure in your inventory +mappy.action('sell_confirm','tiny treasure') # confirm sell some treasure in your inventory +mappy.action('examine','tiny treasure') # examine tiny treasure in your inventory +mappy.action('status') # get status update +mappy.action('pray') # pray in shrine room + +``` \ No newline at end of file diff --git a/find.py b/find.py new file mode 100644 index 00000000..220a5216 --- /dev/null +++ b/find.py @@ -0,0 +1,2 @@ +my_dict ={"0": {"n": 10, "s": 2, "e": 4, "w": 1}, "1": {"e": 0}, "2": {"n": 0, "s": 6, "e": 3}, "3": {"s": 9, "e": 5, "w": 2}, "9": {"n": 3, "s": 12, "e": 11}, "11": {"e": 17, "w": 9}, "17": {"n": 24, "e": 42, "w": 11}, "24": {"s": 17}, "42": {"n": 44, "s": 80, "e": 118, "w": 17}, "44": {"s": 42}, "80": {"n": 42, "s": 81, "e": 86}, "81": {"n": 80}, "86": {"s": 96, "e": 90, "w": 80}, "90": {"e": 178, "w": 86}, "178": {"n": 209, "e": 243, "w": 90}, "243": {"s": 293, "e": 256, "w": 178}, "293": {"n": 243}, "256": {"s": 360, "e": 327, "w": 243}, "327": {"e": 427, "w": 256}, "427": {"e": 430, "w": 327}, "430": {"n": 443, "e": 439, "w": 427}, "443": {"s": 430, "e": 471}, "471": {"w": 443}, "439": {"w": 430}, "360": {"n": 256, "e": 398}, "398": {"e": 438, "w": 360}, "438": {"e": 465, "w": 398}, "465": {"e": 498, "w": 438}, "498": {"w": 465}, "209": {"s": 178}, "96": {"n": 86, "e": 97}, "97": {"e": 181, "w": 96}, "181": {"w": 97}, "118": {"e": 137, "w": 42}, "137": {"w": 118}, "12": {"n": 9, "s": 18, "e": 14, "w": 21}, "14": {"s": 34, "e": 37, "w": 12}, "37": {"w": 14}, "34": {"n": 14, "s": 50, "e": 35}, "50": {"n": 34, "s": 89}, "35": {"s": 52, "w": 34}, "52": {"n": 35, "s": 68, "e": 75}, "68": {"n": 52, "e": 100}, "100": {"s": 106, "e": 112, "w": 68}, "106": {"n": 100, "s": 111, "w": 135}, "111": {"n": 106, "s": 367, "e": 158}, "367": {"n": 111}, "158": {"s": 167, "w": 111}, "167": {"n": 158, "s": 262, "e": 260}, "260": {"w": 167}, "262": {"n": 167, "s": 370, "e": 358}, "358": {"e": 401, "w": 262}, "401": {"w": 358}, "370": {"n": 262, "s": 434, "e": 407}, "434": {"n": 370}, "407": {"s": 496, "w": 370}, "496": {"n": 407}, "135": {"s": 150, "e": 106}, "150": {"n": 135, "w": 166}, "166": {"s": 198, "e": 150, "w": 117}, "198": {"n": 166, "s": 239, "e": 199}, "239": {"n": 198, "w": 244}, "244": {"n": 131, "e": 239}, "131": {"n": 117, "s": 244, "w": 138}, "138": {"s": 211, "e": 131, "w": 195}, "195": {"s": 228, "e": 138, "w": 225}, "225": {"s": 278, "e": 195}, "278": {"n": 225}, "228": {"n": 195, "s": 281}, "281": {"n": 228, "s": 318, "e": 309, "w": 317}, "318": {"n": 281, "s": 487}, "487": {"n": 318, "s": 489}, "489": {"n": 487}, "309": {"s": 333, "e": 326, "w": 281}, "333": {"n": 309, "s": 378}, "378": {"n": 333}, "326": {"s": 342, "w": 309}, "342": {"n": 326, "s": 432}, "432": {"n": 342}, "317": {"s": 387, "e": 281, "w": 409}, "387": {"n": 317, "s": 417, "w": 431}, "431": {"e": 387, "w": 492}, "492": {"e": 431}, "417": {"n": 387}, "409": {"e": 317}, "211": {"n": 138}, "117": {"n": 108, "s": 131, "e": 166, "w": 133}, "133": {"e": 117, "w": 173}, "173": {"e": 133, "w": 214}, "214": {"n": 194, "e": 173, "w": 226}, "194": {"s": 214, "w": 129}, "129": {"n": 126, "e": 194, "w": 170}, "170": {"e": 129}, "126": {"n": 98, "s": 129}, "98": {"n": 102, "s": 126, "e": 70, "w": 109}, "109": {"s": 185, "e": 98, "w": 175}, "175": {"s": 183, "e": 109, "w": 179}, "179": {"s": 233, "e": 175, "w": 213}, "213": {"e": 179, "w": 420}, "420": {"s": 444, "e": 213, "w": 437}, "437": {"e": 420, "w": 497}, "497": {"e": 437}, "444": {"n": 420, "w": 490}, "490": {"e": 444, "w": 493}, "493": {"e": 490}, "233": {"n": 179, "w": 238}, "238": {"e": 233}, "183": {"n": 175, "s": 229}, "229": {"n": 183, "s": 250, "w": 236}, "236": {"s": 264, "e": 229}, "264": {"n": 236, "s": 274, "w": 273}, "273": {"n": 343, "e": 264}, "343": {"s": 273, "w": 351}, "351": {"s": 491, "e": 343, "w": 478}, "478": {"e": 351}, "491": {"n": 351}, "274": {"n": 264, "w": 308}, "308": {"e": 274}, "250": {"n": 229, "s": 294, "e": 289}, "294": {"n": 250, "s": 334}, "334": {"n": 294, "s": 393, "e": 341, "w": 391}, "341": {"s": 449, "w": 334}, "449": {"n": 341}, "393": {"n": 334, "s": 482}, "482": {"n": 393}, "391": {"s": 396, "e": 334, "w": 428}, "396": {"n": 391}, "428": {"e": 391}, "289": {"w": 250}, "185": {"n": 109}, "102": {"s": 98, "w": 142}, "142": {"e": 102, "w": 159}, "159": {"e": 142, "w": 196}, "196": {"n": 222, "e": 159, "w": 197}, "197": {"n": 232, "e": 196, "w": 276}, "232": {"n": 272, "s": 197, "w": 235}, "235": {"n": 330, "e": 232, "w": 355}, "330": {"n": 369, "s": 235, "w": 383}, "383": {"e": 330, "w": 495}, "495": {"e": 383}, "369": {"n": 400, "s": 330, "w": 376}, "400": {"s": 369}, "376": {"e": 369}, "355": {"e": 235}, "272": {"n": 295, "s": 232}, "295": {"s": 272}, "276": {"e": 197, "w": 419}, "419": {"e": 276}, "222": {"n": 305, "s": 196}, "305": {"n": 365, "s": 222}, "365": {"s": 305}, "70": {"s": 163, "e": 60, "w": 98}, "60": {"n": 45, "e": 36, "w": 70}, "36": {"s": 48, "e": 22, "w": 60}, "22": {"n": 18, "s": 78, "w": 36}, "18": {"n": 12, "s": 22, "w": 25}, "21": {"e": 12, "w": 29}, "29": {"s": 45, "e": 21, "w": 49}, "49": {"s": 79, "e": 29, "w": 136}, "136": {"e": 49, "w": 148}, "148": {"e": 136, "w": 292}, "292": {"n": 301, "e": 148}, "301": {"n": 304, "s": 292}, "304": {"s": 301}, "79": {"n": 49}, "45": {"n": 29, "s": 60}, "48": {"n": 36, "s": 105, "w": 149}, "149": {"e": 48}, "105": {"n": 48, "w": 202}, "202": {"e": 105}, "78": {"n": 22, "s": 108}, "108": {"n": 78, "s": 117, "e": 93}, "93": {"n": 89, "w": 108}, "89": {"n": 50, "s": 93}, "75": {"e": 85, "w": 52}, "85": {"e": 154, "w": 75}, "154": {"e": 193, "w": 85}, "193": {"e": 251, "w": 154}, "251": {"e": 315, "w": 193}, "315": {"w": 251}, "112": {"s": 141, "e": 140, "w": 100}, "140": {"w": 112}, "141": {"n": 112, "e": 156}, "156": {"s": 168, "e": 164, "w": 141}, "168": {"n": 156, "e": 340}, "340": {"w": 168}, "164": {"n": 217, "e": 298, "w": 156}, "217": {"s": 164, "e": 247}, "247": {"e": 261, "w": 217}, "261": {"s": 277, "e": 322, "w": 247}, "322": {"n": 382, "e": 435, "w": 261}, "382": {"s": 322, "e": 388}, "388": {"e": 477, "w": 382}, "477": {"e": 483, "w": 388}, "483": {"w": 477}, "435": {"w": 322}, "277": {"n": 261, "e": 323}, "323": {"e": 433, "w": 277}, "433": {"s": 455, "e": 460, "w": 323}, "455": {"n": 433}, "460": {"w": 433}, "298": {"s": 324, "w": 164}, "324": {"n": 298, "s": 349, "e": 354}, "349": {"n": 324, "s": 352, "e": 384, "w": 356}, "356": {"e": 349}, "352": {"n": 349, "s": 362, "e": 485}, "485": {"w": 352}, "362": {"n": 352, "s": 399, "w": 463}, "399": {"n": 362, "s": 467}, "467": {"n": 399}, "463": {"s": 468, "e": 362}, "468": {"n": 463}, "384": {"w": 349}, "354": {"w": 324}, "25": {"e": 18}, "5": {"w": 3}, "6": {"n": 2, "w": 7}, "7": {"n": 8, "e": 6, "w": 56}, "8": {"s": 7, "w": 16}, "16": {"n": 58, "e": 8, "w": 67}, "58": {"s": 16, "w": 65}, "65": {"n": 74, "e": 58, "w": 139}, "139": {"e": 65, "w": 188}, "188": {"e": 139, "w": 335}, "335": {"e": 188, "w": 366}, "366": {"e": 335}, "74": {"n": 87, "s": 65, "w": 161}, "161": {"e": 74}, "87": {"s": 74}, "67": {"e": 16, "w": 162}, "162": {"e": 67}, "56": {"e": 7, "w": 61}, "61": {"e": 56, "w": 171}, "171": {"e": 61}, "10": {"n": 19, "s": 0, "w": 43}, "19": {"n": 20, "s": 10, "w": 77}, "20": {"n": 63, "s": 19, "e": 27, "w": 46}, "63": {"n": 72, "s": 20, "w": 73}, "72": {"s": 63, "w": 76}, "76": {"n": 83, "e": 72, "w": 110}, "110": {"e": 76}, "83": {"s": 76, "e": 130, "w": 125}, "125": {"n": 165, "e": 83, "w": 237}, "165": {"n": 203, "s": 125, "w": 204}, "203": {"n": 268, "s": 165, "e": 299}, "268": {"s": 203, "e": 411, "w": 312}, "411": {"w": 268}, "312": {"n": 328, "e": 268}, "328": {"n": 332, "s": 312, "e": 357, "w": 363}, "363": {"n": 372, "e": 328}, "372": {"n": 441, "s": 363}, "441": {"s": 372}, "332": {"n": 350, "s": 328}, "350": {"n": 436, "s": 332, "e": 404}, "436": {"s": 350}, "404": {"n": 481, "w": 350}, "481": {"s": 404}, "357": {"w": 328}, "299": {"e": 311, "w": 203}, "311": {"w": 299}, "204": {"n": 219, "e": 165, "w": 216}, "219": {"s": 204}, "216": {"n": 234, "e": 204, "w": 218}, "234": {"n": 368, "s": 216, "w": 252}, "252": {"n": 284, "e": 234}, "284": {"n": 302, "s": 252, "w": 303}, "303": {"n": 361, "e": 284, "w": 405}, "405": {"n": 406, "e": 303}, "406": {"s": 405, "w": 415}, "415": {"e": 406, "w": 418}, "418": {"n": 425, "s": 474, "e": 415}, "425": {"s": 418, "w": 469}, "469": {"e": 425}, "474": {"n": 418}, "361": {"n": 408, "s": 303}, "408": {"n": 458, "s": 361, "w": 423}, "423": {"e": 408, "w": 454}, "454": {"n": 470, "e": 423}, "470": {"s": 454}, "458": {"s": 408, "w": 459}, "459": {"e": 458}, "302": {"n": 422, "s": 284}, "422": {"n": 426, "s": 302}, "426": {"n": 457, "s": 422}, "457": {"n": 461, "s": 426}, "461": {"s": 457}, "368": {"s": 234}, "218": {"s": 263, "e": 216, "w": 242}, "242": {"n": 287, "s": 259, "e": 218, "w": 275}, "287": {"s": 242, "w": 339}, "339": {"e": 287, "w": 445}, "445": {"n": 447, "e": 339, "w": 450}, "450": {"e": 445}, "447": {"s": 445}, "275": {"e": 242, "w": 456}, "456": {"e": 275, "w": 499}, "499": {"e": 456}, "259": {"n": 242, "w": 310}, "310": {"e": 259, "w": 412}, "412": {"s": 488, "e": 310}, "488": {"n": 412}, "263": {"n": 218}, "237": {"e": 125, "w": 245}, "245": {"s": 254, "e": 237}, "254": {"n": 245, "w": 314}, "314": {"e": 254}, "130": {"w": 83}, "73": {"e": 63}, "27": {"n": 40, "s": 28, "e": 30, "w": 20}, "40": {"s": 27}, "28": {"n": 27}, "30": {"s": 31, "e": 32, "w": 27}, "32": {"n": 39, "e": 54, "w": 30}, "39": {"n": 53, "s": 32, "e": 51, "w": 41}, "53": {"n": 95, "s": 39, "w": 88}, "88": {"e": 53, "w": 122}, "122": {"n": 124, "e": 88}, "124": {"n": 157, "s": 122}, "157": {"n": 210, "s": 124, "w": 182}, "210": {"s": 157}, "182": {"e": 157, "w": 208}, "208": {"e": 182}, "95": {"n": 119, "s": 53, "w": 115}, "115": {"n": 116, "e": 95}, "116": {"n": 132, "s": 115}, "132": {"s": 116}, "119": {"n": 134, "s": 95}, "134": {"n": 147, "s": 119, "e": 144}, "144": {"e": 155, "w": 134}, "155": {"s": 187, "e": 316, "w": 144}, "187": {"n": 155}, "316": {"n": 344, "w": 155}, "344": {"n": 392, "s": 316, "e": 390}, "390": {"w": 344}, "392": {"s": 344, "e": 462}, "462": {"w": 392}, "147": {"n": 200, "s": 134, "e": 153, "w": 151}, "153": {"e": 329, "w": 147}, "329": {"w": 153}, "151": {"n": 172, "e": 147, "w": 207}, "207": {"n": 231, "e": 151, "w": 290}, "231": {"s": 207, "w": 248}, "248": {"n": 296, "e": 231, "w": 280}, "280": {"n": 325, "e": 248}, "325": {"n": 353, "s": 280, "w": 374}, "374": {"e": 325}, "353": {"s": 325}, "296": {"s": 248}, "290": {"e": 207}, "172": {"n": 267, "s": 151}, "267": {"n": 285, "s": 172, "w": 271}, "285": {"n": 286, "s": 267}, "286": {"n": 336, "s": 285, "w": 291}, "336": {"s": 286}, "291": {"n": 410, "e": 286, "w": 347}, "347": {"n": 452, "s": 442, "e": 291}, "452": {"s": 347}, "442": {"n": 347}, "410": {"s": 291}, "271": {"n": 337, "e": 267}, "337": {"s": 271}, "200": {"n": 227, "s": 147, "e": 206}, "227": {"n": 269, "s": 200}, "269": {"n": 319, "s": 227}, "319": {"n": 359, "s": 269, "e": 345}, "359": {"s": 319}, "345": {"s": 375, "w": 319}, "375": {"n": 345, "e": 385}, "385": {"w": 375}, "206": {"n": 288, "e": 380, "w": 200}, "288": {"s": 206}, "380": {"n": 424, "w": 206}, "424": {"s": 380, "e": 473}, "473": {"e": 494, "w": 424}, "494": {"w": 473}, "51": {"n": 69, "e": 57, "w": 39}, "57": {"e": 145, "w": 51}, "145": {"n": 174, "e": 220, "w": 57}, "220": {"w": 145}, "174": {"n": 192, "s": 145, "e": 224}, "224": {"w": 174}, "192": {"n": 201, "s": 174, "e": 223}, "201": {"s": 192}, "223": {"n": 283, "w": 192}, "283": {"n": 331, "s": 223, "e": 313}, "331": {"s": 283, "e": 446}, "446": {"e": 466, "w": 331}, "466": {"s": 486, "e": 472, "w": 446}, "486": {"n": 466}, "472": {"w": 466}, "313": {"w": 283}, "69": {"n": 94, "s": 51, "e": 103}, "94": {"n": 152, "s": 69}, "152": {"s": 94}, "103": {"n": 160, "w": 69}, "160": {"s": 103}, "41": {"e": 39}, "54": {"w": 32}, "31": {"n": 30, "e": 33}, "33": {"e": 38, "w": 31}, "38": {"s": 59, "e": 66, "w": 33}, "59": {"n": 38, "s": 104, "e": 92}, "92": {"w": 59}, "104": {"n": 59, "e": 107}, "107": {"s": 120, "e": 121, "w": 104}, "120": {"n": 107, "e": 127}, "127": {"e": 184, "w": 120}, "184": {"e": 221, "w": 127}, "221": {"s": 253, "e": 240, "w": 184}, "240": {"n": 249, "e": 386, "w": 221}, "249": {"n": 265, "s": 240, "e": 282}, "282": {"w": 249}, "265": {"n": 279, "s": 249, "e": 270}, "279": {"s": 265}, "270": {"n": 416, "e": 338, "w": 265}, "338": {"s": 379, "w": 270}, "379": {"n": 338, "e": 395}, "395": {"s": 403, "e": 421, "w": 379}, "421": {"n": 440, "w": 395}, "440": {"s": 421, "w": 476}, "476": {"e": 440}, "403": {"n": 395}, "416": {"s": 270}, "386": {"e": 414, "w": 240}, "414": {"w": 386}, "253": {"n": 221, "e": 258}, "258": {"e": 306, "w": 253}, "306": {"e": 397, "w": 258}, "397": {"w": 306}, "121": {"n": 128, "e": 143, "w": 107}, "143": {"e": 212, "w": 121}, "212": {"w": 143}, "128": {"s": 121, "e": 189}, "189": {"e": 255, "w": 128}, "255": {"w": 189}, "66": {"n": 169, "e": 123, "w": 38}, "169": {"s": 66, "e": 186}, "186": {"e": 205, "w": 169}, "205": {"s": 241, "e": 479, "w": 186}, "479": {"w": 205}, "241": {"n": 205, "e": 266}, "266": {"w": 241}, "123": {"w": 66}, "46": {"e": 20, "w": 62}, "62": {"n": 64, "e": 46, "w": 84}, "84": {"e": 62, "w": 91}, "91": {"n": 180, "s": 101, "e": 84, "w": 99}, "180": {"s": 91}, "99": {"n": 190, "e": 91, "w": 146}, "190": {"s": 99}, "146": {"n": 215, "s": 177, "e": 99, "w": 257}, "257": {"n": 320, "e": 146, "w": 364}, "364": {"n": 429, "s": 381, "e": 257, "w": 448}, "429": {"s": 364}, "448": {"e": 364}, "381": {"n": 364, "w": 394}, "394": {"e": 381}, "320": {"n": 348, "s": 257}, "348": {"s": 320}, "177": {"n": 146, "w": 346}, "346": {"e": 177}, "215": {"n": 246, "s": 146}, "246": {"s": 215}, "101": {"n": 91, "w": 113}, "113": {"s": 114, "e": 101}, "114": {"n": 113, "w": 176}, "176": {"e": 114, "w": 402}, "402": {"e": 176, "w": 451}, "451": {"e": 402, "w": 453}, "453": {"s": 464, "e": 451}, "464": {"n": 453}, "64": {"s": 62, "w": 82}, "82": {"n": 191, "e": 64}, "191": {"s": 82}, "77": {"e": 19}, "43": {"e": 10, "w": 47}, "47": {"n": 71, "e": 43}, "71": {"s": 47}, "4": {"n": 23, "e": 13, "w": 0}, "13": {"e": 15, "w": 4}, "15": {"w": 13}, "23": {"s": 4, "e": 26}, "26": {"e": 55, "w": 23}, "55": {"w": 26}, "163": {"n": 70}, "226": {"s": 300, "e": 214}, "300": {"n": 226, "s": 377, "w": 389}, "389": {"e": 300}, "377": {"n": 300}, "199": {"s": 230, "w": 198}, "230": {"n": 199, "s": 307, "e": 297}, "307": {"n": 230, "s": 373, "e": 371, "w": 321}, "373": {"n": 307, "s": 480}, "480": {"n": 373}, "371": {"s": 475, "w": 307}, "475": {"n": 371, "s": 484}, "484": {"n": 475}, "321": {"s": 413, "e": 307}, "413": {"n": 321}, "297": {"w": 230}} +print(len(my_dict), "LENGTH") diff --git a/hinter.ls8 b/hinter.ls8 new file mode 100644 index 00000000..2ace2b17 --- /dev/null +++ b/hinter.ls8 @@ -0,0 +1,167 @@ +10000010 +00000001 +01001101 +01001000 +00000001 +10000010 +00000001 +01101001 +01001000 +00000001 +10000010 +00000001 +01101110 +01001000 +00000001 +10000010 +00000001 +01100101 +01001000 +00000001 +10000010 +00000001 +00100000 +01001000 +00000001 +10000010 +00000001 +01111001 +01001000 +00000001 +10000010 +00000001 +01101111 +01001000 +00000001 +10000010 +00000001 +01110101 +01001000 +00000001 +10000010 +00000001 +01110010 +01001000 +00000001 +10000010 +00000001 +00100000 +01001000 +00000001 +10000010 +00000001 +01100011 +01001000 +00000001 +10000010 +00000001 +01101111 +01001000 +00000001 +10000010 +00000001 +01101001 +01001000 +00000001 +10000010 +00000001 +01101110 +01001000 +00000001 +10000010 +00000001 +00100000 +01001000 +00000001 +10000010 +00000001 +01101001 +01001000 +00000001 +10000010 +00000001 +01101110 +01001000 +00000001 +10000010 +00000001 +00100000 +01001000 +00000001 +10000010 +00000001 +01110010 +01001000 +00000001 +10000010 +00000001 +01101111 +01001000 +00000001 +10000010 +00000001 +01101111 +01001000 +00000001 +10000010 +00000001 +01101101 +01001000 +00000001 +10000010 +00000001 +00100000 +01001000 +00000001 +10000010 +00000001 +00000000 +10000010 +00000010 +11110101 +10101000 +00000001 +00000010 +10000010 +00000010 +00110011 +10101011 +00000001 +00000010 +01001000 +00000001 +10000010 +00000001 +00110101 +10000010 +00000010 +00000000 +10101000 +00000001 +00000010 +10000010 +00000010 +00111000 +10101011 +00000001 +00000010 +01001000 +00000001 +10000010 +00000001 +11001100 +10000010 +00000010 +01110110 +10101000 +00000001 +00000010 +10000010 +00000010 +01110111 +10101011 +00000001 +00000010 +01001000 +00000001 +00000001 diff --git a/ls8.py b/ls8.py new file mode 100644 index 00000000..06b94d77 --- /dev/null +++ b/ls8.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +"""Main.""" + +import sys +from cpu2 import * + +cpu = CPU() + +cpu.load('hinter.ls8') +cpu.run() \ No newline at end of file diff --git a/map.txt b/map.txt new file mode 100644 index 00000000..dac4384a --- /dev/null +++ b/map.txt @@ -0,0 +1 @@ +{"483": {"w": 477}, "477": {"e": 483, "w": 388}, "388": {"e": 477, "w": 382}, "382": {"s": 322, "e": 388}, "322": {"n": 382, "e": 435, "w": 261}, "261": {"s": 277, "e": 322, "w": 247}, "247": {"e": 261, "w": 217}, "217": {"s": 164, "e": 247}, "164": {"n": 217, "e": 298, "w": 156}, "156": {"s": 168, "e": 164, "w": 141}, "141": {"n": 112, "e": 156}, "112": {"s": 141, "e": 140, "w": 100}, "100": {"s": 106, "e": 112, "w": 68}, "68": {"n": 52, "e": 100}, "52": {"n": 35, "s": 68, "e": 75}, "75": {"e": 85, "w": 52}, "85": {"e": 154, "w": 75}, "154": {"e": 193, "w": 85}, "193": {"e": 251, "w": 154}, "251": {"e": 315, "w": 193}, "315": {"w": 251}, "35": {"s": 52, "w": 34}, "34": {"n": 14, "s": 50, "e": 35}, "50": {"n": 34, "s": 89}, "89": {"n": 50, "s": 93}, "93": {"n": 89, "w": 108}, "108": {"n": 78, "s": 117, "e": 93}, "117": {"n": 108, "s": 131, "e": 166, "w": 133}, "131": {"n": 117, "s": 244, "w": 138}, "138": {"s": 211, "e": 131, "w": 195}, "195": {"s": 228, "e": 138, "w": 225}, "225": {"s": 278, "e": 195}, "278": {"n": 225}, "228": {"n": 195, "s": 281}, "281": {"n": 228, "s": 318, "e": 309, "w": 317}, "309": {"s": 333, "e": 326, "w": 281}, "333": {"n": 309, "s": 378}, "378": {"n": 333}, "326": {"s": 342, "w": 309}, "342": {"n": 326, "s": 432}, "432": {"n": 342}, "317": {"s": 387, "e": 281, "w": 409}, "409": {"e": 317}, "387": {"n": 317, "s": 417, "w": 431}, "431": {"e": 387, "w": 492}, "492": {"e": 431}, "417": {"n": 387}, "318": {"n": 281, "s": 487}, "487": {"n": 318, "s": 489}, "489": {"n": 487}, "211": {"n": 138}, "244": {"n": 131, "e": 239}, "239": {"n": 198, "w": 244}, "198": {"n": 166, "s": 239, "e": 199}, "166": {"s": 198, "e": 150, "w": 117}, "133": {"e": 117, "w": 173}, "173": {"e": 133, "w": 214}, "214": {"n": 194, "e": 173, "w": 226}, "226": {"s": 300, "e": 214}, "300": {"n": 226, "s": 377, "w": 389}, "377": {"n": 300}, "389": {"e": 300}, "194": {"s": 214, "w": 129}, "129": {"n": 126, "e": 194, "w": 170}, "170": {"e": 129}, "126": {"n": 98, "s": 129}, "98": {"n": 102, "s": 126, "e": 70, "w": 109}, "102": {"s": 98, "w": 142}, "142": {"e": 102, "w": 159}, "159": {"e": 142, "w": 196}, "196": {"n": 222, "e": 159, "w": 197}, "197": {"n": 232, "e": 196, "w": 276}, "276": {"e": 197, "w": 419}, "419": {"e": 276}, "232": {"n": 272, "s": 197, "w": 235}, "235": {"n": 330, "e": 232, "w": 355}, "355": {"e": 235}, "330": {"n": 369, "s": 235, "w": 383}, "383": {"e": 330, "w": 495}, "495": {"e": 383}, "369": {"n": 400, "s": 330, "w": 376}, "376": {"e": 369}, "400": {"s": 369}, "272": {"n": 295, "s": 232}, "295": {"s": 272}, "222": {"n": 305, "s": 196}, "305": {"n": 365, "s": 222}, "365": {"s": 305}, "109": {"s": 185, "e": 98, "w": 175}, "185": {"n": 109}, "175": {"s": 183, "e": 109, "w": 179}, "179": {"s": 233, "e": 175, "w": 213}, "233": {"n": 179, "w": 238}, "238": {"e": 233}, "213": {"e": 179, "w": 420}, "420": {"s": 444, "e": 213, "w": 437}, "444": {"n": 420, "w": 490}, "490": {"e": 444, "w": 493}, "493": {"e": 490}, "437": {"e": 420, "w": 497}, "497": {"e": 437}, "183": {"n": 175, "s": 229}, "229": {"n": 183, "s": 250, "w": 236}, "250": {"n": 229, "s": 294, "e": 289}, "289": {"w": 250}, "294": {"n": 250, "s": 334}, "334": {"n": 294, "s": 393, "e": 341, "w": 391}, "393": {"n": 334, "s": 482}, "482": {"n": 393}, "391": {"s": 396, "e": 334, "w": 428}, "396": {"n": 391}, "428": {"e": 391}, "341": {"s": 449, "w": 334}, "449": {"n": 341}, "236": {"s": 264, "e": 229}, "264": {"n": 236, "s": 274, "w": 273}, "274": {"n": 264, "w": 308}, "308": {"e": 274}, "273": {"n": 343, "e": 264}, "343": {"s": 273, "w": 351}, "351": {"s": 491, "e": 343, "w": 478}, "491": {"n": 351}, "478": {"e": 351}, "70": {"s": 163, "e": 60, "w": 98}, "163": {"n": 70}, "60": {"n": 45, "e": 36, "w": 70}, "45": {"n": 29, "s": 60}, "29": {"s": 45, "e": 21, "w": 49}, "49": {"s": 79, "e": 29, "w": 136}, "136": {"e": 49, "w": 148}, "148": {"e": 136, "w": 292}, "292": {"n": 301, "e": 148}, "301": {"n": 304, "s": 292}, "304": {"s": 301}, "79": {"n": 49}, "21": {"e": 12, "w": 29}, "12": {"n": 9, "s": 18, "e": 14, "w": 21}, "14": {"s": 34, "e": 37, "w": 12}, "37": {"w": 14}, "18": {"n": 12, "s": 22, "w": 25}, "25": {"e": 18}, "22": {"n": 18, "s": 78, "w": 36}, "36": {"s": 48, "e": 22, "w": 60}, "48": {"n": 36, "s": 105, "w": 149}, "149": {"e": 48}, "105": {"n": 48, "w": 202}, "202": {"e": 105}, "78": {"n": 22, "s": 108}, "150": {"n": 135, "w": 166}, "135": {"s": 150, "e": 106}, "106": {"n": 100, "s": 111, "w": 135}, "111": {"n": 106, "s": 367, "e": 158}, "367": {"n": 111}, "158": {"s": 167, "w": 111}, "167": {"n": 158, "s": 262, "e": 260}, "260": {"w": 167}, "262": {"n": 167, "s": 370, "e": 358}, "370": {"n": 262, "s": 434, "e": 407}, "434": {"n": 370}, "407": {"s": 496, "w": 370}, "496": {"n": 407}, "358": {"e": 401, "w": 262}, "401": {"w": 358}, "140": {"w": 112}, "168": {"n": 156, "e": 340}, "340": {"w": 168}, "298": {"s": 324, "w": 164}, "324": {"n": 298, "s": 349, "e": 354}, "354": {"w": 324}, "349": {"n": 324, "s": 352, "e": 384, "w": 356}, "384": {"w": 349}, "352": {"n": 349, "s": 362, "e": 485}, "362": {"n": 352, "s": 399, "w": 463}, "463": {"s": 468, "e": 362}, "468": {"n": 463}, "399": {"n": 362, "s": 467}, "467": {"n": 399}, "485": {"w": 352}, "356": {"e": 349}, "277": {"n": 261, "e": 323}, "323": {"e": 433, "w": 277}, "433": {"s": 455, "e": 460, "w": 323}, "455": {"n": 433}, "460": {"w": 433}, "435": {"w": 322}, "199": {"s": 230, "w": 198}, "230": {"n": 199, "s": 307, "e": 297}, "307": {"n": 230, "s": 373, "e": 371, "w": 321}, "373": {"n": 307, "s": 480}, "480": {"n": 373}, "371": {"s": 475, "w": 307}, "475": {"n": 371, "s": 484}, "484": {"n": 475}, "321": {"s": 413, "e": 307}, "413": {"n": 321}, "297": {"w": 230}, "9": {"n": 3, "s": 12, "e": 11}, "3": {"s": 9, "e": 5, "w": 2}, "2": {"n": 0, "s": 6, "e": 3}, "6": {"n": 2, "w": 7}, "7": {"n": 8, "e": 6, "w": 56}, "56": {"e": 7, "w": 61}, "61": {"e": 56, "w": 171}, "171": {"e": 61}, "8": {"s": 7, "w": 16}, "16": {"n": 58, "e": 8, "w": 67}, "58": {"s": 16, "w": 65}, "65": {"n": 74, "e": 58, "w": 139}, "139": {"e": 65, "w": 188}, "188": {"e": 139, "w": 335}, "335": {"e": 188, "w": 366}, "366": {"e": 335}, "74": {"n": 87, "s": 65, "w": 161}, "87": {"s": 74}, "161": {"e": 74}, "67": {"e": 16, "w": 162}, "162": {"e": 67}, "0": {"n": 10, "s": 2, "e": 4, "w": 1}, "10": {"n": 19, "s": 0, "w": 43}, "43": {"e": 10, "w": 47}, "47": {"n": 71, "e": 43}, "71": {"s": 47}, "19": {"n": 20, "s": 10, "w": 77}, "77": {"e": 19}, "20": {"n": 63, "s": 19, "e": 27, "w": 46}, "63": {"n": 72, "s": 20, "w": 73}, "72": {"s": 63, "w": 76}, "76": {"n": 83, "e": 72, "w": 110}, "83": {"s": 76, "e": 130, "w": 125}, "125": {"n": 165, "e": 83, "w": 237}, "165": {"n": 203, "s": 125, "w": 204}, "204": {"n": 219, "e": 165, "w": 216}, "216": {"n": 234, "e": 204, "w": 218}, "234": {"n": 368, "s": 216, "w": 252}, "368": {"s": 234}, "252": {"n": 284, "e": 234}, "284": {"n": 302, "s": 252, "w": 303}, "302": {"n": 422, "s": 284}, "422": {"n": 426, "s": 302}, "426": {"n": 457, "s": 422}, "457": {"n": 461, "s": 426}, "461": {"s": 457}, "303": {"n": 361, "e": 284, "w": 405}, "361": {"n": 408, "s": 303}, "408": {"n": 458, "s": 361, "w": 423}, "458": {"s": 408, "w": 459}, "459": {"e": 458}, "423": {"e": 408, "w": 454}, "454": {"n": 470, "e": 423}, "470": {"s": 454}, "405": {"n": 406, "e": 303}, "406": {"s": 405, "w": 415}, "415": {"e": 406, "w": 418}, "418": {"n": 425, "s": 474, "e": 415}, "474": {"n": 418}, "425": {"s": 418, "w": 469}, "469": {"e": 425}, "218": {"s": 263, "e": 216, "w": 242}, "263": {"n": 218}, "242": {"n": 287, "s": 259, "e": 218, "w": 275}, "287": {"s": 242, "w": 339}, "339": {"e": 287, "w": 445}, "445": {"n": 447, "e": 339, "w": 450}, "447": {"s": 445}, "450": {"e": 445}, "259": {"n": 242, "w": 310}, "310": {"e": 259, "w": 412}, "412": {"s": 488, "e": 310}, "488": {"n": 412}, "275": {"e": 242, "w": 456}, "456": {"e": 275, "w": 499}, "499": {"e": 456}, "219": {"s": 204}, "203": {"n": 268, "s": 165, "e": 299}, "299": {"e": 311, "w": 203}, "311": {"w": 299}, "268": {"s": 203, "e": 411, "w": 312}, "411": {"w": 268}, "312": {"n": 328, "e": 268}, "328": {"n": 332, "s": 312, "e": 357, "w": 363}, "332": {"n": 350, "s": 328}, "350": {"n": 436, "s": 332, "e": 404}, "404": {"n": 481, "w": 350}, "481": {"s": 404}, "436": {"s": 350}, "363": {"n": 372, "e": 328}, "372": {"n": 441, "s": 363}, "441": {"s": 372}, "357": {"w": 328}, "237": {"e": 125, "w": 245}, "245": {"s": 254, "e": 237}, "254": {"n": 245, "w": 314}, "314": {"e": 254}, "130": {"w": 83}, "110": {"e": 76}, "73": {"e": 63}, "27": {"n": 40, "s": 28, "e": 30, "w": 20}, "30": {"s": 31, "e": 32, "w": 27}, "31": {"n": 30, "e": 33}, "33": {"e": 38, "w": 31}, "38": {"s": 59, "e": 66, "w": 33}, "59": {"n": 38, "s": 104, "e": 92}, "92": {"w": 59}, "104": {"n": 59, "e": 107}, "107": {"s": 120, "e": 121, "w": 104}, "121": {"n": 128, "e": 143, "w": 107}, "128": {"s": 121, "e": 189}, "189": {"e": 255, "w": 128}, "255": {"w": 189}, "143": {"e": 212, "w": 121}, "212": {"w": 143}, "120": {"n": 107, "e": 127}, "127": {"e": 184, "w": 120}, "184": {"e": 221, "w": 127}, "221": {"s": 253, "e": 240, "w": 184}, "253": {"n": 221, "e": 258}, "258": {"e": 306, "w": 253}, "306": {"e": 397, "w": 258}, "397": {"w": 306}, "240": {"n": 249, "e": 386, "w": 221}, "386": {"e": 414, "w": 240}, "414": {"w": 386}, "249": {"n": 265, "s": 240, "e": 282}, "265": {"n": 279, "s": 249, "e": 270}, "270": {"n": 416, "e": 338, "w": 265}, "416": {"s": 270}, "338": {"s": 379, "w": 270}, "379": {"n": 338, "e": 395}, "395": {"s": 403, "e": 421, "w": 379}, "421": {"n": 440, "w": 395}, "440": {"s": 421, "w": 476}, "476": {"e": 440}, "403": {"n": 395}, "279": {"s": 265}, "282": {"w": 249}, "66": {"n": 169, "e": 123, "w": 38}, "169": {"s": 66, "e": 186}, "186": {"e": 205, "w": 169}, "205": {"s": 241, "e": 479, "w": 186}, "241": {"n": 205, "e": 266}, "266": {"w": 241}, "479": {"w": 205}, "123": {"w": 66}, "32": {"n": 39, "e": 54, "w": 30}, "54": {"w": 32}, "39": {"n": 53, "s": 32, "e": 51, "w": 41}, "53": {"n": 95, "s": 39, "w": 88}, "88": {"e": 53, "w": 122}, "122": {"n": 124, "e": 88}, "124": {"n": 157, "s": 122}, "157": {"n": 210, "s": 124, "w": 182}, "182": {"e": 157, "w": 208}, "208": {"e": 182}, "210": {"s": 157}, "95": {"n": 119, "s": 53, "w": 115}, "115": {"n": 116, "e": 95}, "116": {"n": 132, "s": 115}, "132": {"s": 116}, "119": {"n": 134, "s": 95}, "134": {"n": 147, "s": 119, "e": 144}, "144": {"e": 155, "w": 134}, "155": {"s": 187, "e": 316, "w": 144}, "316": {"n": 344, "w": 155}, "344": {"n": 392, "s": 316, "e": 390}, "390": {"w": 344}, "392": {"s": 344, "e": 462}, "462": {"w": 392}, "187": {"n": 155}, "147": {"n": 200, "s": 134, "e": 153, "w": 151}, "151": {"n": 172, "e": 147, "w": 207}, "207": {"n": 231, "e": 151, "w": 290}, "231": {"s": 207, "w": 248}, "248": {"n": 296, "e": 231, "w": 280}, "296": {"s": 248}, "280": {"n": 325, "e": 248}, "325": {"n": 353, "s": 280, "w": 374}, "353": {"s": 325}, "374": {"e": 325}, "290": {"e": 207}, "172": {"n": 267, "s": 151}, "267": {"n": 285, "s": 172, "w": 271}, "285": {"n": 286, "s": 267}, "286": {"n": 336, "s": 285, "w": 291}, "336": {"s": 286}, "291": {"n": 410, "e": 286, "w": 347}, "347": {"n": 452, "s": 442, "e": 291}, "452": {"s": 347}, "442": {"n": 347}, "410": {"s": 291}, "271": {"n": 337, "e": 267}, "337": {"s": 271}, "200": {"n": 227, "s": 147, "e": 206}, "206": {"n": 288, "e": 380, "w": 200}, "380": {"n": 424, "w": 206}, "424": {"s": 380, "e": 473}, "473": {"e": 494, "w": 424}, "494": {"w": 473}, "288": {"s": 206}, "227": {"n": 269, "s": 200}, "269": {"n": 319, "s": 227}, "319": {"n": 359, "s": 269, "e": 345}, "359": {"s": 319}, "345": {"s": 375, "w": 319}, "375": {"n": 345, "e": 385}, "385": {"w": 375}, "153": {"e": 329, "w": 147}, "329": {"w": 153}, "51": {"n": 69, "e": 57, "w": 39}, "57": {"e": 145, "w": 51}, "145": {"n": 174, "e": 220, "w": 57}, "220": {"w": 145}, "174": {"n": 192, "s": 145, "e": 224}, "224": {"w": 174}, "192": {"n": 201, "s": 174, "e": 223}, "201": {"s": 192}, "223": {"n": 283, "w": 192}, "283": {"n": 331, "s": 223, "e": 313}, "331": {"s": 283, "e": 446}, "446": {"e": 466, "w": 331}, "466": {"s": 486, "e": 472, "w": 446}, "472": {"w": 466}, "486": {"n": 466}, "313": {"w": 283}, "69": {"n": 94, "s": 51, "e": 103}, "103": {"n": 160, "w": 69}, "160": {"s": 103}, "94": {"n": 152, "s": 69}, "152": {"s": 94}, "41": {"e": 39}, "28": {"n": 27}, "40": {"s": 27}, "46": {"e": 20, "w": 62}, "62": {"n": 64, "e": 46, "w": 84}, "84": {"e": 62, "w": 91}, "91": {"n": 180, "s": 101, "e": 84, "w": 99}, "101": {"n": 91, "w": 113}, "113": {"s": 114, "e": 101}, "114": {"n": 113, "w": 176}, "176": {"e": 114, "w": 402}, "402": {"e": 176, "w": 451}, "451": {"e": 402, "w": 453}, "453": {"s": 464, "e": 451}, "464": {"n": 453}, "99": {"n": 190, "e": 91, "w": 146}, "146": {"n": 215, "s": 177, "e": 99, "w": 257}, "215": {"n": 246, "s": 146}, "246": {"s": 215}, "177": {"n": 146, "w": 346}, "346": {"e": 177}, "257": {"n": 320, "e": 146, "w": 364}, "320": {"n": 348, "s": 257}, "348": {"s": 320}, "364": {"n": 429, "s": 381, "e": 257, "w": 448}, "429": {"s": 364}, "448": {"e": 364}, "381": {"n": 364, "w": 394}, "394": {"e": 381}, "190": {"s": 99}, "180": {"s": 91}, "64": {"s": 62, "w": 82}, "82": {"n": 191, "e": 64}, "191": {"s": 82}, "4": {"n": 23, "e": 13, "w": 0}, "13": {"e": 15, "w": 4}, "15": {"w": 13}, "23": {"s": 4, "e": 26}, "26": {"e": 55, "w": 23}, "55": {"w": 26}, "1": {"e": 0}, "5": {"w": 3}, "11": {"e": 17, "w": 9}, "17": {"n": 24, "e": 42, "w": 11}, "24": {"s": 17}, "42": {"n": 44, "s": 80, "e": 118, "w": 17}, "118": {"e": 137, "w": 42}, "137": {"w": 118}, "80": {"n": 42, "s": 81, "e": 86}, "86": {"s": 96, "e": 90, "w": 80}, "90": {"e": 178, "w": 86}, "178": {"n": 209, "e": 243, "w": 90}, "243": {"s": 293, "e": 256, "w": 178}, "293": {"n": 243}, "256": {"s": 360, "e": 327, "w": 243}, "327": {"e": 427, "w": 256}, "427": {"e": 430, "w": 327}, "430": {"n": 443, "e": 439, "w": 427}, "439": {"w": 430}, "443": {"s": 430, "e": 471}, "471": {"w": 443}, "360": {"n": 256, "e": 398}, "398": {"e": 438, "w": 360}, "438": {"e": 465, "w": 398}, "465": {"e": 498, "w": 438}, "498": {"w": 465}, "209": {"s": 178}, "96": {"n": 86, "e": 97}, "97": {"e": 181, "w": 96}, "181": {"w": 97}, "81": {"n": 80}, "44": {"s": 42}} diff --git a/miner.py b/miner.py new file mode 100644 index 00000000..b4aef0a6 --- /dev/null +++ b/miner.py @@ -0,0 +1,47 @@ +import hashlib +import requests + +import sys +from timeit import default_timer as timer +import random + + +def proof_of_work(last_proof, difficulty): + start = timer() + + print("Searching for next proof") + proof = 80000000 + total_tries = 0 + prev_proof = f'{last_proof}'.encode() + last_hash = hashlib.sha256(prev_proof).hexdigest() + #while valid_proof(last_hash, proof, difficulty) is False: + while valid_proof(last_proof, proof, difficulty) is False and total_tries < 6000000: + #proof = random.randint(0, 10000) + #proof+=1 + proof = random.randint(0, 100000000) + total_tries += 1 + if total_tries % 1000000 == 0: + print(total_tries/1000000,'million tries') + + + if total_tries < 6000000: + print("Proof found: " + str(proof) + " in " + str(timer() - start)) + return proof + else: + print('re-run') + return 'rerun' + + +def valid_proof(last_hash, proof, difficulty): + guess = f'{proof}' + guess = (str(last_hash)+str(guess)).encode() #there was no ref to last hash in valid proof + guess_hash = hashlib.sha256(guess).hexdigest() + #guess_hash = hash(guess)#.hexdigest() + + if difficulty is not None: + leading_zeros = "0" * difficulty + else: + leading_zeros = "0" * 6 + + #return guess_hash[0:difficulty] == leading_zeros + return str(guess_hash)[0:difficulty] == leading_zeros \ No newline at end of file diff --git a/rooms.txt b/rooms.txt new file mode 100644 index 00000000..ed58f247 --- /dev/null +++ b/rooms.txt @@ -0,0 +1,11 @@ +{"A misty room": 44, +"Mt. Holloway": 11, +"The Transmogriphier": 495, +"The Peak of Mt. Holloway": 22, +"Pirate Ry's": 467, +"A brightly lit room": 0, +"A Dark Cave": 488, +"Linh's Shrine": 461, +"Glasowyn's Grave": 499, +"Wishing Well": 55, +"Shop": 1} \ No newline at end of file diff --git a/test_graph.py b/test_graph.py new file mode 100644 index 00000000..f5468d80 --- /dev/null +++ b/test_graph.py @@ -0,0 +1,4 @@ +from basic_utils import Graph +graph = Graph() +graph.vertices = {'1':{'n':'2','e':'3','w':'4','s':'5'},'2':{'s':'1'},'3':{'w':'1'},'4':{'e':'1'},'5':{'n':'1'}} +print(graph.bfs('5','3')) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 00000000..a82ebbf3 --- /dev/null +++ b/utils.py @@ -0,0 +1,549 @@ +from decouple import config +from basic_utils import * +from miner import * +import requests +import json +import time +import random +import os +from cpu2 import * +import datetime + +auth_key = config('AUTH_KEY') # MAKE SURE YPU HAVE .ENV SET UP +my_url = config('LAMBDA_URL') # AND PYTHON DECOUPLE INSTALLED +my_name = config('NAME') # when to change name + + +def keystoint(x): + "function to change json dictionary keys to ints - used for map load" + return {int(k): v for k, v in x.items()} + + +class Player: + def __init__(self, name, startingRoom): + self.name = name + self.currentRoom = startingRoom + self.player_cooldown = 1, + self.player_encumbrance = 0, + self.player_strength = 0, + self.player_speed = 0, + self.player_gold = 0, + self.player_inventory = [], + self.player_status = [], + self.player_errors = [], + self.player_messages = [] + self.player_mine = '' + + +class mapper: + def __init__(self, auth=auth_key, save=True, load_map=True): + self.auth = auth # the auth token + # the header for post and get + self.header = {'Authorization': f'Token {self.auth}'} + self.wait = 18 # the current sleep length - this is no longer required as wait always points to cooldown + self.info = {} # the last status json from post or get + # whether player picks up items or not - it is very easy to get overencumbered + self.accumulate = False + self.pray = False # can't pray without a name unfortunately + self.save_map_to_text = save # save latest map to a text file + # import map so far - setting to false starts from scratch + self.import_text_map = load_map + self.player = None + self.fly = False + self.dash = False + self.important_rooms = {} # May not need this anymore (all special rooms are id'd) + self.hour = datetime.datetime.today().hour + self.auto_stop = 19 + + def get_info(self, what='init', direction=None, backtrack=None): + """multi purpose move & init function - this is used + for the most common actions""" + + if what == 'init': + response = requests.get(f'{my_url}{what}/', headers=self.header) + + elif what == 'move': + if self.fly and self.info['elevation']>0: + response = requests.post( + f'{my_url}fly/', headers=self.header, json={"direction": direction}) + else: + response = requests.post( + f'{my_url}move/', headers=self.header, json={"direction": direction}) + + elif what == 'fly': + response = requests.post( + f'{my_url}fly/', headers=self.header, json={"direction": direction}) + + elif what == 'backtrack': + response = requests.post(f'{my_url}move/', headers=self.header, + json={"direction": direction, "next_room_id": backtrack}) + + if response.status_code == 200: + self.info = json.loads(response.content) + if self.player is not None: + self.player.currentRoom = self.info['room_id'] + + if 'cooldown' in self.info.keys(): # there are a lot of TRAPS which require extra cooldown + time.sleep(self.info['cooldown']) + + self.room_check() + return self.info + else: + print('cooldown triggered - waiting 20 seconds') + time.sleep(20) + self.get_info(what=what, direction=direction, backtrack=backtrack) + + def action(self, what='take', treasure=None, name=None): + """another multi purpose request function + this one focuses on less common actions""" + + if what in ['take', 'drop', 'sell', 'examine']: + response = requests.post( + f'{my_url}{what}/', headers=self.header, json={"name": treasure}) + print(f"Action: {what}") + + if what in ['status', 'pray']: + response = requests.post(f'{my_url}{what}/', headers=self.header) + + if what == 'confirm_sell': + response = requests.post( + f'{my_url}{what}/', headers=self.header, json={"name": treasure, "confirm": "yes"}) + + if what == 'change_name': + response = requests.post( + f'{my_url}{what}/', headers=self.header, json={"name": name, "confirm": "aye"}) + + if what == 'balance': + response = requests.get( + 'https://lambda-treasure-hunt.herokuapp.com/api/bc/get_balance/', headers=self.header) + + if response.status_code == 200: + self.info = json.loads(response.content) + if 'cooldown' in self.info.keys(): + time.sleep(self.info['cooldown']) + return self.info + else: + print('error', what, treasure, response.status_code) + + def room_check(self): + """checks for items in teh room or special rooms""" + # print('room check triggered. info: ',self.info) + if self.info['items'] != [] and self.accumulate: + for item in self.info['items']: + # Examines the item + self.info = self.action('examine', item) + print(self.info) + self.info = self.action('take', item) + print(self.info) + + if self.info['title'] == "Linh's Shrine" and self.pray: # there may be other shrines + self.info = self.action('pray') + + if self.info['title'] == "shop": + self.info = self.action('sell', item) + self.info = self.action('confirm_sell') + + def create_starting_map(self): + """"initiates your starting map which is stored under the vertices of a graph class""" + info_dict = self.get_info() + # print(info_dict) # this can be deactivated - just helpful at first + self.my_map = Graph() + self.player = Player("MicahJones", info_dict['room_id']) + exits = info_dict['exits'] + exit_dict = {} + for e in exits: + exit_dict[e] = '?' + if self.import_text_map: + print("load map triggered") + with open('map.txt', 'r') as file: + string_dict = json.loads(file.read()) + for key in string_dict: + self.my_map.vertices[int(key)] = string_dict[key] + # May not need this anymore since all important rooms are id'd + with open('rooms.txt', 'r') as file: + string_dict = json.loads(file.read()) + for key in string_dict: + self.important_rooms[key] = string_dict[key] + else: + print("fresh map triggered") + self.my_map.vertices[self.player.currentRoom] = exit_dict + + return self.my_map, self.player + + def pop_map_on_move(self, move): + """fills in the map while moving in the direction specified""" + reverse_dir = {'n': 's', 's': 'n', 'w': 'e', 'e': 'w'} + old_room = self.player.currentRoom + info = self.get_info('move', move) + self.player.currentRoom = info['room_id'] + print(info) # leave this line in to get movement updates + new_room = info['room_id'] + if new_room not in self.my_map.vertices: + exit_dict = {} + for exits in info['exits']: + for e in exits: + exit_dict[e] = '?' + self.my_map.vertices[new_room] = exit_dict + self.my_map.vertices[old_room][move] = new_room + reverse_move = reverse_dir[move] + self.my_map.vertices[new_room][reverse_move] = old_room + if self.save_map_to_text: + with open('map.txt', 'w') as file: + file.write(json.dumps(self.my_map.vertices)) + # May not need this anymore since all important rooms are id'd + self.important_rooms.update({info['title']: info['room_id']}) + if self.save_map_to_text: + with open('rooms.txt', 'w') as file: + file.write(json.dumps(self.important_rooms)) + + def count_unmapped(self): + """counts all the unmapped rooms""" + counter = 0 + for val1 in self.my_map.vertices.values(): + for val2 in val1.values(): + if val2 == '?': + counter += 1 + return counter + + def get_dirs(self, traversal): + """gets the direction of travel given a room traversal list""" + point = traversal[0] + dir_list = [] + for t in traversal[1:]: + for key in self.my_map.vertices[point]: + if self.my_map.vertices[point][key] == t: + dir_list.append(key) + point = t + return dir_list + + def bfs_for_q(self): + """breadth first search for last ?""" + room = self.player.currentRoom + q = Queue() + q.enqueue([room]) + + while '?' not in self.my_map.vertices[room].values(): + joins = self.my_map.vertices[room] + for j in joins.values(): + if j in q.queue[0]: + pass + else: + _ = [x for x in q.queue[0]] + _.append(j) + q.enqueue(_) + q.dequeue() + room = q.queue[0][-1] + + return q.queue[0] + + def explore_random(self, counter=5): + """explores the map choosing random ? and backtracks using bfs + counter is the number of times you want it to explore unknown rooms""" + unmapped_number = self.count_unmapped() + moves = [] + c = 0 + while unmapped_number > 0 and c <= counter: + print(self.my_map.vertices) + + room = self.player.currentRoom + unvisited_exits = [x for x in self.my_map.vertices[room] + if self.my_map.vertices[room][x] == '?'] + if unvisited_exits != []: + print('exit checker', unvisited_exits) + move = random.choice(unvisited_exits) + moves.append(move) + self.pop_map_on_move(move) + unmapped_number = self.count_unmapped() + time.sleep(self.wait) + else: + # leave this line in to show you when you are backtracking + print('back track on') + backtrack = self.bfs_for_q() + backtrack_dirs = self.get_dirs(backtrack) + # this line shows details of backtrack + print('backtrack details', backtrack, backtrack_dirs) + for i in range(len(backtrack_dirs)): + b_info = self.get_info( + 'backtrack', backtrack_dirs[i], str(backtrack[i+1])) + self.player.currentRoom = b_info['room_id'] + c += 1 + + def go_to_room(self, destination): + """Breadth First Traversal to particular room in shortest route""" + print('moving') + path = self.my_map.bfs(self.player.currentRoom, destination) + for m in path: + room = self.player.currentRoom + exits = self.my_map.vertices[room] + for direction in exits: + if self.my_map.vertices[room][direction] == m: + self.get_info(what='move', direction=direction) + print( + f"Current Room -> Title: {self.info['title']} ID: {self.info['room_id']} Items: {self.info['items']}") + else: + continue + + def dash_to_room(self, destination): + "same as go to room but with dash" + #print('dashing') + path = self.my_map.bfs(self.player.currentRoom, destination) + #print('bfs',path) + my_dirs = self.get_dirs(path) + i = 0 + while i < len(path)-1: + if i < len(path)-2 and my_dirs[i]==my_dirs[i+1]: + print('dashing') + dash_path = self.get_dash_path(path[i:],my_dirs[i:]) + self.make_dash(my_dirs[i],dash_path[1:]) + print(f"Current Room -> Title: {self.info['title']} ID: {self.info['room_id']} Items: {self.info['items']}") + i += len(dash_path[1:]) + else: + print('normal walking') + room = self.player.currentRoom + exits = self.my_map.vertices[room] + for direction in exits: + if self.my_map.vertices[room][direction] == path[i+1]: + #print('walk triggered',path[i+1],direction) + self.get_info(what='backtrack', direction=direction,backtrack=str(path[i+1])) + print( + f"Current Room -> Title: {self.info['title']} ID: {self.info['room_id']} Items: {self.info['items']}") + + else: + continue + i+=1 + + + def get_dash_path(self,traversal,dirs): + "check if the path in go to room contains a dashable stretch" + print('dash path check',traversal,dirs) + dash_list = [] + j = 0 + while (j= 1000: + # Go to name changer (pirate ry) + print('Time to Buy a Name') + # * Made this false here so that we don't somehow pick up a ton of treasure on the way, and + # * get over-encumbered. + self.accumulate = False + self.pirate() # pirate ry's room + time.sleep(self.wait) + # Buy name + #! -------------------------- Change the name here to be what you want!! + self.action('change_name', name='SirSnuffaluffagus') + time.sleep(self.wait) + + #! This print isn't accurate. It doesn't update when you actually change your name. + #! Next time you see it, it should have changed though. + print(f"Got a name! Time to get a COIN. New Name: {ret_data['name']}") + time.sleep(self.wait) + # self.action('status') #Check new name + elif ret_data['encumbrance'] <= ret_data['strength'] - 2: + # If encumbered is str-2 (at base = 8) + # Travel the room bfs style at random + # Loot as you go with room_check + print('Looting..') + # * accumlate is true here since that's the whole point of this block + self.accumulate = True + + # self.explore_random(500) + self.go_to_room(random.randint(0, 499)) + print('Current Inventory: ', ret_data['inventory']) + time.sleep(self.wait) + # Could potentially add a section to manage miner + else: + # else go directly to the shop + # loop through inventory and sell + # Go back to looting + print('Need to offload my loot.') + # * Setting accumulate to false so we don't get overburdening on the way to shop. + self.accumulate = False + self.vendor() + print('At the shop, time to sell.') + for item in ret_data['inventory']: + print(f"Selling {item}...") + self.action('sell', item) + time.sleep(self.wait) + self.action('confirm_sell', item) + time.sleep(self.wait) + # This doesn't actually update after each sell for some reason. + print(f"You're current gold: {ret_data['gold']}") + print('Back to Looting') + + def get_coins(self): + # Want this to do 3 things: + # Function to go to the wishing well and examine + # Function to go to where the wishing well says + # Function to mine coin at specified location + # Could include if clause to go transmog coins + + coins = 0 + # variable for proof? + while coins < 1000: + # Go to wishing well + print('Going to the Wishing Well.') + self.wishing_well() + # Examine well + self.action('examine') + # Go to where it says + self.go_to_room('hinted location/room') + # Mine Coin + print('Getting proof...') + response = request.post(f'https://lambda-treasure-hunt.herokuapp.com/api/bc/last_proof/', headers=self.headers) + new_proof = proof_of_work(data.get('proof'), data.get('difficulty')) + time.sleep(self.wait) + # Need to send new_proof in the mine request json + response = request.post(f'https://lambda-treasure-hunt.herokuapp.com/api/bc/mine/', headers=self.headers, json={"proof":''}) + print('You got a coin!') + coins += 1 + time.sleep(self.wait) + + def hint_to_ld8(self): + "converts hint in well to room number" + self.action('examine','well') + z = self.info['description'] #read the last info to get the hint + z = z.split('\n')[2:] + print(z) + with open('hinter.ls8','w') as f: + for zz in z: + f.write("%s\n" % zz) + #quicker way to parse message + #z = [int(zz,2) for zz in z] + + + def get_proof(self): + """gets last proof then obtains proof of work + then posts new proof to server""" + print('Getting proof...') + response = requests.get(f'https://lambda-treasure-hunt.herokuapp.com/api/bc/last_proof/', headers=self.header) + self.last_proof = json.loads(response.content) + print(self.last_proof) + time.sleep(self.last_proof['cooldown']) + my_proof = proof_of_work(self.last_proof['proof'],self.last_proof['difficulty']) + if my_proof != 'rerun': + self.get_mine(my_proof) + time.sleep(self.mine_response['cooldown']) + else: + self.get_proof() + + def get_mine(self,new_proof): + """posts your new proof to the server - note high cooldown penalties for posting wrong proof""" + params = {"proof" : new_proof} + response = requests.post(f'https://lambda-treasure-hunt.herokuapp.com/api/bc/mine/', headers=self.header,json = params) + self.mine_response = json.loads(response.content) + if 'errors' in self.mine_response.keys() and self.mine_response['errors']!=[]: + time.sleep(self.mine_response['cooldown']) + self.get_proof() + print(self.mine_response) + + def sell_all_items(self): + """sells all items if you are in the shop""" + self.action('status') + inv = self.info['inventory'] + for i in inv: + self.action('sell',i) + self.action('confirm_sell',i) + + def auto_coins(self,acc=True,fly=True): + "now added timer stop" + self.fly = fly + self.accumulate = acc + while True and self.hour16: + self.dash_to_room(1) + self.sell_all_items() + self.action('status') + print(self.info) + + self.dash_to_room(55) + self.hint_to_ld8() + cpu = CPU() + cpu.load('hinter.ls8') + room_inst = cpu.run() + room_inst = ''.join(room_inst) + print(room_inst) + try: + mine_room = int(room_inst[-3:]) + except: + try: + mine_room = int(room_inst[-2:]) + except: + mine_room = int(room_inst[-1:]) + print(mine_room) + self.dash_to_room(mine_room) + self.get_proof() + self.action('balance') #new lines + print(self.info) #new lines + + + +