diff --git a/board/carrot.png b/board/carrot.png new file mode 100644 index 000000000..86c63cb33 Binary files /dev/null and b/board/carrot.png differ diff --git a/main.py b/main.py index 1925cdfcc..6b50a8b9d 100644 --- a/main.py +++ b/main.py @@ -5,8 +5,6 @@ from tractor import Tractor from kolejka import Stan, Kolejka, Odwiedzone - - fps = 5 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)): akcje.append(elem.a) elem = elem.p[0] - return akcje + def graphsearch(istate, goaltest, board): explored = Odwiedzone() fringe = Kolejka() @@ -46,14 +44,14 @@ def graphsearch(istate, goaltest, board): def main(): rotation = ["left", "up", "right", "down"] istate = Stan(4,4, "down") - goaltest = Stan(1,1, "up") + goaltest = Stan(2,3, "up") run = True clock = pygame.time.Clock() board = Board() board.load_images() actions = graphsearch(istate, goaltest, board) print("akcje: >",actions ) - tractor = Tractor(4, 4) + tractor = Tractor(2, 3) while run: clock.tick(fps) @@ -64,6 +62,7 @@ def main(): keys = pygame.key.get_pressed() if keys[pygame.K_UP]: + if keys[pygame.K_UP]: if(tractor.direction == "up" and tractor.row > 0 ): if board.is_weed(tractor.col, tractor.row - 1): board.set_grass(tractor.col, tractor.row - 1) @@ -71,8 +70,12 @@ def main(): elif board.is_dirt(tractor.col, tractor.row - 1): board.set_soil(tractor.col, 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): tractor.row -= 1 + if(tractor.direction == "left" and tractor.col > 0): if board.is_weed(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): board.set_soil(tractor.col - 1, tractor.row) 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): tractor.col -= 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): board.set_soil(tractor.col, 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): tractor.row += 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): board.set_soil(tractor.col + 1, tractor.row) 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): tractor.col += 1 if keys[pygame.K_LEFT]: