prawie dzialajacy bfs

This commit is contained in:
s464859 2022-04-07 05:33:10 +02:00
parent 634a651fb5
commit 2aab028009
11 changed files with 35 additions and 58 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
.idea
# C extensions
*.so

8
.idea/.gitignore vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (InteligentnySaper)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/InteligentnySaper.iml" filepath="$PROJECT_DIR$/.idea/InteligentnySaper.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -7,6 +7,8 @@ class AI:
current_map:minesweeper.Map
saper:minesweeper.Minesweeper
the_way:list
#jak True to można się poruszać strzałkami, jak False sam się porusza
user_controlled=False
@ -23,7 +25,7 @@ class AI:
print(goal_state)
find_path = bfs.BFS(self.saper)
find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
self.the_way = find_path.graphsearch([], [], bfs.BFS.successor, goal_state)
#co ma robić przy każdym FPS'ie
def updateFPS(self):
@ -34,10 +36,10 @@ class AI:
#aktualne pola (do debugu)
sensor = self.saper.sensor()
print(sensor[0])
print(sensor[1])
print(sensor[2])
print("-------")
#print(sensor[0])
#print(sensor[1])
#print(sensor[2])
#print("-------")
#podniesienie bomby jeśli jest jakaś na tym polu
@ -47,7 +49,7 @@ class AI:
if self.user_controlled:
self.minesweeper_controls()
return
self.chaos_controls() # <--------------------------zamiast tego trzeba wstawić jakiś algorytm
self.way_controls()
def minesweeper_controls(self):
@ -72,3 +74,9 @@ class AI:
elif dir==3:
self.saper.rotate("E")
self.saper.move()
def way_controls(self):
if len(self.the_way)>0:
way = self.the_way.pop(0)
self.saper.rotate(way)
self.saper.move()

View File

@ -66,19 +66,16 @@ class BFS:
print(' we find node')
# print(visited_position)
print(fringe)
#print(fringe)
#break
while tmp_node[1].get_parent() is not None:
#print('sdfhdfg')
#print(tmp_node[1].get_parent())
final_action_list.append(tmp_node[1].get_action())
#print(final_action_list)
tmp_node = tmp_node[1].get_parent()
final_action_list = reversed(final_action_list)
final_action_list.reverse()
print(final_action_list)
break
# return final_action_list
return final_action_list
explored.append(tmp_node)

View File

@ -1,9 +1,23 @@
class Node:
def __init__(self, parent, action, state_array):
self.parent = parent
self.action = action
self.position = state_array
if parent:
parent_pos = parent[1].get_position()
diff = [state_array[0] - parent_pos[0], state_array[1] - parent_pos[1]]
if diff[0]==1:
action="E"
elif diff[0]==-1:
action="W"
elif diff[1]==1:
action="S"
elif diff[1]==-1:
action="N"
self.action=action
else:
self.action=action
def get_position(self):
return self.position

View File

@ -3,7 +3,7 @@ import pygame
#system - klasy związane z pygame
#minesweeper - klasy związane z samym saperem
#ai - klasa wykonująca ruchy sapera
from classes import system, minesweeper, ai, bfs
from classes import system, minesweeper, ai
#ustalenie wielkości pojedyńczych kawałków mapy, oraz wielkości mapy
TILE_SIZE = 64
@ -38,7 +38,6 @@ def main():
saper = minesweeper.Minesweeper(0,0, TILE_SIZE)
#utworzenie objektu klasy AI
AI = ai.AI(window, map, saper)
#wykonanie funkcji ready() AI