podprojekt kacper
71
game.py
@ -5,6 +5,7 @@ import random
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import astar
|
import astar
|
||||||
|
import uczenie_kacper as kacper
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
@ -42,8 +43,7 @@ def game():
|
|||||||
nieodwiedzone_kontenery = [(obiekty["kontener_szklo"].x, obiekty["kontener_szklo"].y),
|
nieodwiedzone_kontenery = [(obiekty["kontener_szklo"].x, obiekty["kontener_szklo"].y),
|
||||||
(obiekty["kontener_papier"].x, obiekty["kontener_papier"].y),
|
(obiekty["kontener_papier"].x, obiekty["kontener_papier"].y),
|
||||||
(obiekty["kontener_metal"].x, obiekty["kontener_metal"].y),
|
(obiekty["kontener_metal"].x, obiekty["kontener_metal"].y),
|
||||||
(obiekty["kontener_plastik"].x, obiekty["kontener_plastik"].y),
|
(obiekty["kontener_plastik"].x, obiekty["kontener_plastik"].y),]
|
||||||
(obiekty["kontener_organiczne"].x, obiekty["kontener_organiczne"].y)]
|
|
||||||
# Petla az uzytkownik zamknie program
|
# Petla az uzytkownik zamknie program
|
||||||
done = False
|
done = False
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
@ -66,9 +66,10 @@ def game():
|
|||||||
"Grid coordinates: ", wiersz, kolumna)
|
"Grid coordinates: ", wiersz, kolumna)
|
||||||
elif event.type == pygame.KEYDOWN:
|
elif event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
obiekty["smieciarka"].w_lewo()
|
kacper.przewidz()
|
||||||
|
|
||||||
if event.key == pygame.K_RIGHT:
|
if event.key == pygame.K_RIGHT:
|
||||||
obiekty["smieciarka"].w_prawo()
|
kacper.trainModel()
|
||||||
if event.key == pygame.K_UP:
|
if event.key == pygame.K_UP:
|
||||||
obiekty["smieciarka"].w_gore()
|
obiekty["smieciarka"].w_gore()
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
@ -79,11 +80,45 @@ def game():
|
|||||||
nieodwiedzone_domy.sort(key=lambda x: astar.heurystyka((obiekty["smieciarka"].x, obiekty["smieciarka"].y), x))
|
nieodwiedzone_domy.sort(key=lambda x: astar.heurystyka((obiekty["smieciarka"].x, obiekty["smieciarka"].y), x))
|
||||||
cel = nieodwiedzone_domy.pop(0)
|
cel = nieodwiedzone_domy.pop(0)
|
||||||
obiekty["smieciarka"].astar_move(obiekty, (obiekty["smieciarka"].x, obiekty["smieciarka"].y), cel)
|
obiekty["smieciarka"].astar_move(obiekty, (obiekty["smieciarka"].x, obiekty["smieciarka"].y), cel)
|
||||||
|
pozX = cel[0]
|
||||||
|
pozY = cel[1]
|
||||||
|
for dom in obiekty["domy"]:
|
||||||
|
if dom.x == pozX and dom.y == pozY:
|
||||||
|
while dom.smieci:
|
||||||
|
smiec = dom.smieci.pop(0)
|
||||||
|
rodzaj = kacper.przewidz(smiec)
|
||||||
|
if rodzaj == "paper":
|
||||||
|
obiekty["smieciarka"].dodajPapier(smiec)
|
||||||
|
elif rodzaj == "glass":
|
||||||
|
obiekty["smieciarka"].dodajSzklo(smiec)
|
||||||
|
elif rodzaj == "metal":
|
||||||
|
obiekty["smieciarka"].dodajMetal(smiec)
|
||||||
|
elif rodzaj == "plastic":
|
||||||
|
obiekty["smieciarka"].dodajPlastik(smiec)
|
||||||
|
|
||||||
while nieodwiedzone_kontenery:
|
while nieodwiedzone_kontenery:
|
||||||
nieodwiedzone_kontenery.sort(key=lambda x: astar.heurystyka((obiekty["smieciarka"].x, obiekty["smieciarka"].y), x))
|
nieodwiedzone_kontenery.sort(key=lambda x: astar.heurystyka((obiekty["smieciarka"].x, obiekty["smieciarka"].y), x))
|
||||||
cel = nieodwiedzone_kontenery.pop(0)
|
cel = nieodwiedzone_kontenery.pop(0)
|
||||||
obiekty["smieciarka"].astar_move(obiekty, (obiekty["smieciarka"].x, obiekty["smieciarka"].y), cel)
|
obiekty["smieciarka"].astar_move(obiekty, (obiekty["smieciarka"].x, obiekty["smieciarka"].y), cel)
|
||||||
|
pozX = cel[0]
|
||||||
|
pozY = cel[1]
|
||||||
|
|
||||||
|
if obiekty["plansza"][pozX, pozY].obiekt == obiekty["kontener_papier"]:
|
||||||
|
while obiekty["smieciarka"].papier:
|
||||||
|
smiec = obiekty["smieciarka"].papier.pop(0)
|
||||||
|
obiekty["kontener_papier"].dodajSmiec(smiec)
|
||||||
|
elif obiekty["plansza"][pozX, pozY].obiekt == obiekty["kontener_szklo"]:
|
||||||
|
while obiekty["smieciarka"].szklo:
|
||||||
|
smiec = obiekty["smieciarka"].szklo.pop(0)
|
||||||
|
obiekty["kontener_szklo"].dodajSmiec(smiec)
|
||||||
|
elif obiekty["plansza"][pozX, pozY].obiekt == obiekty["kontener_metal"]:
|
||||||
|
while obiekty["smieciarka"].metal:
|
||||||
|
smiec = obiekty["smieciarka"].metal.pop(0)
|
||||||
|
obiekty["kontener_metal"].dodajSmiec(smiec)
|
||||||
|
elif obiekty["plansza"][pozX, pozY].obiekt == obiekty["kontener_plastik"]:
|
||||||
|
while obiekty["smieciarka"].plastik:
|
||||||
|
smiec = obiekty["smieciarka"].plastik.pop(0)
|
||||||
|
obiekty["kontener_plastik"].dodajSmiec(smiec)
|
||||||
|
|
||||||
clock.tick(7)
|
clock.tick(7)
|
||||||
|
|
||||||
@ -113,14 +148,14 @@ def rysowaniePlanszy(obiekty):
|
|||||||
obiekty["plansza"][7, 11].setJestPrzeszkoda(True)
|
obiekty["plansza"][7, 11].setJestPrzeszkoda(True)
|
||||||
obiekty["sprajty"].draw(obiekty["obraz"])
|
obiekty["sprajty"].draw(obiekty["obraz"])
|
||||||
text_metal, text_papier, text_plastik, text_szklo, text_pozostale, text_odwiedzone_domy = liczSmieci(
|
text_metal, text_papier, text_plastik, text_szklo, text_pozostale, text_odwiedzone_domy = liczSmieci(
|
||||||
obiekty["domy"],obiekty)
|
obiekty["domy"], obiekty)
|
||||||
obiekty["obraz"].blit(obiekty["text_pozostalo"],
|
obiekty["obraz"].blit(obiekty["text_pozostalo"],
|
||||||
(1020, 240))
|
(1020, 240))
|
||||||
obiekty["obraz"].blit(text_metal, (1020, 280))
|
obiekty["obraz"].blit(text_metal, (1020, 280))
|
||||||
obiekty["obraz"].blit(text_plastik, (1020, 320))
|
obiekty["obraz"].blit(text_plastik, (1020, 320))
|
||||||
obiekty["obraz"].blit(text_szklo, (1020, 360))
|
obiekty["obraz"].blit(text_szklo, (1020, 360))
|
||||||
obiekty["obraz"].blit(text_papier, (1020, 400))
|
obiekty["obraz"].blit(text_papier, (1020, 400))
|
||||||
obiekty["obraz"].blit(text_pozostale, (1020, 440))
|
# obiekty["obraz"].blit(text_pozostale, (1020, 440))
|
||||||
obiekty["obraz"].blit(text_odwiedzone_domy, (1020, 480))
|
obiekty["obraz"].blit(text_odwiedzone_domy, (1020, 480))
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
@ -159,11 +194,11 @@ def utworzObiekty():
|
|||||||
plansza[0, 4].setJestKontenerem(True)
|
plansza[0, 4].setJestKontenerem(True)
|
||||||
plansza[0, 4].setObiekt(kontener_metal)
|
plansza[0, 4].setObiekt(kontener_metal)
|
||||||
|
|
||||||
kontener_organiczne = modele.Kontener(2, 2, "pozostale")
|
# kontener_organiczne = modele.Kontener(2, 2, "pozostale")
|
||||||
kontener_organiczne.setImage(pygame.image.load(
|
# kontener_organiczne.setImage(pygame.image.load(
|
||||||
"resources/plansza/pojemnik_organiczne.png"))
|
# "resources/plansza/pojemnik_organiczne.png"))
|
||||||
plansza[2, 2].setJestKontenerem(True)
|
# plansza[2, 2].setJestKontenerem(True)
|
||||||
plansza[2, 2].setObiekt(kontener_organiczne)
|
# plansza[2, 2].setObiekt(kontener_organiczne)
|
||||||
|
|
||||||
kontener_papier = modele.Kontener(4, 0, "papier")
|
kontener_papier = modele.Kontener(4, 0, "papier")
|
||||||
kontener_papier.setImage(pygame.image.load(
|
kontener_papier.setImage(pygame.image.load(
|
||||||
@ -203,18 +238,25 @@ def utworzObiekty():
|
|||||||
all_sprites_list.add(dom)
|
all_sprites_list.add(dom)
|
||||||
|
|
||||||
lista_domow = domy_lista.sprites()
|
lista_domow = domy_lista.sprites()
|
||||||
|
acc = 0
|
||||||
for d in lista_domow:
|
for d in lista_domow:
|
||||||
for j in range(5):
|
for j in range(5):
|
||||||
smiec = random.choice(smieci_lista)
|
smiec = random.choice(smieci_lista)
|
||||||
d.dodajSmiec(smiec)
|
d.dodajSmiec(smiec)
|
||||||
smieci_lista.remove(smiec)
|
# print('')
|
||||||
|
# print(smiec)
|
||||||
|
# print(kacper.przewidz(smiec))
|
||||||
|
# if kacper.przewidz(smiec) in smiec:
|
||||||
|
# acc += 1
|
||||||
|
# smieci_lista.remove(smiec)
|
||||||
|
# print(acc)
|
||||||
|
|
||||||
# ustawienie wysypiska, rozmiar wysypiska 5x5
|
# ustawienie wysypiska, rozmiar wysypiska 5x5
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
for j in range(5):
|
for j in range(5):
|
||||||
plansza[i, j].setJestWysypiskiem(True)
|
plansza[i, j].setJestWysypiskiem(True)
|
||||||
|
|
||||||
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_papier, kontener_szklo,
|
||||||
smieciarka)
|
smieciarka)
|
||||||
|
|
||||||
obiekty = {
|
obiekty = {
|
||||||
@ -224,7 +266,6 @@ def utworzObiekty():
|
|||||||
"kontener_plastik": kontener_plastik,
|
"kontener_plastik": kontener_plastik,
|
||||||
"kontener_szklo": kontener_szklo,
|
"kontener_szklo": kontener_szklo,
|
||||||
"kontener_metal": kontener_metal,
|
"kontener_metal": kontener_metal,
|
||||||
"kontener_organiczne": kontener_organiczne,
|
|
||||||
"kontener_papier": kontener_papier,
|
"kontener_papier": kontener_papier,
|
||||||
"sprajty": all_sprites_list,
|
"sprajty": all_sprites_list,
|
||||||
"domy": lista_domow,
|
"domy": lista_domow,
|
||||||
@ -254,8 +295,6 @@ def liczSmieci(domy, obiekty):
|
|||||||
ile_plastiku += 1
|
ile_plastiku += 1
|
||||||
elif "glass" in s:
|
elif "glass" in s:
|
||||||
ile_szkla += 1
|
ile_szkla += 1
|
||||||
elif "trash" in s:
|
|
||||||
ile_pozostalych += 1
|
|
||||||
|
|
||||||
text_metal = obiekty["font"].render("Metal: " + str(ile_metalu), True, WHITE)
|
text_metal = obiekty["font"].render("Metal: " + str(ile_metalu), True, WHITE)
|
||||||
text_papier = obiekty["font"].render("Papier: " + str(ile_papieru), True, WHITE)
|
text_papier = obiekty["font"].render("Papier: " + str(ile_papieru), True, WHITE)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
pygame==1.9.6
|
pygame==1.9.6
|
||||||
numpy==1.18.2
|
numpy==1.18
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |