74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
import pygame
|
|
from classes import minesweeper, system, bfs
|
|
from random import randrange
|
|
|
|
class AI:
|
|
window:system.Window
|
|
current_map:minesweeper.Map
|
|
saper:minesweeper.Minesweeper
|
|
|
|
#jak True to można się poruszać strzałkami, jak False sam się porusza
|
|
user_controlled=False
|
|
|
|
def __init__(self, window, current_map, saper):
|
|
self.window = window
|
|
self.current_map = current_map
|
|
self.saper = saper
|
|
|
|
#co ma zrobić tylko na początku
|
|
def ready(self):
|
|
self.saper.set_map(self.current_map)
|
|
|
|
goal_state = [minesweeper.Map.mines[0].position_x, minesweeper.Map.mines[0].position_y]
|
|
print(goal_state)
|
|
|
|
find_path = bfs.BFS(self.saper)
|
|
find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
|
|
|
|
#co ma robić przy każdym FPS'ie
|
|
def updateFPS(self):
|
|
pass
|
|
|
|
#co ma zrobić przy każdym ruchu <------------------------- najważniejsze
|
|
def updateTile(self):
|
|
#aktualne pola (do debugu)
|
|
sensor = self.saper.sensor()
|
|
|
|
print(sensor[0])
|
|
print(sensor[1])
|
|
print(sensor[2])
|
|
print("-------")
|
|
|
|
|
|
#podniesienie bomby jeśli jest jakaś na tym polu
|
|
self.saper.pick_up()
|
|
|
|
#poruszenie się
|
|
if self.user_controlled:
|
|
self.minesweeper_controls()
|
|
return
|
|
self.chaos_controls() # <--------------------------zamiast tego trzeba wstawić jakiś algorytm
|
|
|
|
|
|
def minesweeper_controls(self):
|
|
keys = pygame.key.get_pressed()
|
|
if keys[pygame.K_DOWN]:
|
|
self.saper.move(0)
|
|
elif keys[pygame.K_UP]:
|
|
self.saper.move(180)
|
|
elif keys[pygame.K_LEFT]:
|
|
self.saper.move(270)
|
|
elif keys[pygame.K_RIGHT]:
|
|
self.saper.move(90)
|
|
|
|
def chaos_controls(self):
|
|
dir = randrange(4)
|
|
if dir==0:
|
|
self.saper.rotate("N")
|
|
elif dir==1:
|
|
self.saper.rotate("S")
|
|
elif dir==2:
|
|
self.saper.rotate("W")
|
|
elif dir==3:
|
|
self.saper.rotate("E")
|
|
self.saper.move() |