naprawiony bfs 4

This commit is contained in:
s464859 2022-04-07 17:13:50 +02:00
parent 139068130b
commit 077d2b8015

View File

@ -1,3 +1,4 @@
from math import dist, sqrt
import pygame
from classes import minesweeper, system, bfs
from random import randrange
@ -21,11 +22,7 @@ class AI:
def ready(self):
self.saper.set_map(self.current_map)
goal_state = [self.current_map.mines[0].position_x, self.current_map.mines[0].position_y]
print(goal_state)
find_path = bfs.BFS(self.saper)
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
self.bfs()
#co ma robić przy każdym FPS'ie
def updateFPS(self):
@ -81,8 +78,16 @@ class AI:
self.saper.rotate(way)
self.saper.move()
elif len(self.current_map.mines)!=0:
goal_state = [self.current_map.mines[0].position_x, self.current_map.mines[0].position_y]
print(goal_state)
self.bfs()
def bfs(self):
dists = []
for mine in self.current_map.mines:
dists.append(sqrt((self.saper.position_x-mine.position_x)**2 + (self.saper.position_y-mine.position_y)**2))
ind = dists.index(min(dists))
goal_state = [self.current_map.mines[ind].position_x, self.current_map.mines[ind].position_y]
print(goal_state)
find_path = bfs.BFS(self.saper)
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
find_path = bfs.BFS(self.saper)
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)