forked from s474139/Inteligentny_Wozek
adding class stan, bfs template
This commit is contained in:
parent
48c4833ec8
commit
ea49df80bd
54
main.py
54
main.py
@ -2,7 +2,8 @@ import sys
|
||||
import pygame
|
||||
import regal
|
||||
import paczka
|
||||
#from wozek import Wozek
|
||||
from wozek import Wozek
|
||||
import wyszukiwanie
|
||||
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((980, 980))
|
||||
@ -12,47 +13,6 @@ pygame.display.set_caption("Inteligentny wozek")
|
||||
icon = pygame.image.load('images/icon.png')
|
||||
pygame.display.set_icon(icon)
|
||||
|
||||
class Wozek():
|
||||
def __init__(self):
|
||||
self.x = 55
|
||||
self.y = 55
|
||||
self.x_change = 0
|
||||
self.y_change = 0
|
||||
self.height = 64
|
||||
self.width = 64
|
||||
self.image = pygame.image.load("images/pusty_wozek.png")
|
||||
# Credit: Forklift icons created by Smashicons - Flaticon
|
||||
# https://www.flaticon.com/free-icons/forklift
|
||||
|
||||
def draw(self):
|
||||
screen.blit(self.image, (self.x, self.y))
|
||||
|
||||
#storage = ["none"] * 10
|
||||
storage = []
|
||||
max_size = 10
|
||||
|
||||
def add_element(element, storage, max_size):
|
||||
if len(storage) < max_size:
|
||||
storage.append(element)
|
||||
else:
|
||||
print("I'm full!")
|
||||
def remove_element(storage):
|
||||
if len(storage) > 0:
|
||||
place = storage.pop()
|
||||
return place
|
||||
else:
|
||||
print("I'm empty!")
|
||||
|
||||
def dynamic_wozek_picture(wozek, storage):
|
||||
if len(storage) == 0:
|
||||
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
||||
elif ((len(storage) > 0) and (len(storage) < 4)):
|
||||
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
||||
elif ((len(storage) > 3) and (len(storage) < 10)):
|
||||
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
||||
elif (len(storage) == 10):
|
||||
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
||||
|
||||
|
||||
def main():
|
||||
wozek = Wozek()
|
||||
@ -63,6 +23,16 @@ def main():
|
||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
||||
sys.exit(0)
|
||||
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
# lewy przycisk myszy
|
||||
if event.button == 1:
|
||||
x = pygame.mouse.get_pos()[0]
|
||||
y = pygame.mouse.get_pos()[1]
|
||||
|
||||
docelowy_stan = wyszukiwanie.Stan(x, y, 0)
|
||||
# print(f'{docelowy_stan.x} + {docelowy_stan.y}')
|
||||
wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan)
|
||||
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_DOWN:
|
||||
wozek.y_change = 1
|
||||
|
@ -1,5 +1,5 @@
|
||||
from etykieta import Etykieta
|
||||
from main import pygame
|
||||
import pygame
|
||||
|
||||
|
||||
class Paczka:
|
||||
|
4
regal.py
4
regal.py
@ -1,6 +1,6 @@
|
||||
import pygame
|
||||
|
||||
from main import screen
|
||||
|
||||
|
||||
def obliczPixeleNaPodstawieKratek(wymiar): #Przeliczanie współrzędnych podanych w kratkach na pixele
|
||||
i = 1
|
||||
@ -29,6 +29,8 @@ class Regal:
|
||||
self.kolumna = obliczPixeleNaPodstawieKratek(numerKolumny)
|
||||
self.dlugosc = obliczPixeleDlugosciRegalu(self)
|
||||
|
||||
from main import screen
|
||||
|
||||
if(self.numerRegalu >= 0 and self.numerRegalu <= 4):
|
||||
reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu])
|
||||
reg = pygame.image.load("images/regal.png")
|
||||
|
18
wozek.py
18
wozek.py
@ -1,4 +1,6 @@
|
||||
from main import pygame, screen
|
||||
import pygame
|
||||
|
||||
|
||||
|
||||
# screen nie działa
|
||||
|
||||
@ -13,9 +15,12 @@ class Wozek():
|
||||
self.image = pygame.image.load("images/pusty_wozek.png")
|
||||
# Credit: Forklift icons created by Smashicons - Flaticon
|
||||
# https://www.flaticon.com/free-icons/forklift
|
||||
self.__zainicjuj_stan_poczatkowy()
|
||||
|
||||
def draw(self):
|
||||
screen.blit(self.image, (self.x, self.y))
|
||||
from main import screen
|
||||
# screen.blit(self.image, (self.x, self.y))
|
||||
screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
|
||||
|
||||
# storage = ["none"] * 10
|
||||
storage = []
|
||||
@ -26,6 +31,7 @@ class Wozek():
|
||||
storage.append(element)
|
||||
else:
|
||||
print("I'm full!")
|
||||
|
||||
def remove_element(storage):
|
||||
if len(storage) > 0:
|
||||
place = storage.pop()
|
||||
@ -42,3 +48,11 @@ class Wozek():
|
||||
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
||||
elif (len(storage) == 10):
|
||||
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
||||
|
||||
def __zainicjuj_stan_poczatkowy(self):
|
||||
from wyszukiwanie import Stan
|
||||
self.obecnyStan = Stan(55, 55, 3)
|
||||
|
||||
# def ustaw_wozek_w_kierunku(self, kierunek):
|
||||
# TODO
|
||||
|
||||
|
59
wyszukiwanie.py
Normal file
59
wyszukiwanie.py
Normal file
@ -0,0 +1,59 @@
|
||||
class Stan:
|
||||
def __init__(self, x, y, kierunek):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.kierunek = kierunek
|
||||
|
||||
|
||||
class Wezel:
|
||||
def __init__(self, stan):
|
||||
self.stan = stan
|
||||
|
||||
|
||||
def poprzednik(wezel):
|
||||
# gora -> prawo -> dol -> lewo | obrot w prawo
|
||||
# gora -> lewo -> dol -> prawo | obrot w lewo
|
||||
# 0 gora 1 prawo 2 dol 3 lewo
|
||||
y = wezel.stan.x
|
||||
x = wezel.stan.y
|
||||
obrot_w_prawo = Stan(x, y, (wezel.stan.kierunek + 1) % 4)
|
||||
obrot_w_lewo = Stan(x, y, (wezel.stan.kierunek - 1) % 4)
|
||||
|
||||
if wezel.stan.kierunek == 0:
|
||||
y -= 1
|
||||
elif wezel.stan.kierunek == 1:
|
||||
x += 1
|
||||
elif wezel.stan.kierunek == 2:
|
||||
y += 1
|
||||
elif wezel.stan.kierunek == 3:
|
||||
x -= 1
|
||||
|
||||
wezly = [obrot_w_prawo, obrot_w_lewo]
|
||||
ruch_w_przod = Stan(x, y, wezel.stan.kierunek)
|
||||
|
||||
# sprawdzenie czy nie wyjdzie poza plansze
|
||||
if 0 <= x <= 916 and 0 <= y <= 916:
|
||||
wezly.append(ruch_w_przod)
|
||||
|
||||
return wezly
|
||||
|
||||
|
||||
def wyszukiwanie_bfs(stan_poczatkowy, stan_docelowy):
|
||||
pierwszy_wezel = Wezel(stan_poczatkowy)
|
||||
fringe = [pierwszy_wezel]
|
||||
|
||||
odwiedzone = list()
|
||||
|
||||
while fringe:
|
||||
# kolejka
|
||||
wezel = fringe.pop(0)
|
||||
|
||||
if stan_docelowy.x == wezel.stan.x and stan_docelowy.y == wezel.stan.y:
|
||||
return odwiedzone
|
||||
|
||||
odwiedzone.append(wezel)
|
||||
|
||||
for stan in poprzednik(wezel):
|
||||
if wezel not in fringe and stan not in odwiedzone:
|
||||
nowy_wezel = Wezel(stan)
|
||||
fringe.append(nowy_wezel)
|
Loading…
Reference in New Issue
Block a user