fixes
This commit is contained in:
parent
ca3df94bce
commit
476944a6df
@ -2,7 +2,7 @@
|
|||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
21
field.py
21
field.py
@ -72,7 +72,6 @@ def draw_interface():
|
|||||||
startpoint = (0, 0)
|
startpoint = (0, 0)
|
||||||
endpoint = startpoint
|
endpoint = startpoint
|
||||||
|
|
||||||
|
|
||||||
fl_running = True
|
fl_running = True
|
||||||
while fl_running:
|
while fl_running:
|
||||||
draw_grid()
|
draw_grid()
|
||||||
@ -98,9 +97,8 @@ def draw_interface():
|
|||||||
if (tractor.x, tractor.y) == SPAWN_POINT:
|
if (tractor.x, tractor.y) == SPAWN_POINT:
|
||||||
tractor.water = WATER_TANK_CAPACITY
|
tractor.water = WATER_TANK_CAPACITY
|
||||||
tractor.gas = GAS_TANK_CAPACITY
|
tractor.gas = GAS_TANK_CAPACITY
|
||||||
elif event.type == pygame.MOUSEWHEEL:
|
|
||||||
print(1)
|
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
startpoint = (tractor.x, tractor.y)
|
||||||
endpoint = get_click_mouse_pos()
|
endpoint = get_click_mouse_pos()
|
||||||
print(endpoint)
|
print(endpoint)
|
||||||
a = graph1.dijkstra(startpoint, endpoint)
|
a = graph1.dijkstra(startpoint, endpoint)
|
||||||
@ -208,9 +206,11 @@ class Grid:
|
|||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
def get_next_nodes(self, x, y):
|
def get_next_nodes(self, x, y):
|
||||||
check_next_node = lambda x, y: True if 0 <= x < BOARD_SIZE and 0 <= y < BOARD_SIZE and (self.grid[x][y] != types.ROCK) else False
|
check_next_node = lambda x, y: True if 0 <= x < BOARD_SIZE and 0 <= y < BOARD_SIZE and (
|
||||||
|
self.grid[x][y] != types.ROCK) else False
|
||||||
ways = [-1, 0], [1, 0], [0, -1], [0, 1]
|
ways = [-1, 0], [1, 0], [0, -1], [0, 1]
|
||||||
return [(1 if self.grid[x][y] != types.ROCK else 5, (x + dx, y + dy)) for dx, dy in ways if check_next_node(x + dx, y + dy)]
|
return [(1 if self.grid[x][y] != types.ROCK else 5, (x + dx, y + dy)) for dx, dy in ways if
|
||||||
|
check_next_node(x + dx, y + dy)]
|
||||||
|
|
||||||
|
|
||||||
class Graph:
|
class Graph:
|
||||||
@ -221,9 +221,9 @@ class Graph:
|
|||||||
def initialize_graph(self, grid: Grid):
|
def initialize_graph(self, grid: Grid):
|
||||||
for y, row in enumerate(grid.grid):
|
for y, row in enumerate(grid.grid):
|
||||||
for x, col in enumerate(row):
|
for x, col in enumerate(row):
|
||||||
if col != types.ROCK:
|
|
||||||
self.graph[(x, y)] = self.graph.get((x, y), []) + grid.get_next_nodes(x, y)
|
self.graph[(x, y)] = self.graph.get((x, y), []) + grid.get_next_nodes(x, y)
|
||||||
|
|
||||||
|
|
||||||
def dijkstra(self, start, goal):
|
def dijkstra(self, start, goal):
|
||||||
# not finished yet https://www.youtube.com/watch?v=abHftC1GU6w
|
# not finished yet https://www.youtube.com/watch?v=abHftC1GU6w
|
||||||
queue = []
|
queue = []
|
||||||
@ -249,6 +249,7 @@ class Graph:
|
|||||||
# print(visited)
|
# print(visited)
|
||||||
return visited
|
return visited
|
||||||
|
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
def __init__(self, x, y, direction: Direction):
|
def __init__(self, x, y, direction: Direction):
|
||||||
self.x = x
|
self.x = x
|
||||||
@ -289,6 +290,7 @@ class Tractor:
|
|||||||
def movement(traktor: Tractor, grid: Grid, road):
|
def movement(traktor: Tractor, grid: Grid, road):
|
||||||
n = len(road)
|
n = len(road)
|
||||||
for i in range(n - 1):
|
for i in range(n - 1):
|
||||||
|
time.sleep(0.3)
|
||||||
if road[i][0] != road[i + 1][0]:
|
if road[i][0] != road[i + 1][0]:
|
||||||
if road[i][0] > road[i + 1][0]:
|
if road[i][0] > road[i + 1][0]:
|
||||||
if traktor.direction != 3:
|
if traktor.direction != 3:
|
||||||
@ -316,6 +318,7 @@ def movement(traktor:Tractor, grid:Grid, road):
|
|||||||
traktor.move(grid=grid)
|
traktor.move(grid=grid)
|
||||||
print("move down")
|
print("move down")
|
||||||
|
|
||||||
|
|
||||||
def getRoad(start, goal, visited):
|
def getRoad(start, goal, visited):
|
||||||
arr = []
|
arr = []
|
||||||
aFrom = goal
|
aFrom = goal
|
||||||
@ -336,9 +339,3 @@ def getRoad(start, goal, visited):
|
|||||||
# a = graph1.dijkstra(startpoint, endpoint)
|
# a = graph1.dijkstra(startpoint, endpoint)
|
||||||
# b = getRoad(startpoint, endpoint, a)
|
# b = getRoad(startpoint, endpoint, a)
|
||||||
# print(b)
|
# print(b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user