rozpoznany sauron = zmiana na inny cel
This commit is contained in:
parent
7cb2903a1d
commit
b01f3e48f9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
__pycache__/nn.cpython-310.pyc
Normal file
BIN
__pycache__/nn.cpython-310.pyc
Normal file
Binary file not shown.
6
bfs.py
6
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
|
||||
|
30
main.py
30
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)
|
||||
@ -213,6 +239,8 @@ print("path_true:",path_true)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
g = Game()
|
||||
g.new()
|
||||
while g.running:
|
||||
|
6
nn.py
6
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
|
||||
|
Loading…
Reference in New Issue
Block a user