działający graph search i zbierający plony traktor
This commit is contained in:
parent
97a210167c
commit
06e30867c3
@ -5,7 +5,6 @@
|
|||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -114,6 +113,7 @@
|
|||||||
<workItem from="1618049213609" duration="5378000" />
|
<workItem from="1618049213609" duration="5378000" />
|
||||||
<workItem from="1618060647009" duration="10450000" />
|
<workItem from="1618060647009" duration="10450000" />
|
||||||
<workItem from="1618073000111" duration="1948000" />
|
<workItem from="1618073000111" duration="1948000" />
|
||||||
|
<workItem from="1618075018240" duration="1221000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
@ -125,22 +125,22 @@
|
|||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617994393023" />
|
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617994393023" />
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.bottom" timestamp="1618074966357">
|
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1618076242344">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618076242344" />
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1618074966357">
|
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1618076242344">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618076242344" />
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1618074966357">
|
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1618076242344">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618076242344" />
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1618074966357">
|
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1618076242344">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1879" height="364" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618076242344" />
|
||||||
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1618074966357">
|
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1618074966357">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
@ -157,10 +157,10 @@
|
|||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
|
||||||
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1618060648138">
|
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1618075018440">
|
||||||
<screen x="0" y="0" width="1920" height="1080" />
|
<screen x="0" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1618060648138" />
|
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1618075018440" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
@ -174,6 +174,6 @@
|
|||||||
</breakpoint-manager>
|
</breakpoint-manager>
|
||||||
</component>
|
</component>
|
||||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||||
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1618074916801" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1618076215552" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
Binary file not shown.
Binary file not shown.
16
plant.py
16
plant.py
@ -12,7 +12,21 @@ class Plant:
|
|||||||
def set_state(self, state):
|
def set_state(self, state):
|
||||||
self.state = state
|
self.state = state
|
||||||
@staticmethod
|
@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
|
x = -1
|
||||||
y = -1
|
y = -1
|
||||||
min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
|
min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
|
||||||
|
26
py.py
26
py.py
@ -3,7 +3,6 @@ import graph
|
|||||||
import map
|
import map
|
||||||
import plant
|
import plant
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
|
||||||
import station
|
import station
|
||||||
import tractor
|
import tractor
|
||||||
pygame.display.set_caption("Smart Tractor")
|
pygame.display.set_caption("Smart Tractor")
|
||||||
@ -16,7 +15,7 @@ def main():
|
|||||||
collected_plants_dict = {"beetroot": 0, "carrot": 0, "potato": 0, "wheat": 0}
|
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}
|
fertilizer_dict = {"beetroot": definitions.TRACTOR_FERTILIZER, "carrot": definitions.TRACTOR_FERTILIZER, "potato": definitions.TRACTOR_FERTILIZER, "wheat": definitions.TRACTOR_FERTILIZER}
|
||||||
station1 = station.Station(collected_plants_dict)
|
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)
|
tractor1_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
run = True
|
run = True
|
||||||
@ -26,22 +25,15 @@ def main():
|
|||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
run = False
|
run = False
|
||||||
map1.draw_window(tractor1, tractor1_rect)
|
map1.draw_window(tractor1, tractor1_rect)
|
||||||
if not move_list:
|
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)
|
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)
|
||||||
r1 = random.randint(1, 9)
|
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ć
|
||||||
r2 = random.randint(1, 9)
|
elif move_list: #jeżeli move_list nie jest pusta
|
||||||
print(r1)
|
tractor1.handle_movement(move_list.pop(0), tractor1_rect) #wykonaj kolejny ruch oraz zdejmij ten ruch z początku listy
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
tractor1.handle_random_movement(tractor1_rect)
|
tractor1.handle_random_movement(tractor1_rect) #wykonuj losowe ruchy
|
||||||
tractor1.do_work(map1, station1, tractor1_rect)
|
tractor1.do_work(map1, station1, tractor1_rect) #wykonaj pracę na danym polu
|
||||||
plant.Plant.grow_plants(map1)
|
plant.Plant.grow_plants(map1) #zwiększ poziom dojrzałości roślin
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user