important bug fix: conditions regarding bfs

This commit is contained in:
MarRac 2024-04-14 18:59:37 +02:00
parent 8fe3d25324
commit f10a60063d
5 changed files with 7 additions and 6 deletions

View File

@ -1,5 +1,6 @@
from crop_protection_product import CropProtectionProduct
from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH, FIELD_WIDTH, FIELD_HEIGHT, WIDTH, HEIGHT
from area.field import fieldX, fieldY
import pygame
import time
@ -108,13 +109,13 @@ class Tractor:
#sprawdza czy mozna sie dalej poruszyc, czy nie wyjdziemy poza mape - do funkcji succ w bfs
def can_it_move_node(node):
if node.get_direction() == DIRECTION_EAST and node.get_x() + TILE_SIZE < FIELD_WIDTH:
if node.get_direction() == DIRECTION_EAST and node.get_x() + TILE_SIZE < 830: #last tile on the west has y:797
return "move east"
elif node.get_direction() == DIRECTION_WEST and node.get_x() - TILE_SIZE >=0:
elif node.get_direction() == DIRECTION_WEST and node.get_x() - TILE_SIZE >=fieldX:
return "move west"
elif node.get_direction() == DIRECTION_NORTH and node.get_y() - TILE_SIZE >=0:
elif node.get_direction() == DIRECTION_NORTH and node.get_y() - TILE_SIZE >=fieldY:
return "move north"
elif node.get_direction() == DIRECTION_SOUTH and node.get_y() + TILE_SIZE < FIELD_HEIGHT:
elif node.get_direction() == DIRECTION_SOUTH and node.get_y() + TILE_SIZE < 760: #last tile on the south has y:727
return "move south"
else:
return False

View File

@ -20,7 +20,7 @@ def main():
pygame.display.update()
#getting coordinates of a certain tile - test:
tile_index=30
tile_index=399
tile_x, tile_y = get_tile_coordinates(tile_index)
if tile_x is not None and tile_y is not None:
print(f"Coordinates of tile {tile_index} are: ({tile_x}, {tile_y})")
@ -54,7 +54,7 @@ def main():
tractor.rect.y += fieldY
tractor.draw_tractor(WIN)
time.sleep(1)
if moves != None:
if moves != False:
do_actions(tractor, WIN, moves)
tractor.work_on_field(tile1, d1, p1)