naprawiony błąd cofania

This commit is contained in:
Tomasz Adamczyk 2021-04-10 19:16:34 +02:00
parent 2836a0771d
commit 97a210167c
8 changed files with 57 additions and 53 deletions

View File

@ -3,7 +3,6 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment=""> <list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<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$/graph.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph.py" 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" /> <change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" />
@ -114,6 +113,7 @@
<workItem from="1618045709925" duration="3464000" /> <workItem from="1618045709925" duration="3464000" />
<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" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -125,38 +125,38 @@
<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="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.0.bottom" timestamp="1618074966357">
<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="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1618074966357">
<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="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1618074966357">
<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="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1618074966357">
<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="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1618071825769"> <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>
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1618074966357">
<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.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1618074966357">
<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.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618071825769" /> <state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618074966357" />
<state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1618071825769"> <state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1618074966357">
<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="1618071825769" /> <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="1618060648138">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
@ -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="1618071647071" 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="1618074916801" 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.

Binary file not shown.

View File

@ -11,34 +11,34 @@ class Plant:
return self.state return self.state
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 get_closest_mature_plant(map1, tractor1):
# x = -1 x = -1
# y = -1 y = -1
# min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1 min = definitions.WIDTH_AMOUNT + definitions.HEIGHT_AMOUNT + 1
# for i in range(definitions.WIDTH_AMOUNT): for i in range(definitions.WIDTH_AMOUNT):
# for j in range(definitions.HEIGHT_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT):
# field = map1.get_fields()[i][j] 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: 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 x = i
# y = j y = j
# min = abs(tractor1.get_x() - i) + abs(tractor1.get_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: 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 x = i
# y = j y = j
# min = abs(tractor1.get_x() - i) + abs(tractor1.get_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: 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 x = i
# y = j y = j
# min = abs(tractor1.get_x() - i) + abs(tractor1.get_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: 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 x = i
# y = j y = j
# min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j) min = abs(tractor1.get_x() - i) + abs(tractor1.get_y() - j)
# if x == -1 and y == -1: if x == -1 and y == -1:
# return False return False
# else: else:
# return x, y return x, y
@staticmethod @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 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): for i in range(definitions.WIDTH_AMOUNT):

10
py.py
View File

@ -16,7 +16,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_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) 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
@ -27,8 +27,12 @@ def main():
run = False run = False
map1.draw_window(tractor1, tractor1_rect) map1.draw_window(tractor1, tractor1_rect)
if not move_list: if not move_list:
istate = graph.Istate(tractor1.get_direction(), 0, 0) istate = graph.Istate(tractor1.get_direction(), tractor1.get_x() / definitions.BLOCK_SIZE, tractor1.get_y() / definitions.BLOCK_SIZE)
move_list = (graph.graphsearch([], [], istate, graph.succ, (4, 4))) 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) print(move_list)
elif move_list: elif move_list:
temp = move_list.pop(0) temp = move_list.pop(0)

View File

@ -174,13 +174,13 @@ class Tractor:
return False return False
@staticmethod @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 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" 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" 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" 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" return "x - 1"
else: else:
return False return False