diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6864bd5..e52488c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,6 @@
-
@@ -114,6 +113,7 @@
+
@@ -125,22 +125,22 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -157,10 +157,10 @@
-
+
-
+
@@ -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 ba1ba5c..2c79fe9 100644
Binary files a/__pycache__/definitions.cpython-37.pyc and b/__pycache__/definitions.cpython-37.pyc differ
diff --git a/__pycache__/plant.cpython-37.pyc b/__pycache__/plant.cpython-37.pyc
index 7b39b42..fc68bd3 100644
Binary files a/__pycache__/plant.cpython-37.pyc and b/__pycache__/plant.cpython-37.pyc differ
diff --git a/plant.py b/plant.py
index 93d7450..dca31b2 100644
--- a/plant.py
+++ b/plant.py
@@ -12,7 +12,21 @@ class Plant:
def set_state(self, state):
self.state = state
@staticmethod
- def get_closest_mature_plant(map1, tractor1):
+ def if_any_mature_plant(map1): #sprawdza czy na polu występuje choć jedna dojrzała roślina, jeśli tak zwraca prawdę, w przeciwnym razie zwraca fałsz
+ 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:
+ return True
+ elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
+ return True
+ elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
+ return True
+ elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
+ return True
+ return False
+ @staticmethod
+ def get_closest_mature_plant(map1, tractor1): #TO DO, pobiera współrzędne najbliższej dojrzałej rośliny od miejsca, w którym znajduje się traktor
x = -1
y = -1
min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
diff --git a/py.py b/py.py
index bd43cdd..7c5450a 100644
--- a/py.py
+++ b/py.py
@@ -3,7 +3,6 @@ import graph
import map
import plant
import pygame
-import random
import station
import tractor
pygame.display.set_caption("Smart Tractor")
@@ -16,7 +15,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_SOUTH, fertilizer_dict, definitions.TRACTOR_FUEL, definitions.TRACTOR_WATER_LEVEL, 0, 0)
+ 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_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock()
run = True
@@ -26,22 +25,15 @@ def main():
if event.type == pygame.QUIT:
run = False
map1.draw_window(tractor1, tractor1_rect)
- if not move_list:
- 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)
- print(temp)
- tractor1.handle_movement(temp, tractor1_rect)
+ if not move_list and plant.Plant.if_any_mature_plant(map1) is True: #jeżeli są jakieś ruchy do wykonania w move_list oraz istnieje jakaś dojrzała roślina
+ istate = graph.Istate(tractor1.get_direction(), tractor1.get_x() / definitions.BLOCK_SIZE, tractor1.get_y() / definitions.BLOCK_SIZE) #stan początkowy traktora (jego orientacja oraz jego aktualne współrzędne)
+ move_list = (graph.graphsearch([], [], istate, graph.succ, plant.Plant.get_closest_mature_plant(map1, tractor1))) #lista z ruchami, które należy po kolei wykonać
+ elif move_list: #jeżeli move_list nie jest pusta
+ tractor1.handle_movement(move_list.pop(0), tractor1_rect) #wykonaj kolejny ruch oraz zdejmij ten ruch z początku listy
else:
- tractor1.handle_random_movement(tractor1_rect)
- tractor1.do_work(map1, station1, tractor1_rect)
- plant.Plant.grow_plants(map1)
+ tractor1.handle_random_movement(tractor1_rect) #wykonuj losowe ruchy
+ tractor1.do_work(map1, station1, tractor1_rect) #wykonaj pracę na danym polu
+ plant.Plant.grow_plants(map1) #zwiększ poziom dojrzałości roślin
pygame.quit()
if __name__ == "__main__":
main()
\ No newline at end of file