From 7271a80bd0435cab0a1aa790c7ce170c5d63726b Mon Sep 17 00:00:00 2001 From: emil Date: Tue, 29 Oct 2024 03:57:47 +0300 Subject: [PATCH] Decide to write from scratch again, but much more simplistic --- main.py | 5 ++++- main2.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 main2.py diff --git a/main.py b/main.py index 339802e..be45ce3 100644 --- a/main.py +++ b/main.py @@ -234,12 +234,14 @@ def read_input(): return inpt def move(x, y): - neo.update_open_set() + for i in neo.open_set: + print(i.position) if map.get_cell(x, y) in neo.open_set: #TODO: FIX CHECK neo.set_position(x, y) print(f"m {x} {y}") else: print("ERROR: CAN'T MOVE HERE") + neo.update_open_set() map = Map((8, 8)) @@ -254,6 +256,7 @@ pg.display.set_caption("Matrix Universe") running = True #pg.time.delay(7000) neo.set_position(0, 0) #TODO: ITS TEMPORARY +neo.update_open_set() move(0, 0) read_initial_inputs() pg.time.delay(1500) diff --git a/main2.py b/main2.py new file mode 100644 index 0000000..a6b3765 --- /dev/null +++ b/main2.py @@ -0,0 +1,58 @@ + + +def get_position_input(): + position_input_list = (input().split(" ")) + position_input_tuple = () + for i in position_input_list: + position_input_tuple += (i,) + return position_input_tuple + +def get_walkable_cells(): + walkable_cells = [] + potential_positions = [] + potential_positions.append((neo[0], neo[1] + 1)) + potential_positions.append((neo[0], neo[1] - 1)) + potential_positions.append((neo[0] - 1, neo[1])) + potential_positions.append((neo[0] + 1, neo[1])) + for i in potential_positions: + if i[0] in range(MAP_SIZE) and i[1] in range(MAP_SIZE): + walkable_cells.append(i) + return walkable_cells + +def get_g(cell:tuple): + return abs((neo[0] - cell[0]) + (neo[1] - cell[1])) + +def get_h(cell:tuple): + return abs((keymaster[0] - cell[0]) + (keymaster[1] - cell[1])) + +def get_f(cell:tuple): + return get_g(cell) + get_h(cell) + +def set_position(new_postion:tuple): + neo = new_postion + + + + + +MAP_SIZE = 8 +map = [] +start = (0, 0) #initial position of Neo +neo = start #position of Neo +keymaster = () #position of Keymaster + +perception_radius = input() +position_input = get_position_input() + +keymaster = (position_input[0], position_input[1]) + + + +print(neo) +print(get_walkable_cells()) + +while (True): + position_input = get_position_input() + set_position(position_input) + print(neo) + print(get_walkable_cells()) \ No newline at end of file