Compare commits

...

9 Commits

Author SHA1 Message Date
93ed2f39f5 merged 2020-04-26 14:27:24 +02:00
230b63d87b merged semi-final 2020-04-26 14:12:08 +02:00
e2facd2c42 unsresolved merge 2020-04-26 14:11:19 +02:00
f7612970d2 mergeradd 2020-04-26 13:32:47 +02:00
8b609f0259 merge 2020-04-26 13:32:20 +02:00
7cb3aa904c kolejna poprawa astar 2020-04-26 12:58:52 +02:00
9127c46938 algoryth astar v2 2020-04-26 11:14:26 +02:00
Adam Osiowy
1dc9e45f19 dodana obsluga przyciskow 'q' i 's' 2020-04-25 16:33:44 +02:00
Adam Osiowy
cc6fdc2e8b stworzone srodowisko testowe - A* 2020-04-25 15:42:45 +02:00
3 changed files with 25 additions and 13 deletions

View File

@ -40,7 +40,8 @@ def astar(obiekty, start, cel):
continue continue
elif 6 <= sasiad[0] <= 7 and 10 <= sasiad[1] <= 11: elif 6 <= sasiad[0] <= 7 and 10 <= sasiad[1] <= 11:
continue continue
tentative_h_score = heurystyka(obiekty, sasiad, cel) + heurystyka(obiekty, current, sasiad) tentative_h_score = heurystyka(
obiekty, sasiad, cel) + heurystyka(obiekty, current, sasiad)
if sasiad in [i[1] for i in oheap] and tentative_h_score < hscore.get(current, 0): if sasiad in [i[1] for i in oheap] and tentative_h_score < hscore.get(current, 0):
continue continue
@ -48,7 +49,8 @@ def astar(obiekty, start, cel):
came_from[sasiad] = current came_from[sasiad] = current
hscore[sasiad] = tentative_h_score hscore[sasiad] = tentative_h_score
fscore[sasiad] = tentative_h_score + gscore[current] fscore[sasiad] = tentative_h_score + gscore[current]
gscore[sasiad] = gscore[current] + heurystyka(obiekty, current, sasiad) gscore[sasiad] = gscore[current] + \
heurystyka(obiekty, current, sasiad)
heapq.heappush(oheap, (fscore[sasiad], sasiad)) heapq.heappush(oheap, (fscore[sasiad], sasiad))
obiekty["plansza"][sasiad[0], sasiad[1]].setKolor((0, 255, 0)) obiekty["plansza"][sasiad[0], sasiad[1]].setKolor((0, 255, 0))
return False return False

15
game.py
View File

