naprawiony bfs 4
This commit is contained in:
parent
139068130b
commit
077d2b8015
@ -1,3 +1,4 @@
|
|||||||
|
from math import dist, sqrt
|
||||||
import pygame
|
import pygame
|
||||||
from classes import minesweeper, system, bfs
|
from classes import minesweeper, system, bfs
|
||||||
from random import randrange
|
from random import randrange
|
||||||
@ -21,11 +22,7 @@ class AI:
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
self.saper.set_map(self.current_map)
|
self.saper.set_map(self.current_map)
|
||||||
|
|
||||||
goal_state = [self.current_map.mines[0].position_x, self.current_map.mines[0].position_y]
|
self.bfs()
|
||||||
print(goal_state)
|
|
||||||
|
|
||||||
find_path = bfs.BFS(self.saper)
|
|
||||||
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
|
|
||||||
|
|
||||||
#co ma robić przy każdym FPS'ie
|
#co ma robić przy każdym FPS'ie
|
||||||
def updateFPS(self):
|
def updateFPS(self):
|
||||||
@ -81,8 +78,16 @@ class AI:
|
|||||||
self.saper.rotate(way)
|
self.saper.rotate(way)
|
||||||
self.saper.move()
|
self.saper.move()
|
||||||
elif len(self.current_map.mines)!=0:
|
elif len(self.current_map.mines)!=0:
|
||||||
goal_state = [self.current_map.mines[0].position_x, self.current_map.mines[0].position_y]
|
self.bfs()
|
||||||
print(goal_state)
|
|
||||||
|
|
||||||
find_path = bfs.BFS(self.saper)
|
|
||||||
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
|
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)
|
Loading…
Reference in New Issue
Block a user