zwraca ruchy
This commit is contained in:
parent
7baf7dadb3
commit
58949ff985
@ -3,6 +3,7 @@
|
||||
<component name="ChangeListManager">
|
||||
<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$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
|
||||
</list>
|
||||
@ -109,6 +110,8 @@
|
||||
<workItem from="1617992640419" duration="8178000" />
|
||||
<workItem from="1618001458885" duration="787000" />
|
||||
<workItem from="1618042095757" duration="3541000" />
|
||||
<workItem from="1618045709925" duration="3464000" />
|
||||
<workItem from="1618049213609" duration="5378000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -120,38 +123,38 @@
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<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="295" key="GridCell.Tab.0.bottom" timestamp="1618045669923">
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.bottom" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669923" />
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1618045669923">
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669923" />
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1618045669923">
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669923" />
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1618045669923">
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669923" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1618045669918">
|
||||
<state width="1879" height="364" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669918" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1618045669918">
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669918" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1618045669918">
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669918" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1618045669918">
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1618054918620">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618045669918" />
|
||||
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1618054918620" />
|
||||
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1618042189818">
|
||||
<screen x="0" y="0" width="1920" height="1080" />
|
||||
</state>
|
||||
@ -159,13 +162,6 @@
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/graph.py</url>
|
||||
<line>75</line>
|
||||
<option name="timeStamp" value="7" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
<default-breakpoints>
|
||||
<breakpoint type="python-exception">
|
||||
<properties notifyOnTerminate="true" exception="BaseException">
|
||||
@ -176,6 +172,6 @@
|
||||
</breakpoint-manager>
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1618045588811" 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="1618054873527" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
@ -30,7 +30,7 @@ FARMLAND_DRY = pygame.image.load(os.path.join('resources', 'farmland_dry.png'))
|
||||
FARMLAND_DRY = pygame.transform.scale(FARMLAND_DRY, (BLOCK_SIZE, BLOCK_SIZE))
|
||||
FARMLAND_WET = pygame.image.load(os.path.join('resources', 'farmland_wet.png'))
|
||||
FARMLAND_WET = pygame.transform.scale(FARMLAND_WET, (BLOCK_SIZE, BLOCK_SIZE))
|
||||
FPS = 20
|
||||
FPS = 1
|
||||
POTATOES_GROW_TIME = 5
|
||||
POTATOES_MAXIMUM_STATE = POTATOES_GROW_TIME * 3 + 1
|
||||
POTATOES_STAGE_0 = pygame.image.load(os.path.join('resources', 'potatoes_stage_0.png'))
|
||||
|
55
graph.py
55
graph.py
@ -60,6 +60,13 @@ def goal_test(elem, goaltest):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
def print_moves(elem, explored):
|
||||
moves_list = []
|
||||
while (elem.get_parent() != None):
|
||||
moves_list.append(elem.get_action())
|
||||
elem = elem.get_parent()
|
||||
moves_list.reverse()
|
||||
return moves_list
|
||||
def succ(elem):
|
||||
actions_list = []
|
||||
temp = copy.copy(elem.get_direction())
|
||||
@ -74,14 +81,18 @@ def succ(elem):
|
||||
else:
|
||||
temp = temp + 1
|
||||
actions_list.append(("rotate_right", (temp, elem.get_x(), elem.get_y())))
|
||||
temp_move_south = elem.get_y() + 1
|
||||
temp_move_west = elem.get_x() - 1
|
||||
temp_move_east = elem.get_x() + 1
|
||||
temp_move_north = elem.get_y() - 1
|
||||
if tractor.Tractor.is_move_allowed_succ(elem) == "x + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.set_x(elem.get_x() + 1), elem.get_y())))
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_east, elem.get_y())))
|
||||
elif tractor.Tractor.is_move_allowed_succ(elem) == "y - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), elem.set_y(elem.get_y() - 1))))
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_north)))
|
||||
elif tractor.Tractor.is_move_allowed_succ(elem) == "y + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), elem.set_y(elem.get_y() + 1))))
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_south)))
|
||||
elif tractor.Tractor.is_move_allowed_succ(elem) == "x - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.set_x(elem.get_x() - 1), elem.get_y())))
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_west, elem.get_y())))
|
||||
return actions_list
|
||||
def graphsearch(fringe, explored, istate, succ, goaltest):
|
||||
node = Node(None, istate.get_direction(), None, istate.get_x(), istate.get_y()) #może None coś nie gra
|
||||
@ -94,15 +105,35 @@ def graphsearch(fringe, explored, istate, succ, goaltest):
|
||||
elem = fringe.pop(0)
|
||||
temp = copy.copy(elem) #żeby explored w for succ() nie zmieniało
|
||||
if goal_test(elem, goaltest) is True:
|
||||
return explored
|
||||
# for x in fringe:
|
||||
# print("action: " + str(x.get_action()))
|
||||
# print("direction: " + str(x.get_direction()))
|
||||
# print("parent: " + str(x.get_parent()))
|
||||
# print("node: " + str(x))
|
||||
# print("x: " + str(x.get_x()))
|
||||
# print("y: " + str(x.get_y()))
|
||||
# for x in explored:
|
||||
# print("action ex: " + str(x.get_action()))
|
||||
# print("direction ex: " + str(x.get_direction()))
|
||||
# print("parent ex: " + str(x.get_parent()))
|
||||
# print("node ex: " + str(x))
|
||||
# print("x ex: " + str(x.get_x()))
|
||||
# print("y ex: " + str(x.get_y()))
|
||||
return print_moves(elem, explored)
|
||||
explored.append(elem)
|
||||
for (action, state) in succ(temp):
|
||||
if state not in fringe and state not in explored:
|
||||
fringe_tuple = []
|
||||
explored_tuple = []
|
||||
for x in fringe:
|
||||
fringe_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
for x in explored:
|
||||
explored_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
if state not in fringe_tuple and state not in explored_tuple:
|
||||
x = Node(action, state[0], elem, state[1], state[2])
|
||||
print(state[0])
|
||||
print(state[1])
|
||||
print(state[2])
|
||||
print(x.get_action())
|
||||
#print(x.get_direction())
|
||||
#print(x.get_parent())
|
||||
# print(x.get_action())
|
||||
# print(state[0])
|
||||
# print(state[1])
|
||||
# print(state[2])
|
||||
# print(x.get_direction())
|
||||
# print(x.get_parent())
|
||||
fringe.append(x)
|
6
py.py
6
py.py
@ -14,7 +14,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_EAST, 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
|
||||
@ -23,8 +23,8 @@ def main():
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
istate = graph.Istate(definitions.TRACTOR_DIRECTION_EAST, 0, 0)
|
||||
istate1 = graph.Istate(None, 4, 4)
|
||||
istate = graph.Istate(definitions.TRACTOR_DIRECTION_SOUTH, 0, 0)
|
||||
istate1 = graph.Istate(None, 4, 6)
|
||||
print(graph.graphsearch([], [], istate, graph.succ, istate1))
|
||||
map1.draw_window(tractor1, tractor1_rect)
|
||||
tractor1.tractor1_handle_movement(tractor1_rect)
|
||||
|
Loading…
Reference in New Issue
Block a user