Route_planning_bfs #2
Binary file not shown.
@ -42,20 +42,30 @@ def drawWindow(win):
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
def update_tiles(win, tractor):
|
||||
tiles = createTiles()
|
||||
for tile in tiles:
|
||||
if tile.x == tractor.previous_x and tile.y == tractor.previous_y:
|
||||
tile.x = tractor.x
|
||||
tile.y = tractor.y
|
||||
#experimental:
|
||||
# def update_tiles(win, tractor):
|
||||
# tiles = createTiles()
|
||||
# for tile in tiles:
|
||||
# if tile.x == tractor.previous_x and tile.y == tractor.previous_y:
|
||||
# tile.x = tractor.x
|
||||
# tile.y = tractor.y
|
||||
|
||||
if tile.image is not None:
|
||||
new_tile = Tile(tile.x, tile.y)
|
||||
new_tile.image = tile.image
|
||||
# if tile.image is not None:
|
||||
# new_tile = Tile(tile.x, tile.y)
|
||||
# new_tile.image = tile.image
|
||||
|
||||
|
||||
tiles.append(new_tile)
|
||||
# tiles.append(new_tile)
|
||||
|
||||
image = pygame.image.load(tile.image).convert()
|
||||
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
||||
win.blit(image, (tile.x + fieldX-1, tile.y + fieldY-1))
|
||||
# image = pygame.image.load(tile.image).convert()
|
||||
# image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
||||
# win.blit(image, (tile.x + fieldX-1, tile.y + fieldY-1))
|
||||
|
||||
|
||||
|
||||
def get_tile_coordinates(index):
|
||||
if index < len(tiles):
|
||||
tile = tiles[index]
|
||||
return tile.x, tile.y
|
||||
else:
|
||||
return None
|
@ -6,9 +6,10 @@ from area.constants import WIDTH, HEIGHT, TILE_SIZE, GREY
|
||||
from area.field import drawWindow
|
||||
from area.tractor import Tractor
|
||||
from area.field import tiles, fieldX, fieldY
|
||||
from area.field import update_tiles
|
||||
from area.field import get_tile_coordinates
|
||||
from ground import Dirt
|
||||
from plant import Plant
|
||||
from bfs import graphsearch, Istate, succ
|
||||
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
pygame.display.set_caption('Intelligent tractor')
|
||||
|
||||
@ -19,13 +20,27 @@ def main():
|
||||
window = drawWindow(WIN)
|
||||
pygame.display.update()
|
||||
|
||||
#getting coordinates of a certain tile - test:
|
||||
tile_index=2
|
||||
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})")
|
||||
else: print("Such tile does not exist")
|
||||
|
||||
istate = Istate(170, 100, 2)
|
||||
goaltest = []
|
||||
goaltest.append(tile_x)
|
||||
goaltest.append(tile_y)
|
||||
|
||||
print(graphsearch(istate, succ, goaltest))
|
||||
|
||||
#main loop:
|
||||
while run:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
#small test:
|
||||
#small test of work_on_field method:
|
||||
time.sleep(1)
|
||||
tile1 = tiles[0]
|
||||
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
|
||||
|
Loading…
Reference in New Issue
Block a user