add carrot
This commit is contained in:
parent
8cdf6d8118
commit
9eb5029b38
BIN
board/carrot.png
Normal file
BIN
board/carrot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 232 KiB |
22
main.py
22
main.py
@ -5,8 +5,6 @@ from tractor import Tractor
|
|||||||
from kolejka import Stan, Kolejka, Odwiedzone
|
from kolejka import Stan, Kolejka, Odwiedzone
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fps = 5
|
fps = 5
|
||||||
WIN = pygame.display.set_mode((width, height))
|
WIN = pygame.display.set_mode((width, height))
|
||||||
|
|
||||||
@ -24,8 +22,8 @@ def actions(elem, istate):
|
|||||||
while((elem.row != istate.row) or (elem.col != istate.col) or (elem.direction != istate.direction)):
|
while((elem.row != istate.row) or (elem.col != istate.col) or (elem.direction != istate.direction)):
|
||||||
akcje.append(elem.a)
|
akcje.append(elem.a)
|
||||||
elem = elem.p[0]
|
elem = elem.p[0]
|
||||||
|
|
||||||
return akcje
|
return akcje
|
||||||
|
|
||||||
def graphsearch(istate, goaltest, board):
|
def graphsearch(istate, goaltest, board):
|
||||||
explored = Odwiedzone()
|
explored = Odwiedzone()
|
||||||
fringe = Kolejka()
|
fringe = Kolejka()
|
||||||
@ -46,14 +44,14 @@ def graphsearch(istate, goaltest, board):
|
|||||||
def main():
|
def main():
|
||||||
rotation = ["left", "up", "right", "down"]
|
rotation = ["left", "up", "right", "down"]
|
||||||
istate = Stan(4,4, "down")
|
istate = Stan(4,4, "down")
|
||||||
goaltest = Stan(1,1, "up")
|
goaltest = Stan(2,3, "up")
|
||||||
run = True
|
run = True
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
board = Board()
|
board = Board()
|
||||||
board.load_images()
|
board.load_images()
|
||||||
actions = graphsearch(istate, goaltest, board)
|
actions = graphsearch(istate, goaltest, board)
|
||||||
print("akcje: >",actions )
|
print("akcje: >",actions )
|
||||||
tractor = Tractor(4, 4)
|
tractor = Tractor(2, 3)
|
||||||
while run:
|
while run:
|
||||||
clock.tick(fps)
|
clock.tick(fps)
|
||||||
|
|
||||||
@ -63,6 +61,7 @@ def main():
|
|||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
if keys[pygame.K_UP]:
|
||||||
if keys[pygame.K_UP]:
|
if keys[pygame.K_UP]:
|
||||||
if(tractor.direction == "up" and tractor.row > 0 ):
|
if(tractor.direction == "up" and tractor.row > 0 ):
|
||||||
if board.is_weed(tractor.col, tractor.row - 1):
|
if board.is_weed(tractor.col, tractor.row - 1):
|
||||||
@ -71,8 +70,12 @@ def main():
|
|||||||
elif board.is_dirt(tractor.col, tractor.row - 1):
|
elif board.is_dirt(tractor.col, tractor.row - 1):
|
||||||
board.set_soil(tractor.col, tractor.row - 1)
|
board.set_soil(tractor.col, tractor.row - 1)
|
||||||
tractor.row -= 1
|
tractor.row -= 1
|
||||||
|
elif board.is_soil(tractor.col, tractor.row - 1):
|
||||||
|
board.set_carrot(tractor.col, tractor.row - 1)
|
||||||
|
tractor.row -= 1
|
||||||
elif not board.is_rock(tractor.col, tractor.row - 1):
|
elif not board.is_rock(tractor.col, tractor.row - 1):
|
||||||
tractor.row -= 1
|
tractor.row -= 1
|
||||||
|
|
||||||
if(tractor.direction == "left" and tractor.col > 0):
|
if(tractor.direction == "left" and tractor.col > 0):
|
||||||
if board.is_weed(tractor.col - 1, tractor.row):
|
if board.is_weed(tractor.col - 1, tractor.row):
|
||||||
board.set_grass(tractor.col - 1, tractor.row)
|
board.set_grass(tractor.col - 1, tractor.row)
|
||||||
@ -80,6 +83,9 @@ def main():
|
|||||||
elif board.is_dirt(tractor.col - 1, tractor.row):
|
elif board.is_dirt(tractor.col - 1, tractor.row):
|
||||||
board.set_soil(tractor.col - 1, tractor.row)
|
board.set_soil(tractor.col - 1, tractor.row)
|
||||||
tractor.col -= 1
|
tractor.col -= 1
|
||||||
|
elif board.is_soil(tractor.col - 1, tractor.row):
|
||||||
|
board.set_carrot(tractor.col - 1, tractor.row)
|
||||||
|
tractor.col -= 1
|
||||||
elif not board.is_rock(tractor.col - 1, tractor.row):
|
elif not board.is_rock(tractor.col - 1, tractor.row):
|
||||||
tractor.col -= 1
|
tractor.col -= 1
|
||||||
if(tractor.direction == "down" and tractor.row < rows - 1):
|
if(tractor.direction == "down" and tractor.row < rows - 1):
|
||||||
@ -89,6 +95,9 @@ def main():
|
|||||||
elif board.is_dirt(tractor.col, tractor.row + 1):
|
elif board.is_dirt(tractor.col, tractor.row + 1):
|
||||||
board.set_soil(tractor.col, tractor.row + 1)
|
board.set_soil(tractor.col, tractor.row + 1)
|
||||||
tractor.row += 1
|
tractor.row += 1
|
||||||
|
elif board.is_soil(tractor.col, tractor.row + 1):
|
||||||
|
board.set_carrot(tractor.col, tractor.row + 1)
|
||||||
|
tractor.row += 1
|
||||||
elif not board.is_rock(tractor.col, tractor.row + 1):
|
elif not board.is_rock(tractor.col, tractor.row + 1):
|
||||||
tractor.row += 1
|
tractor.row += 1
|
||||||
if(tractor.direction == "right" and tractor.col < cols - 1):
|
if(tractor.direction == "right" and tractor.col < cols - 1):
|
||||||
@ -98,6 +107,9 @@ def main():
|
|||||||
elif board.is_dirt(tractor.col + 1, tractor.row):
|
elif board.is_dirt(tractor.col + 1, tractor.row):
|
||||||
board.set_soil(tractor.col + 1, tractor.row)
|
board.set_soil(tractor.col + 1, tractor.row)
|
||||||
tractor.col += 1
|
tractor.col += 1
|
||||||
|
elif board.is_soil(tractor.col + 1, tractor.row ):
|
||||||
|
board.set_carrot(tractor.col + 1, tractor.row )
|
||||||
|
tractor.col += 1
|
||||||
elif not board.is_rock(tractor.col + 1, tractor.row):
|
elif not board.is_rock(tractor.col + 1, tractor.row):
|
||||||
tractor.col += 1
|
tractor.col += 1
|
||||||
if keys[pygame.K_LEFT]:
|
if keys[pygame.K_LEFT]:
|
||||||
|
Loading…
Reference in New Issue
Block a user