2023-05-06 14:54:04 +02:00
|
|
|
import sys
|
2023-05-30 19:09:24 +02:00
|
|
|
|
|
|
|
import joblib
|
2023-05-06 14:54:04 +02:00
|
|
|
import pygame
|
2023-05-29 00:13:02 +02:00
|
|
|
from paczka import Paczka
|
2023-06-02 21:14:55 +02:00
|
|
|
from letter import Letter
|
2023-05-06 14:54:04 +02:00
|
|
|
from wozek import Wozek
|
|
|
|
import wyszukiwanie
|
|
|
|
import ekran
|
2023-05-29 00:13:02 +02:00
|
|
|
from grid import GridCellType, SearchGrid
|
2023-06-02 21:14:55 +02:00
|
|
|
import plansza
|
2023-05-30 19:09:24 +02:00
|
|
|
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-29 11:00:58 +02:00
|
|
|
from plansza import a_pix, b_pix
|
2023-05-06 14:54:04 +02:00
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
wozek = Wozek()
|
2023-05-29 11:00:58 +02:00
|
|
|
p1 = Paczka('duzy', 12, 'narzedzia', False, True, False, any, any, any, any, any)
|
|
|
|
p2 = Paczka('maly', 1, 'ogród', False, True, False, any, any, any, any, any)
|
2023-06-02 21:14:55 +02:00
|
|
|
l1 = Letter(1)
|
|
|
|
l2 = Letter(2)
|
|
|
|
ekran.dodaj_na_rampe(p2, l1, p1, l2)
|
2023-05-29 00:13:02 +02:00
|
|
|
grid_points = SearchGrid()
|
2023-05-30 19:09:24 +02:00
|
|
|
|
|
|
|
# Odczyt drzewa z pliku
|
|
|
|
drzewo = joblib.load('DecisionTree/wyuczone_drzewo.pkl')
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-06 14:54:04 +02:00
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
sys.exit(0)
|
|
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
|
|
sys.exit(0)
|
2023-05-29 00:13:02 +02:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_SPACE:
|
2023-06-02 21:14:55 +02:00
|
|
|
|
|
|
|
## wozek jedzie po itemy
|
|
|
|
wiersz = ekran.sprawdz_ktory_wiersz(a_pix)
|
|
|
|
kolumna = ekran.sprawdz_ktora_kolumna(b_pix)
|
|
|
|
docelowy_stan = wyszukiwanie.Stan(wiersz * 70, kolumna * 70, 1)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
#wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan, grid_points)
|
2023-06-02 21:14:55 +02:00
|
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
## sprawdzenie czy lista itemow nie jest pusta
|
|
|
|
if ekran.lista_itemow:
|
|
|
|
if grid_points.grid[(wiersz, kolumna)] is GridCellType.PLACE: #picks up item
|
2023-05-30 21:36:48 +02:00
|
|
|
if wozek.ln == 0:
|
2023-06-02 21:14:55 +02:00
|
|
|
wozek.picks_up_item()
|
2023-05-30 21:36:48 +02:00
|
|
|
wozek.dynamic_wozek_picture()
|
2023-05-29 11:15:06 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
przenoszony_item = wozek.storage[-1]
|
|
|
|
if isinstance(przenoszony_item,Paczka):
|
|
|
|
## wozek jedzie odlozyc paczke na regal
|
|
|
|
przenoszona_paczka = przenoszony_item
|
|
|
|
|
|
|
|
array, reg = przenoszona_paczka.tablica_do_drzewa(przenoszona_paczka.kategoria)
|
|
|
|
|
|
|
|
predictions = drzewo.predict([array])
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
if predictions == 0:
|
|
|
|
print('odklada na dolna polke!')
|
|
|
|
else:
|
|
|
|
print('odklada na gorna polke!')
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
docelowy_stan = wyszukiwanie.Stan(reg.numerWiersza * 70, reg.numerKolumny * 70, 1)
|
|
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
if wozek.ln != 0: # drops package
|
|
|
|
wozek.drops_package(przenoszona_paczka, reg, predictions)
|
|
|
|
wozek.dynamic_wozek_picture()
|
2023-05-30 21:36:48 +02:00
|
|
|
else:
|
2023-06-02 21:14:55 +02:00
|
|
|
#list przenoszony do skrzynki
|
|
|
|
docelowy_stan = wyszukiwanie.Stan(plansza.c_pix, plansza.d_pix, 1)
|
|
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-06-02 21:14:55 +02:00
|
|
|
if wozek.ln != 0: # drops letter
|
|
|
|
wozek.drops_letter(przenoszony_item)
|
|
|
|
wozek.dynamic_wozek_picture()
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-29 00:48:58 +02:00
|
|
|
|
2023-05-29 11:00:58 +02:00
|
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
2023-05-06 14:54:04 +02:00
|
|
|
# lewy przycisk myszy
|
|
|
|
if event.button == 1:
|
|
|
|
x = pygame.mouse.get_pos()[0]
|
|
|
|
y = pygame.mouse.get_pos()[1]
|
|
|
|
wiersz = ekran.sprawdz_ktory_wiersz(x)
|
|
|
|
kolumna = ekran.sprawdz_ktora_kolumna(y)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-14 15:21:09 +02:00
|
|
|
docelowy_stan = wyszukiwanie.Stan(wiersz * 70, kolumna * 70, 1)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
#wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan, grid_points)
|
2023-05-14 15:21:09 +02:00
|
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
2023-05-06 14:54:04 +02:00
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
|
|
|
|
2023-05-29 00:13:02 +02:00
|
|
|
# if grid_points.grid[(wiersz, kolumna)] is GridCellType.PLACE: #picks up package
|
|
|
|
# if wozek.ln == 0:
|
|
|
|
# wozek.load_package()
|
|
|
|
# wozek.dynamic_wozek_picture
|
|
|
|
# else:
|
|
|
|
# if wozek.ln != 0: # drops package
|
|
|
|
# wozek.drop_package()
|
|
|
|
# wozek.dynamic_wozek_picture()
|
|
|
|
|
|
|
|
# if event.type == pygame.KEYDOWN:
|
|
|
|
# if event.key == pygame.K_SPACE:
|
|
|
|
# if wozek.ln == 0:
|
|
|
|
# wozek.load_package()
|
|
|
|
# wozek.dynamic_wozek_picture()
|
|
|
|
# else:
|
|
|
|
# wozek.drop_package()
|
|
|
|
# wozek.dynamic_wozek_picture()
|
2023-05-06 14:54:04 +02:00
|
|
|
|
|
|
|
ekran.odswiez_ekran(wozek)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|