diff --git a/__pycache__/agent.cpython-310.pyc b/__pycache__/agent.cpython-310.pyc index b035cde..cb98914 100644 Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ diff --git a/__pycache__/bfs.cpython-310.pyc b/__pycache__/bfs.cpython-310.pyc index 26538be..9e89e08 100644 Binary files a/__pycache__/bfs.cpython-310.pyc and b/__pycache__/bfs.cpython-310.pyc differ diff --git a/__pycache__/map_add_ons.cpython-310.pyc b/__pycache__/map_add_ons.cpython-310.pyc index de40399..5e59ca2 100644 Binary files a/__pycache__/map_add_ons.cpython-310.pyc and b/__pycache__/map_add_ons.cpython-310.pyc differ diff --git a/__pycache__/mobs.cpython-310.pyc b/__pycache__/mobs.cpython-310.pyc index b55c48a..efa8782 100644 Binary files a/__pycache__/mobs.cpython-310.pyc and b/__pycache__/mobs.cpython-310.pyc differ diff --git a/__pycache__/nn.cpython-310.pyc b/__pycache__/nn.cpython-310.pyc new file mode 100644 index 0000000..ef14e7c Binary files /dev/null and b/__pycache__/nn.cpython-310.pyc differ diff --git a/bfs.py b/bfs.py index 4f1f69b..158f67d 100644 --- a/bfs.py +++ b/bfs.py @@ -1,6 +1,6 @@ import pygame from config import * -class Bfs: +class Bfs(): def __init__(self,game): @@ -12,12 +12,12 @@ class Bfs: self.enemy_cells = [] def heuristic(a,b): return abs(a[0]-b[0])+abs(a[1]-b[1]) - def bfs(self): + def bfs(self,goal_cell): print("x: ", self.game.agent.x, "y: ", self.game.agent.y) cost_road=0 self.open_queue.append(self.get_cell_number(self.game.agent.x,self.game.agent.y)) # tutaj dodaje się cel agenta - goal_cell = self.get_cell_number(self.game.flower.x,self.game.flower.y) + #goal_cell = self.get_cell_number(self.game.flower.x,self.game.flower.y) path = [] processing = True diff --git a/main.py b/main.py index 152e86d..cebd520 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,7 @@ class Game: pygame.display.set_caption('Gra-SI') self.bfs = Bfs(self) + self.nn = NeuralN() def new(self): # tworzy się nowa sesja grania self.all_sprites = pygame.sprite.LayeredUpdates() @@ -87,7 +88,32 @@ class Game: if event.type == pygame.MOUSEBUTTONDOWN: mouse_presses = pygame.mouse.get_pressed() if mouse_presses[0]: - self.bfs.bfs() + #self.bfs.bfs(self.bfs.get_cell_number(self.flower.x,self.flower.y)) + x = self.sauron.x + y = self.sauron.y + mob_image = self.sauron.SAURON_IMG + while True: + prediction = self.prediction_road(x,y,mob_image) + if prediction == "SAURON": + x = self.infantry_ork.x + y = self.infantry_ork.y + mob_image = self.infantry_ork.INFANTRY_ORK_IMG + prediction = self.prediction_road(x,y,mob_image) + else: + self.bfs.bfs(self.bfs.get_cell_number(x,y)) + + + def prediction_road(self,x,y,mob_image): + mob_goal = (self.bfs.get_cell_number(x,y)) + if self.bfs.get_up_cell(mob_goal) == None: + goal = self.bfs.get_down_cell(mob_goal) + else: + goal = self.bfs.get_up_cell(mob_goal) + self.bfs.bfs(goal) + prediction = self.nn.predict(mob_image) + return prediction + + def map(self): # tworzenie mapy self.clock.tick(FRAMERATE) @@ -212,6 +238,8 @@ print("path_true:",path_true) #bfss.move_agent(path_true) + + g = Game() g.new() diff --git a/nn.py b/nn.py index e9f7d7f..7edd8a1 100644 --- a/nn.py +++ b/nn.py @@ -12,7 +12,7 @@ import pathlib class NeuralN: # @staticmethod - # def predict(image): + def predict(self,image): data_dir = pathlib.Path('zdjecia') saved_model_path = pathlib.Path('trained_model.h5') class_names_path = pathlib.Path("class_names.pkl") @@ -93,7 +93,7 @@ class NeuralN: tf.keras.layers.Softmax()]) #image_path = image - image_path = pathlib.Path('path_to_image') + image_path = pathlib.Path('zdjecia\ORK_ARCHER\ork_archer (942).jpg') image = Image.open(image_path) # Preprocess the image @@ -119,4 +119,4 @@ class NeuralN: # Print the predicted label print(predicted_label) - # return predicted_label, action + return predicted_label#, action