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-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)
|
|
|
|
ekran.lista_paczek.append(p1)
|
|
|
|
ekran.lista_paczek.append(p2)
|
|
|
|
p1.update_position(a_pix, b_pix)
|
|
|
|
p2.update_position(a_pix, b_pix)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
grid_points = SearchGrid()
|
|
|
|
|
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:00:58 +02:00
|
|
|
paczka_pop = ekran.lista_paczek.pop()
|
|
|
|
ekran.lista_paczek_na_regalach.append(paczka_pop)
|
|
|
|
paczka_pop.is_in_move = True
|
|
|
|
wozek.storage.append(paczka_pop)
|
|
|
|
wozek.ln = wozek.ln + 1
|
|
|
|
wozek.dynamic_wozek_picture()
|
|
|
|
print(ekran.lista_paczek)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
## wozek jedzie odlozyc paczke na regal
|
2023-05-29 11:00:58 +02:00
|
|
|
paczka1 = wozek.storage[-1]
|
2023-05-29 00:13:02 +02:00
|
|
|
|
2023-05-29 00:48:58 +02:00
|
|
|
array, reg = paczka1.tablica_do_drzewa(paczka1.kategoria)
|
2023-05-29 00:13:02 +02:00
|
|
|
|
|
|
|
plikZPrzecinkami = open("DecisionTree/training_data.txt", 'w')
|
|
|
|
|
|
|
|
with open('DecisionTree/200permutations_table.txt', 'r') as plik:
|
|
|
|
for linia in plik:
|
|
|
|
liczby = linia.strip()
|
|
|
|
wiersz = ""
|
|
|
|
licznik = 0
|
|
|
|
for liczba in liczby:
|
|
|
|
wiersz += liczba
|
|
|
|
wiersz += ";"
|
|
|
|
wiersz = wiersz[:-1]
|
|
|
|
wiersz += '\n'
|
|
|
|
plikZPrzecinkami.write(wiersz)
|
|
|
|
|
|
|
|
plikZPrzecinkami.close()
|
|
|
|
x = pd.read_csv('DecisionTree/training_data.txt', delimiter=';',
|
|
|
|
names=['wielkosc', 'waga,', 'priorytet', 'ksztalt', 'kruchosc', 'dolna', 'gorna', 'g > d'])
|
|
|
|
y = pd.read_csv('DecisionTree/decisions.txt', names=['polka'])
|
|
|
|
clf = DecisionTreeClassifier(criterion='entropy')
|
|
|
|
clf.fit(x.values, y.values)
|
|
|
|
|
|
|
|
predictions = clf.predict([array])
|
|
|
|
if predictions == 0:
|
|
|
|
print('odklada na dolna polke!')
|
|
|
|
else:
|
|
|
|
print('odklada na gorna polke!')
|
|
|
|
|
|
|
|
docelowy_stan = wyszukiwanie.Stan(reg.numerWiersza * 70, reg.numerKolumny * 70, 1) # x1 i y1 bo to są regału kategorii ogród
|
|
|
|
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:00:58 +02:00
|
|
|
print(paczka1)
|
|
|
|
paczka1.update_position(reg.numerWiersza*70, reg.numerKolumny*70)
|
|
|
|
paczka_pop.is_in_move = False
|
|
|
|
wozek.storage.pop()
|
|
|
|
wozek.ln = wozek.ln - 1
|
2023-05-29 00:48:58 +02:00
|
|
|
reg.put_package_on_the_regal(paczka1, predictions)
|
|
|
|
wozek.dynamic_wozek_picture()
|
2023-05-29 11:00:58 +02:00
|
|
|
ekran.odswiez_ekran(wozek)
|
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()
|
|
|
|
|
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()
|