forked from s444420/AL-2020
naprawa poruszania
This commit is contained in:
parent
e832b64f00
commit
563b638f0a
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,7 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="" />
|
||||
<list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/functions.py" beforeDir="false" afterPath="$PROJECT_DIR$/functions.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -15,9 +20,14 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectId" id="1blUxWbA3VMjMFjk8gUnLGMgAoU" />
|
||||
<component name="PropertiesComponent">
|
||||
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="restartRequiresConfirmation" value="false" />
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
@ -98,14 +108,27 @@
|
||||
<workItem from="1589233530634" duration="769000" />
|
||||
<workItem from="1589543001064" duration="78000" />
|
||||
<workItem from="1589543305930" duration="10474000" />
|
||||
<workItem from="1589561555146" duration="3374000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/wozek$board.coverage" NAME="board Coverage Results" MODIFIED="1589210811600" 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/AL_2020$main.coverage" NAME="main Coverage Results" MODIFIED="1589564478428" 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/wozek$main.coverage" NAME="main Coverage Results" MODIFIED="1589556038208" 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.
15
functions.py
15
functions.py
@ -67,6 +67,7 @@ def a_star(start_field, goal_field, board):
|
||||
field.g = 0
|
||||
field.h = 0
|
||||
field.f = 0
|
||||
field.previous = None
|
||||
|
||||
return path
|
||||
|
||||
@ -133,4 +134,16 @@ def change_turn(agent, next_field):
|
||||
agent.turn_right()
|
||||
|
||||
|
||||
|
||||
# def execute_step(agent, next_step, board, path):
|
||||
# if check_turn(agent, next_step):
|
||||
# agent.move_forward(board)
|
||||
# if len(path) != 0:
|
||||
# next_step = path.pop()
|
||||
# else:
|
||||
# next_step = None
|
||||
# for row in board:
|
||||
# for field in row:
|
||||
# if not field.is_shelf:
|
||||
# field.image = pygame.image.load('img/Field.png')
|
||||
# else:
|
||||
# change_turn(agent, next_step)
|
||||
|
30
main.py
30
main.py
@ -6,6 +6,7 @@ import time
|
||||
from agent import Agent
|
||||
from settings import Settings
|
||||
from board import create_board, draw_board
|
||||
from random import randint
|
||||
|
||||
|
||||
# Inicjalizacja programu i utworzenie obiektu ekrany
|
||||
@ -21,9 +22,8 @@ def run():
|
||||
for field in row:
|
||||
print(field.cost_of_travel)
|
||||
|
||||
path = functions.a_star(board[agent.y][agent.x], board[5][7], board)
|
||||
path.pop(len(path) - 1)
|
||||
next_step = path.pop(len(path) - 1)
|
||||
path = []
|
||||
next_step = None
|
||||
# Rozpoczęcie głównej pętli programu
|
||||
while True:
|
||||
# functions.check_events(agent, board)
|
||||
@ -39,18 +39,34 @@ def run():
|
||||
agent.turn_left()
|
||||
elif event.key == pygame.K_UP:
|
||||
agent.move_forward(board)
|
||||
print(agent.x, agent.y)
|
||||
elif event.key == pygame.K_SPACE:
|
||||
field = board[randint(0, 9)][randint(0, 9)]
|
||||
if not field.is_shelf:
|
||||
path = functions.a_star(board[agent.y][agent.x], field, board)
|
||||
path.pop(len(path) - 1)
|
||||
next_step = path.pop(len(path) - 1)
|
||||
|
||||
if len(path) >= 0:
|
||||
if next_step is not None:
|
||||
time.sleep(0.5)
|
||||
|
||||
if functions.check_turn(agent, next_step):
|
||||
agent.move_forward(board)
|
||||
if len(path) != 0:
|
||||
next_step = path.pop()
|
||||
else:
|
||||
next_step = None
|
||||
print(next_step, path)
|
||||
for row in board:
|
||||
for field in row:
|
||||
if not field.is_shelf:
|
||||
field.image = pygame.image.load('img/Field.png')
|
||||
for row in board:
|
||||
for field in row:
|
||||
print(field.g, field.h, field.f, field.previous)
|
||||
else:
|
||||
functions.change_turn(agent, next_step)
|
||||
print(agent.position_x, agent.position_y)
|
||||
|
||||
|
||||
print(agent.x, agent.y)
|
||||
|
||||
draw_board(board)
|
||||
agent.blitme()
|
||||
|
Loading…
Reference in New Issue
Block a user