demo ruch
This commit is contained in:
parent
1315b33894
commit
fb4cd44b61
@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.9 (traktor)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (traktor)" project-jdk-type="Python SDK" />
|
||||
</project>
|
49
main.py
49
main.py
@ -45,13 +45,13 @@ def graphsearch(istate, goaltest, board):
|
||||
|
||||
def main():
|
||||
rotation = ["left", "up", "right", "down"]
|
||||
istate = Stan(4,4, "down")
|
||||
initial_state = Stan(4,4, "down")
|
||||
goaltest = Stan(1,1, "up")
|
||||
run = True
|
||||
clock = pygame.time.Clock()
|
||||
board = Board()
|
||||
board.load_images()
|
||||
actions = graphsearch(istate, goaltest, board)
|
||||
actions = graphsearch(initial_state, goaltest, board)
|
||||
print("akcje: >",actions )
|
||||
tractor = Tractor(4, 4)
|
||||
while run:
|
||||
@ -61,9 +61,27 @@ def main():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
if keys[pygame.K_UP]:
|
||||
if actions:
|
||||
action = actions.pop() # Pobierz kolejną akcję z listy
|
||||
if action == "left":
|
||||
if tractor.direction == "up":
|
||||
tractor.direction = "left"
|
||||
elif tractor.direction == "down":
|
||||
tractor.direction = "right"
|
||||
elif tractor.direction == "left":
|
||||
tractor.direction = "down"
|
||||
elif tractor.direction == "right":
|
||||
tractor.direction = "up"
|
||||
elif action == "right":
|
||||
if tractor.direction == "up":
|
||||
tractor.direction = "right"
|
||||
elif tractor.direction == "down":
|
||||
tractor.direction = "left"
|
||||
elif tractor.direction == "left":
|
||||
tractor.direction = "up"
|
||||
elif tractor.direction == "right":
|
||||
tractor.direction = "down"
|
||||
elif action == "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)
|
||||
@ -73,7 +91,7 @@ def main():
|
||||
tractor.row -= 1
|
||||
elif not board.is_rock(tractor.col, tractor.row - 1):
|
||||
tractor.row -= 1
|
||||
if(tractor.direction == "left" and tractor.col > 0):
|
||||
elif (tractor.direction == "left" and tractor.col > 0):
|
||||
if board.is_weed(tractor.col - 1, tractor.row):
|
||||
board.set_grass(tractor.col - 1, tractor.row)
|
||||
tractor.col -= 1
|
||||
@ -82,7 +100,7 @@ def main():
|
||||
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):
|
||||
elif (tractor.direction == "down" and tractor.row < rows - 1):
|
||||
if board.is_weed(tractor.col, tractor.row + 1):
|
||||
board.set_grass(tractor.col, tractor.row + 1)
|
||||
tractor.row += 1
|
||||
@ -91,7 +109,7 @@ def main():
|
||||
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):
|
||||
elif (tractor.direction == "right" and tractor.col < cols - 1):
|
||||
if board.is_weed(tractor.col + 1, tractor.row):
|
||||
board.set_grass(tractor.col + 1, tractor.row)
|
||||
tractor.col += 1
|
||||
@ -100,20 +118,7 @@ def main():
|
||||
tractor.col += 1
|
||||
elif not board.is_rock(tractor.col + 1, tractor.row):
|
||||
tractor.col += 1
|
||||
if keys[pygame.K_LEFT]:
|
||||
for i in range(0, 4):
|
||||
if(tractor.direction == rotation[i]):
|
||||
if(i == 0):
|
||||
i = 4
|
||||
tractor.direction = rotation[i-1]
|
||||
break
|
||||
if keys[pygame.K_RIGHT]:
|
||||
for i in range(0, 4):
|
||||
if(tractor.direction == rotation[i]):
|
||||
if(i == 3):
|
||||
i = -1
|
||||
tractor.direction = rotation[i+1]
|
||||
break
|
||||
|
||||
|
||||
board.draw_cubes(WIN)
|
||||
tractor.draw(WIN)
|
||||
|
Loading…
Reference in New Issue
Block a user