Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
93ed2f39f5 | |||
230b63d87b | |||
e2facd2c42 | |||
f7612970d2 | |||
8b609f0259 | |||
7cb3aa904c | |||
9127c46938 | |||
|
1dc9e45f19 | ||
|
cc6fdc2e8b |
6
astar.py
6
astar.py
@ -40,7 +40,8 @@ def astar(obiekty, start, cel):
|
||||
continue
|
||||
elif 6 <= sasiad[0] <= 7 and 10 <= sasiad[1] <= 11:
|
||||
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):
|
||||
continue
|
||||
@ -48,7 +49,8 @@ def astar(obiekty, start, cel):
|
||||
came_from[sasiad] = current
|
||||
hscore[sasiad] = tentative_h_score
|
||||
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))
|
||||
obiekty["plansza"][sasiad[0], sasiad[1]].setKolor((0, 255, 0))
|
||||
return False
|
||||
|
17
game.py
17
game.py
@ -105,7 +105,7 @@ def rysowaniePlanszy(obiekty):
|
||||
obiekty["plansza"][7, 11].setJestPrzeszkoda(True)
|
||||
obiekty["sprajty"].draw(obiekty["obraz"])
|
||||
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"],
|
||||
(1020, 240))
|
||||
obiekty["obraz"].blit(text_metal, (1020, 280))
|
||||
@ -190,7 +190,8 @@ def utworzObiekty():
|
||||
dom.setImage(pygame.image.load(random.choice(doms_array)))
|
||||
plansza[wspolrzedne_domow[i][0],
|
||||
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)
|
||||
all_sprites_list.add(dom)
|
||||
|
||||
@ -249,10 +250,14 @@ def liczSmieci(domy, obiekty):
|
||||
elif "trash" in s:
|
||||
ile_pozostalych += 1
|
||||
|
||||
text_metal = obiekty["font"].render("Metal: " + str(ile_metalu), True, WHITE)
|
||||
text_papier = obiekty["font"].render("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_metal = obiekty["font"].render(
|
||||
"Metal: " + str(ile_metalu), True, WHITE)
|
||||
text_papier = obiekty["font"].render(
|
||||
"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(
|
||||
"Pozostałe: " + str(ile_pozostalych), True, WHITE)
|
||||
text_odwiedzone_domy = obiekty["font"].render(
|
||||
|
15
modele.py
15
modele.py
@ -57,7 +57,8 @@ class Smieciarka(pygame.sprite.Sprite):
|
||||
self.w_dol()
|
||||
|
||||
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)
|
||||
if 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].jestDomem is True:
|
||||
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()
|
||||
if self.ruch == 2:
|
||||
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].jestDomem is True:
|
||||
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()
|
||||
if self.ruch == 1:
|
||||
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].jestDomem is True:
|
||||
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.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].jestDomem is True:
|
||||
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.plansza[self.x, self.y + 1].setKolor(BLUE)
|
||||
|
Loading…
Reference in New Issue
Block a user