diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a180c67..6864bd5 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,7 +3,6 @@
-
@@ -114,6 +113,7 @@
+
@@ -125,38 +125,38 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -174,6 +174,6 @@
-
+
\ No newline at end of file
diff --git a/__pycache__/definitions.cpython-37.pyc b/__pycache__/definitions.cpython-37.pyc
index aae9f00..ba1ba5c 100644
Binary files a/__pycache__/definitions.cpython-37.pyc and b/__pycache__/definitions.cpython-37.pyc differ
diff --git a/__pycache__/graph.cpython-37.pyc b/__pycache__/graph.cpython-37.pyc
index 66a7a5e..699e781 100644
Binary files a/__pycache__/graph.cpython-37.pyc and b/__pycache__/graph.cpython-37.pyc differ
diff --git a/__pycache__/plant.cpython-37.pyc b/__pycache__/plant.cpython-37.pyc
index 238da7a..7b39b42 100644
Binary files a/__pycache__/plant.cpython-37.pyc and b/__pycache__/plant.cpython-37.pyc differ
diff --git a/__pycache__/tractor.cpython-37.pyc b/__pycache__/tractor.cpython-37.pyc
index 8b78c04..2456a6c 100644
Binary files a/__pycache__/tractor.cpython-37.pyc and b/__pycache__/tractor.cpython-37.pyc differ
diff --git a/plant.py b/plant.py
index afa337b..93d7450 100644
--- a/plant.py
+++ b/plant.py
@@ -11,34 +11,34 @@ class Plant:
return self.state
def set_state(self, state):
self.state = state
- # @staticmethod
- # def get_closest_mature_plant(map1, tractor1):
- # x = -1
- # y = -1
- # min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
- # for i in range(definitions.WIDTH_AMOUNT):
- # for j in range(definitions.HEIGHT_AMOUNT):
- # field = map1.get_fields()[i][j]
- # if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
- # x = i
- # y = j
- # min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
- # elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
- # x = i
- # y = j
- # min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
- # elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
- # x = i
- # y = j
- # min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
- # elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
- # x = i
- # y = j
- # min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
- # if x == -1 and y == -1:
- # return False
- # else:
- # return x, y
+ @staticmethod
+ def get_closest_mature_plant(map1, tractor1):
+ x = -1
+ y = -1
+ min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
+ for i in range(definitions.WIDTH_AMOUNT):
+ for j in range(definitions.HEIGHT_AMOUNT):
+ field = map1.get_fields()[i][j]
+ if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
+ x = i
+ y = j
+ min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
+ elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
+ x = i
+ y = j
+ min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
+ elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
+ x = i
+ y = j
+ min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
+ elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE: #and abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) < min:
+ x = i
+ y = j
+ min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
+ if x == -1 and y == -1:
+ return False
+ else:
+ return x, y
@staticmethod
def grow_plants(map1): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
for i in range(definitions.WIDTH_AMOUNT):
diff --git a/py.py b/py.py
index d58c500..bd43cdd 100644
--- a/py.py
+++ b/py.py
@@ -16,7 +16,7 @@ def main():
collected_plants_dict = {"beetroot": 0, "carrot": 0, "potato": 0, "wheat": 0}
fertilizer_dict = {"beetroot": definitions.TRACTOR_FERTILIZER, "carrot": definitions.TRACTOR_FERTILIZER, "potato": definitions.TRACTOR_FERTILIZER, "wheat": definitions.TRACTOR_FERTILIZER}
station1 = station.Station(collected_plants_dict)
- tractor1 = tractor.Tractor(amount_of_seeds_dict, collected_plants_dict, definitions.TRACTOR_DIRECTION_NORTH, fertilizer_dict, definitions.TRACTOR_FUEL, definitions.TRACTOR_WATER_LEVEL, 0, 0)
+ tractor1 = tractor.Tractor(amount_of_seeds_dict, collected_plants_dict, definitions.TRACTOR_DIRECTION_SOUTH, fertilizer_dict, definitions.TRACTOR_FUEL, definitions.TRACTOR_WATER_LEVEL, 0, 0)
tractor1_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock()
run = True
@@ -27,8 +27,12 @@ def main():
run = False
map1.draw_window(tractor1, tractor1_rect)
if not move_list:
- istate = graph.Istate(tractor1.get_direction(), 0, 0)
- move_list = (graph.graphsearch([], [], istate, graph.succ, (4, 4)))
+ istate = graph.Istate(tractor1.get_direction(), tractor1.get_x() / definitions.BLOCK_SIZE, tractor1.get_y() / definitions.BLOCK_SIZE)
+ r1 = random.randint(1, 9)
+ r2 = random.randint(1, 9)
+ print(r1)
+ print(r2)
+ move_list = (graph.graphsearch([], [], istate, graph.succ, (r1, r2)))
print(move_list)
elif move_list:
temp = move_list.pop(0)
diff --git a/tractor.py b/tractor.py
index 08173c5..ac4f8ac 100644
--- a/tractor.py
+++ b/tractor.py
@@ -174,13 +174,13 @@ class Tractor:
return False
@staticmethod
def is_move_allowed_succ(node): #sprawdza czy dany ruch, który chce wykonać traktor jest możliwy, zwraca pozycje po wykonaniu ruchu, wersja node
- if node.get_direction() == definitions.TRACTOR_DIRECTION_EAST and node.get_x() + definitions.BLOCK_SIZE < definitions.WIDTH:
+ if node.get_direction() == definitions.TRACTOR_DIRECTION_EAST and node.get_x() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.WIDTH:
return "x + 1"
- elif node.get_direction() == definitions.TRACTOR_DIRECTION_NORTH and node.get_y() - definitions.BLOCK_SIZE >= 0:
+ elif node.get_direction() == definitions.TRACTOR_DIRECTION_NORTH and node.get_y() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE >= 0:
return "y - 1"
- elif node.get_direction() == definitions.TRACTOR_DIRECTION_SOUTH and node.get_y() + definitions.BLOCK_SIZE < definitions.HEIGHT:
+ elif node.get_direction() == definitions.TRACTOR_DIRECTION_SOUTH and node.get_y() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.HEIGHT:
return "y + 1"
- elif node.get_direction() == definitions.TRACTOR_DIRECTION_WEST and node.get_x() - definitions.BLOCK_SIZE >= 0:
+ elif node.get_direction() == definitions.TRACTOR_DIRECTION_WEST and node.get_x() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE >= 0:
return "x - 1"
else:
return False