@ -190,7 +190,8 @@ def utworzObiekty():
dom.setImage(pygame.image.load(random.choice(doms_array))) dom.setImage(pygame.image.load(random.choice(doms_array)))
plansza[wspolrzedne_domow[i][0], plansza[wspolrzedne_domow[i][0],
wspolrzedne_domow[i][1]].setJestDomem(True) wspolrzedne_domow[i][1]].setJestDomem(True)
plansza[wspolrzedne_domow[i][0], wspolrzedne_domow[i][1]].setObiekt(dom) plansza[wspolrzedne_domow[i][0],
wspolrzedne_domow[i][1]].setObiekt(dom)
domy_lista.add(dom) domy_lista.add(dom)
all_sprites_list.add(dom) all_sprites_list.add(dom)
@ -249,10 +250,14 @@ def liczSmieci(domy, obiekty):
elif "trash" in s: elif "trash" in s:
ile_pozostalych += 1 ile_pozostalych += 1
text_metal = obiekty["font"].render("Metal: " + str(ile_metalu), True, WHITE) text_metal = obiekty["font"].render(
text_papier = obiekty["font"].render("Papier: " + str(ile_papieru), True, WHITE) "Metal: " + str(ile_metalu), True, WHITE)
text_plastik = obiekty["font"].render("Plastik: " + str(ile_plastiku), True, WHITE) text_papier = obiekty["font"].render(
text_szklo = obiekty["font"].render("Szkło: " + str(ile_szkla), True, WHITE) "Papier: " + str(ile_papieru), True, WHITE)
text_plastik = obiekty["font"].render(
"Plastik: " + str(ile_plastiku), True, WHITE)
text_szklo = obiekty["font"].render(
"Szkło: " + str(ile_szkla), True, WHITE)
text_pozostale = obiekty["font"].render( text_pozostale = obiekty["font"].render(
"Pozostałe: " + str(ile_pozostalych), True, WHITE) "Pozostałe: " + str(ile_pozostalych), True, WHITE)
text_odwiedzone_domy = obiekty["font"].render( text_odwiedzone_domy = obiekty["font"].render(

View File

@ -57,7 +57,8 @@ class Smieciarka(pygame.sprite.Sprite):
self.w_dol() self.w_dol()
def astar_move(self, obiekty): def astar_move(self, obiekty):
sciezka = astar.astar(obiekty, self.pozycja, (random.randrange(15), random.randrange(15))) sciezka = astar.astar(obiekty, self.pozycja,
(random.randrange(15), random.randrange(15)))
print(sciezka) print(sciezka)
if sciezka: if sciezka:
for koord in sciezka: for koord in sciezka:
@ -75,7 +76,8 @@ class Smieciarka(pygame.sprite.Sprite):
if self.plansza[self.x - 1, self.y].jestPrzeszkoda is not True: if self.plansza[self.x - 1, self.y].jestPrzeszkoda is not True:
if self.plansza[self.x - 1, self.y].jestDomem is True: if self.plansza[self.x - 1, self.y].jestDomem is True:
if [self.x - 1, self.y] not in self.wspolrzedne_odwiedzonych_domow: if [self.x - 1, self.y] not in self.wspolrzedne_odwiedzonych_domow:
self.wspolrzedne_odwiedzonych_domow.append([self.x - 1, self.y]) self.wspolrzedne_odwiedzonych_domow.append(
[self.x - 1, self.y])
self.zwiekszIloscOdwiedzonychDomow() self.zwiekszIloscOdwiedzonychDomow()
if self.ruch == 2: if self.ruch == 2:
self.image = pygame.image.load( self.image = pygame.image.load(
@ -94,7 +96,8 @@ class Smieciarka(pygame.sprite.Sprite):
if self.plansza[self.x + 1, self.y].jestPrzeszkoda is not True: if self.plansza[self.x + 1, self.y].jestPrzeszkoda is not True:
if self.plansza[self.x + 1, self.y].jestDomem is True: if self.plansza[self.x + 1, self.y].jestDomem is True:
if [self.x + 1, self.y] not in self.wspolrzedne_odwiedzonych_domow: if [self.x + 1, self.y] not in self.wspolrzedne_odwiedzonych_domow:
self.wspolrzedne_odwiedzonych_domow.append([self.x + 1, self.y]) self.wspolrzedne_odwiedzonych_domow.append(
[self.x + 1, self.y])
self.zwiekszIloscOdwiedzonychDomow() self.zwiekszIloscOdwiedzonychDomow()
if self.ruch == 1: if self.ruch == 1:
self.image = pygame.transform.flip(self.image, True, False) self.image = pygame.transform.flip(self.image, True, False)
@ -112,7 +115,8 @@ class Smieciarka(pygame.sprite.Sprite):
if self.plansza[self.x, self.y - 1].jestPrzeszkoda is not True: if self.plansza[self.x, self.y - 1].jestPrzeszkoda is not True:
if self.plansza[self.x, self.y - 1].jestDomem is True: if self.plansza[self.x, self.y - 1].jestDomem is True:
if [self.x, self.y - 1] not in self.wspolrzedne_odwiedzonych_domow: if [self.x, self.y - 1] not in self.wspolrzedne_odwiedzonych_domow:
self.wspolrzedne_odwiedzonych_domow.append([self.x, self.y - 1]) self.wspolrzedne_odwiedzonych_domow.append(
[self.x, self.y - 1])
self.zwiekszIloscOdwiedzonychDomow() self.zwiekszIloscOdwiedzonychDomow()
self.plansza[self.x, self.y - 1].setKolor(BLUE) self.plansza[self.x, self.y - 1].setKolor(BLUE)
@ -127,7 +131,8 @@ class Smieciarka(pygame.sprite.Sprite):
if self.plansza[self.x, self.y + 1].jestPrzeszkoda is not True: if self.plansza[self.x, self.y + 1].jestPrzeszkoda is not True:
if self.plansza[self.x, self.y + 1].jestDomem is True: if self.plansza[self.x, self.y + 1].jestDomem is True:
if [self.x, self.y + 1] not in self.wspolrzedne_odwiedzonych_domow: if [self.x, self.y + 1] not in self.wspolrzedne_odwiedzonych_domow:
self.wspolrzedne_odwiedzonych_domow.append([self.x, self.y + 1]) self.wspolrzedne_odwiedzonych_domow.append(
[self.x, self.y + 1])
self.zwiekszIloscOdwiedzonychDomow() self.zwiekszIloscOdwiedzonychDomow()
self.plansza[self.x, self.y + 1].setKolor(BLUE) self.plansza[self.x, self.y + 1].setKolor(BLUE)