2023-05-06 14:54:04 +02:00
|
|
|
import sys
|
|
|
|
import pygame
|
2023-05-29 00:13:02 +02:00
|
|
|
from paczka import Paczka
|
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
|
|
|
|
from sklearn.tree import DecisionTreeClassifier
|
|
|
|
import pandas as pd
|
2023-05-30 18:47:23 +02:00
|
|
|
import drzewo_decyzyjne
|
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-05-30 18:47:23 +02:00
|
|
|
ekran.dodaj_paczki_na_rampe(p1, p2)
|
2023-05-29 00:13:02 +02:00
|
|
|
grid_points = SearchGrid()
|
2023-05-30 18:47:23 +02:00
|
|
|
drzewo = drzewo_decyzyjne.make_tree()
|
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:
|
|
|
|
## wozek jedzie po paczke
|
|
|
|
wiersz = ekran.sprawdz_ktory_wiersz(a_pix)
|
|
|
|
kolumna = ekran.sprawdz_ktora_kolumna(b_pix)
|
|
|
|
docelowy_stan = wyszukiwanie.Stan(wiersz * 70, kolumna * 70, 1)
|
|
|
|
|
|
|
|
#wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
|
|
|
|
|
|
|
if grid_points.grid[(wiersz, kolumna)] is GridCellType.PLACE: #picks up package
|
|
|
|
if wozek.ln == 0:
|
2023-05-29 11:15:06 +02:00
|
|
|
wozek.picks_up_package()
|
2023-05-29 11:00:58 +02:00
|
|
|
wozek.dynamic_wozek_picture()
|
2023-05-29 11:15:06 +02:00
|
|
|
|
2023-05-29 00:13:02 +02:00
|
|
|
## wozek jedzie odlozyc paczke na regal
|
2023-05-29 11:15:06 +02:00
|
|
|
przenoszona_paczka = wozek.storage[-1]
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-29 11:15:06 +02:00
|
|
|
array, reg = przenoszona_paczka.tablica_do_drzewa(przenoszona_paczka.kategoria)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-30 18:47:23 +02:00
|
|
|
predictions = drzewo.predict([array])
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
if predictions == 0:
|
|
|
|
print('odklada na dolna polke!')
|
|
|
|
else:
|
|
|
|
print('odklada na gorna polke!')
|
|
|
|
|
2023-05-30 18:47:23 +02:00
|
|
|
docelowy_stan = wyszukiwanie.Stan(reg.numerWiersza * 70, reg.numerKolumny * 70, 1)
|
2023-05-29 00:13:02 +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:48:58 +02:00
|
|
|
if wozek.ln != 0: # drops package
|
2023-05-29 11:15:06 +02:00
|
|
|
wozek.drops_package(przenoszona_paczka, reg, predictions)
|
2023-05-29 00:48:58 +02:00
|
|
|
wozek.dynamic_wozek_picture()
|
|
|
|
|
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()
|
|
|
|
|
2023-05-06 14:54:04 +02:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_DOWN:
|
|
|
|
wozek.y_change = 1
|
|
|
|
if event.key == pygame.K_UP:
|
|
|
|
wozek.y_change = -1
|
|
|
|
if event.key == pygame.K_RIGHT:
|
|
|
|
wozek.x_change = 1
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
wozek.x_change = -1
|
|
|
|
|
|
|
|
if event.type == pygame.KEYUP:
|
|
|
|
if event.key == pygame.K_DOWN or event.key == pygame.K_UP:
|
|
|
|
wozek.y_change = 0
|
|
|
|
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
|
|
|
wozek.x_change = 0
|
|
|
|
|
2023-05-29 00:13:02 +02:00
|
|
|
# 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
|
|
|
|
|
|
|
wozek.obecnyStan.x += wozek.x_change
|
|
|
|
wozek.obecnyStan.y += wozek.y_change
|
|
|
|
|
|
|
|
if wozek.obecnyStan.x <= 0:
|
|
|
|
wozek.obecnyStan.x = 0
|
2023-05-27 23:50:48 +02:00
|
|
|
elif wozek.obecnyStan.x >= ekran.EKRAN_SZEROKOSC-70:
|
|
|
|
wozek.obecnyStan.x = ekran.EKRAN_SZEROKOSC-70
|
2023-05-06 14:54:04 +02:00
|
|
|
if wozek.obecnyStan.y <= 0:
|
|
|
|
wozek.obecnyStan.y = 0
|
2023-05-27 23:50:48 +02:00
|
|
|
elif wozek.obecnyStan.y >= ekran.EKRAN_WYSOKOSC-70:
|
|
|
|
wozek.obecnyStan.y = ekran.EKRAN_WYSOKOSC-70
|
2023-05-06 14:54:04 +02:00
|
|
|
|
|
|
|
ekran.odswiez_ekran(wozek)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|