test of the bfs route-planning
This commit is contained in:
parent
ffc699494a
commit
3b0c388a1e
Binary file not shown.
@ -42,20 +42,30 @@ def drawWindow(win):
|
|||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
|
||||||
def update_tiles(win, tractor):
|
#experimental:
|
||||||
tiles = createTiles()
|
# def update_tiles(win, tractor):
|
||||||
for tile in tiles:
|
# tiles = createTiles()
|
||||||
if tile.x == tractor.previous_x and tile.y == tractor.previous_y:
|
# for tile in tiles:
|
||||||
tile.x = tractor.x
|
# if tile.x == tractor.previous_x and tile.y == tractor.previous_y:
|
||||||
tile.y = tractor.y
|
# tile.x = tractor.x
|
||||||
|
# tile.y = tractor.y
|
||||||
|
|
||||||
if tile.image is not None:
|
# if tile.image is not None:
|
||||||
new_tile = Tile(tile.x, tile.y)
|
# new_tile = Tile(tile.x, tile.y)
|
||||||
new_tile.image = tile.image
|
# new_tile.image = tile.image
|
||||||
|
|
||||||
|
|
||||||
tiles.append(new_tile)
|
# tiles.append(new_tile)
|
||||||
|
|
||||||
image = pygame.image.load(tile.image).convert()
|
# image = pygame.image.load(tile.image).convert()
|
||||||
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
# image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
||||||
win.blit(image, (tile.x + fieldX-1, tile.y + fieldY-1))
|
# 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.field import drawWindow
|
||||||
from area.tractor import Tractor
|
from area.tractor import Tractor
|
||||||
from area.field import tiles, fieldX, fieldY
|
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 ground import Dirt
|
||||||
from plant import Plant
|
from plant import Plant
|
||||||
|
from bfs import graphsearch, Istate, succ
|
||||||
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
|
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
pygame.display.set_caption('Intelligent tractor')
|
pygame.display.set_caption('Intelligent tractor')
|
||||||
|
|
||||||
@ -19,13 +20,27 @@ def main():
|
|||||||
window = drawWindow(WIN)
|
window = drawWindow(WIN)
|
||||||
pygame.display.update()
|
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:
|
while run:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
run = False
|
run = False
|
||||||
|
|
||||||
#small test:
|
#small test of work_on_field method:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
tile1 = tiles[0]
|
tile1 = tiles[0]
|
||||||
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
|
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
|
||||||
|
Loading…
Reference in New Issue
Block a user