Merge branch 'master' of s444428/AL-2020 into master

This commit is contained in:
Wojciech Łukasik 2020-05-15 17:55:45 +00:00 committed by Gogs
commit 85e52dd150
5 changed files with 67 additions and 9 deletions

6
.idea/vcs.xml Normal file
View 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>

View File

@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <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="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -15,9 +20,14 @@
</list> </list>
</option> </option>
</component> </component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1blUxWbA3VMjMFjk8gUnLGMgAoU" /> <component name="ProjectId" id="1blUxWbA3VMjMFjk8gUnLGMgAoU" />
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="restartRequiresConfirmation" value="false" /> <property name="restartRequiresConfirmation" value="false" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
@ -98,14 +108,27 @@
<workItem from="1589233530634" duration="769000" /> <workItem from="1589233530634" duration="769000" />
<workItem from="1589543001064" duration="78000" /> <workItem from="1589543001064" duration="78000" />
<workItem from="1589543305930" duration="10474000" /> <workItem from="1589543305930" duration="10474000" />
<workItem from="1589561555146" duration="3374000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" /> <option name="version" value="1" />
</component> </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"> <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/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$" /> <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> </component>
</project> </project>

Binary file not shown.

View File

@ -67,6 +67,7 @@ def a_star(start_field, goal_field, board):
field.g = 0 field.g = 0
field.h = 0 field.h = 0
field.f = 0 field.f = 0
field.previous = None
return path return path
@ -133,4 +134,16 @@ def change_turn(agent, next_field):
agent.turn_right() 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
View File

@ -6,6 +6,7 @@ import time
from agent import Agent from agent import Agent
from settings import Settings from settings import Settings
from board import create_board, draw_board from board import create_board, draw_board
from random import randint
# Inicjalizacja programu i utworzenie obiektu ekrany # Inicjalizacja programu i utworzenie obiektu ekrany
@ -21,9 +22,8 @@ def run():
for field in row: for field in row:
print(field.cost_of_travel) print(field.cost_of_travel)
path = functions.a_star(board[agent.y][agent.x], board[5][7], board) path = []
path.pop(len(path) - 1) next_step = None
next_step = path.pop(len(path) - 1)
# Rozpoczęcie głównej pętli programu # Rozpoczęcie głównej pętli programu
while True: while True:
# functions.check_events(agent, board) # functions.check_events(agent, board)
@ -39,18 +39,34 @@ def run():
agent.turn_left() agent.turn_left()
elif event.key == pygame.K_UP: elif event.key == pygame.K_UP:
agent.move_forward(board) 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) time.sleep(0.5)
if functions.check_turn(agent, next_step): if functions.check_turn(agent, next_step):
agent.move_forward(board) agent.move_forward(board)
if len(path) != 0: if len(path) != 0:
next_step = path.pop() 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: else:
functions.change_turn(agent, next_step) functions.change_turn(agent, next_step)
print(agent.position_x, agent.position_y) print(agent.x, agent.y)
draw_board(board) draw_board(board)
agent.blitme() agent.blitme()