nieskończony feature
This commit is contained in:
parent
1c7b3f2840
commit
039f36fda3
@ -94,5 +94,5 @@ class AI:
|
|||||||
goal_state = [self.current_map.mines[ind].position_x, self.current_map.mines[ind].position_y]
|
goal_state = [self.current_map.mines[ind].position_x, self.current_map.mines[ind].position_y]
|
||||||
print(goal_state)
|
print(goal_state)
|
||||||
|
|
||||||
find_path = bfs.BFS(self.saper)
|
find_path = bfs.BFS(self.saper, self.window)
|
||||||
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
|
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
|
@ -1,15 +1,16 @@
|
|||||||
import heapq # dla utrzymania fringe
|
import heapq # dla utrzymania fringe
|
||||||
from classes import node, minesweeper
|
from classes import node, minesweeper, system
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class BFS:
|
class BFS:
|
||||||
|
window: system.Window
|
||||||
agent: minesweeper.Minesweeper
|
agent: minesweeper.Minesweeper
|
||||||
node: node.Node
|
node: node.Node
|
||||||
|
|
||||||
def __init__(self, agent):
|
def __init__(self, agent, window):
|
||||||
self.agent = agent
|
self.agent = agent
|
||||||
|
self.window = window
|
||||||
|
|
||||||
def successor(self, current_position):
|
def successor(self, current_position):
|
||||||
new_nodes = []
|
new_nodes = []
|
||||||
@ -39,6 +40,7 @@ class BFS:
|
|||||||
# goaltest = test spewnienia celu
|
# goaltest = test spewnienia celu
|
||||||
|
|
||||||
def graphsearch(self, fringe, explored, succ, goaltest):
|
def graphsearch(self, fringe, explored, succ, goaltest):
|
||||||
|
self.window.pause(True)
|
||||||
|
|
||||||
positiont_at_beginning = [self.agent.position_x, self.agent.position_y, self.agent.rotation_degrees] # x, y, gdzie_patczy
|
positiont_at_beginning = [self.agent.position_x, self.agent.position_y, self.agent.rotation_degrees] # x, y, gdzie_patczy
|
||||||
final_action_list = []
|
final_action_list = []
|
||||||
@ -78,6 +80,7 @@ class BFS:
|
|||||||
tmp_node = tmp_node[1].get_parent()
|
tmp_node = tmp_node[1].get_parent()
|
||||||
final_action_list.reverse()
|
final_action_list.reverse()
|
||||||
print(final_action_list)
|
print(final_action_list)
|
||||||
|
self.window.pause(False)
|
||||||
return final_action_list
|
return final_action_list
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +95,8 @@ class BFS:
|
|||||||
#print([node_[0], node_[1]])
|
#print([node_[0], node_[1]])
|
||||||
x = node.Node(tmp_node, None, [node_[0], node_[1]]) # action
|
x = node.Node(tmp_node, None, [node_[0], node_[1]]) # action
|
||||||
heapq.heappush(fringe, (counter, x))
|
heapq.heappush(fringe, (counter, x))
|
||||||
# time.sleep(0.5)
|
self.window.draw_search([self.agent.position_x, self.agent.position_y], [node_[0], node_[1]])
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ class Window:
|
|||||||
title:str
|
title:str
|
||||||
icon_path:str
|
icon_path:str
|
||||||
paused:bool
|
paused:bool
|
||||||
|
pause_menu:None
|
||||||
|
|
||||||
|
search: pygame.Surface
|
||||||
|
|
||||||
def __init__(self, width:int=640, height:int=480, title="", icon_path=""):
|
def __init__(self, width:int=640, height:int=480, title="", icon_path=""):
|
||||||
self.set_resolution(width,height)
|
self.set_resolution(width,height)
|
||||||
@ -14,6 +17,11 @@ class Window:
|
|||||||
self.set_icon(icon_path)
|
self.set_icon(icon_path)
|
||||||
self.mount()
|
self.mount()
|
||||||
self.paused=False
|
self.paused=False
|
||||||
|
|
||||||
|
self.pause_menu = pygame.Surface((width, height))
|
||||||
|
self.pause_menu.set_alpha(128)
|
||||||
|
self.pause_menu.fill((0,0,0))
|
||||||
|
self.search = pygame.Surface((width, height), flags=pygame.SRCALPHA)
|
||||||
|
|
||||||
def set_resolution(self, width:int, height:int):
|
def set_resolution(self, width:int, height:int):
|
||||||
self.width = width
|
self.width = width
|
||||||
@ -30,4 +38,18 @@ class Window:
|
|||||||
pygame.display.set_caption(self.title)
|
pygame.display.set_caption(self.title)
|
||||||
if self.icon_path != "":
|
if self.icon_path != "":
|
||||||
icon = pygame.image.load(self.icon_path)
|
icon = pygame.image.load(self.icon_path)
|
||||||
pygame.display.set_icon(icon)
|
pygame.display.set_icon(icon)
|
||||||
|
|
||||||
|
def pause(self, paused:bool):
|
||||||
|
self.paused=paused
|
||||||
|
if self.paused:
|
||||||
|
self.window.blit(self.pause_menu,(0,0))
|
||||||
|
pygame.display.update()
|
||||||
|
self.search.fill(pygame.Color(0,0,0,0))
|
||||||
|
|
||||||
|
def draw_search(self, pos1:list=[0,0], pos2:list=[0,0], tile_size:int=64):
|
||||||
|
self.search.fill(pygame.Color(0,0,0,0))
|
||||||
|
pos1 = [pos1[0]*tile_size, pos1[1]*tile_size]
|
||||||
|
pos2 = [pos2[0]*tile_size, pos2[1]*tile_size]
|
||||||
|
pygame.draw.line(self.search, pygame.Color(255,0,0), pos1, pos2, 1)
|
||||||
|
pygame.display.update()
|
13
main.py
13
main.py
@ -24,10 +24,6 @@ def main():
|
|||||||
#utworzenie okna do gry
|
#utworzenie okna do gry
|
||||||
window = system.Window(TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y, "Intelligent Minesweeper", "icon.png")
|
window = system.Window(TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y, "Intelligent Minesweeper", "icon.png")
|
||||||
|
|
||||||
#utworzenie ekranu pauzy
|
|
||||||
pause_menu = pygame.Surface((TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y))
|
|
||||||
pause_menu.set_alpha(128)
|
|
||||||
pause_menu.fill((0,0,0))
|
|
||||||
|
|
||||||
#utworzenie objektu mapy, wygenerowanie jej i narysowanie na ekranie
|
#utworzenie objektu mapy, wygenerowanie jej i narysowanie na ekranie
|
||||||
map = minesweeper.Map(window, TILE_SIZE, TILES_X, TILES_Y)
|
map = minesweeper.Map(window, TILE_SIZE, TILES_X, TILES_Y)
|
||||||
@ -37,6 +33,11 @@ def main():
|
|||||||
#utworzenie sapera
|
#utworzenie sapera
|
||||||
saper = minesweeper.Minesweeper(0,0, TILE_SIZE)
|
saper = minesweeper.Minesweeper(0,0, TILE_SIZE)
|
||||||
|
|
||||||
|
#pierwszy render
|
||||||
|
map.draw_tiles()
|
||||||
|
map.draw_objects()
|
||||||
|
saper.draw(window.window, 0.1)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
#utworzenie objektu klasy AI
|
#utworzenie objektu klasy AI
|
||||||
AI = ai.AI(window, map, saper)
|
AI = ai.AI(window, map, saper)
|
||||||
@ -60,10 +61,6 @@ def main():
|
|||||||
map.draw_tiles()
|
map.draw_tiles()
|
||||||
map.draw_objects()
|
map.draw_objects()
|
||||||
saper.draw(window.window, delta)
|
saper.draw(window.window, delta)
|
||||||
|
|
||||||
#pauza
|
|
||||||
if window.paused:
|
|
||||||
window.window.blit(pause_menu, (0,0))
|
|
||||||
|
|
||||||
#odświeżenie ekranu
|
#odświeżenie ekranu
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user