added prompt to asking user of target coorfinates
This commit is contained in:
parent
fa5339685d
commit
5773c6e1bb
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
10
.idea/Projekt_Sztuczna_Inteligencja.iml
Normal file
10
.idea/Projekt_Sztuczna_Inteligencja.iml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?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="jdk" jdkName="Python 3.8 (Projekt_Sztuczna_Inteligencja)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (Projekt_Sztuczna_Inteligencja)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Projekt_Sztuczna_Inteligencja.iml" filepath="$PROJECT_DIR$/.idea/Projekt_Sztuczna_Inteligencja.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
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>
|
136
main.py
136
main.py
@ -1,9 +1,10 @@
|
|||||||
# libraries
|
# libraries
|
||||||
|
import sys
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import time
|
import time
|
||||||
from pyglet.gl import * # for blocky textures
|
from pyglet.gl import * # for blocky textures
|
||||||
|
import random
|
||||||
# other files of this project
|
# other files of this project
|
||||||
import project_constants as const
|
import project_constants as const
|
||||||
import minefield as mf
|
import minefield as mf
|
||||||
@ -27,14 +28,126 @@ def main():
|
|||||||
minefield = mf.Minefield(const.MAP_RANDOM_10x10)
|
minefield = mf.Minefield(const.MAP_RANDOM_10x10)
|
||||||
|
|
||||||
# get sequence of actions found by BFS algorithm
|
# get sequence of actions found by BFS algorithm
|
||||||
|
|
||||||
|
|
||||||
|
running = False
|
||||||
|
|
||||||
|
# basic font for user typed
|
||||||
|
base_font = pygame.font.Font(None, 32)
|
||||||
|
user_text1 = ''
|
||||||
|
user_text2 = ''
|
||||||
|
# create rectangle
|
||||||
|
input_rect1 = pygame.Rect(200, 200, 140, 32)
|
||||||
|
input_rect2 = pygame.Rect(200, 250, 140, 32)
|
||||||
|
|
||||||
|
randomb = pygame.Rect(200, 300, 140, 32)
|
||||||
|
ok = pygame.Rect(200, 350, 140, 32)
|
||||||
|
x = pygame.Rect(180, 200, 140, 32)
|
||||||
|
y = pygame.Rect(180, 250, 140, 32)
|
||||||
|
okt = pygame.Rect(240, 305, 140, 32)
|
||||||
|
randtext = pygame.Rect(220, 355, 140, 32)
|
||||||
|
# color_active stores color(lightskyblue3) which
|
||||||
|
# gets active when input box is clicked by user
|
||||||
|
color_active = pygame.Color('lightskyblue3')
|
||||||
|
|
||||||
|
# color_passive store color(chartreuse4) which is
|
||||||
|
# color of input box.
|
||||||
|
color_passive = pygame.Color('chartreuse4')
|
||||||
|
color1 = color_passive
|
||||||
|
color2 = color_passive
|
||||||
|
while True:
|
||||||
|
active1 = False
|
||||||
|
active2 = False
|
||||||
|
|
||||||
|
while running== False:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
|
||||||
|
# if user types QUIT then the screen will close
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
if input_rect1.collidepoint(event.pos):
|
||||||
|
active1 = True
|
||||||
|
else:
|
||||||
|
active1 = False
|
||||||
|
if input_rect2.collidepoint(event.pos):
|
||||||
|
active2 = True
|
||||||
|
else:
|
||||||
|
active2 = False
|
||||||
|
if randomb.collidepoint(event.pos):
|
||||||
|
running = True
|
||||||
|
if ok.collidepoint(event.pos):
|
||||||
|
user_text1 = str(random.randint(0, 9))
|
||||||
|
user_text2 =str(random.randint(0, 9))
|
||||||
|
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if active2 == True:
|
||||||
|
if event.key == pygame.K_BACKSPACE:
|
||||||
|
user_text2 = user_text2[:-1]
|
||||||
|
else:
|
||||||
|
user_text2 += event.unicode
|
||||||
|
|
||||||
|
if active1 == True:
|
||||||
|
if event.key == pygame.K_BACKSPACE:
|
||||||
|
user_text1 = user_text1[:-1]
|
||||||
|
else:
|
||||||
|
user_text1 += event.unicode
|
||||||
|
|
||||||
|
|
||||||
|
# it will set background color of screen
|
||||||
|
const.SCREEN.fill((255, 255, 255))
|
||||||
|
|
||||||
|
if active1:
|
||||||
|
color1 = color_active
|
||||||
|
else:
|
||||||
|
color1 = color_passive
|
||||||
|
|
||||||
|
if active2:
|
||||||
|
color2 = color_active
|
||||||
|
else:
|
||||||
|
color2 = color_passive
|
||||||
|
|
||||||
|
# draw rectangle and argument passed which should
|
||||||
|
# be on screen
|
||||||
|
pygame.draw.rect(const.SCREEN, color1, input_rect1)
|
||||||
|
pygame.draw.rect(const.SCREEN, color2, input_rect2)
|
||||||
|
pygame.draw.rect(const.SCREEN, color_passive, ok)
|
||||||
|
pygame.draw.rect(const.SCREEN, color_passive, randomb)
|
||||||
|
text_surface1 = base_font.render(user_text1, True, (255, 255, 255))
|
||||||
|
text_surface2 = base_font.render(user_text2, True, (255, 255, 255))
|
||||||
|
xd = base_font.render("x", True, (0, 0, 0))
|
||||||
|
yd = base_font.render("y", True, (0, 0, 0))
|
||||||
|
okd = base_font.render("ok", True, (0, 0, 0))
|
||||||
|
randd = base_font.render("random", True, (0, 0, 0))
|
||||||
|
# render at position stated in arguments
|
||||||
|
const.SCREEN.blit(xd, (x.x, x.y))
|
||||||
|
const.SCREEN.blit(yd, (y.x, y.y))
|
||||||
|
const.SCREEN.blit(okd, (okt.x, okt.y))
|
||||||
|
const.SCREEN.blit(randd, (randtext.x, randtext.y))
|
||||||
|
const.SCREEN.blit(text_surface1, (input_rect1.x + 5, input_rect1.y + 5))
|
||||||
|
const.SCREEN.blit(text_surface2, (input_rect2.x + 5, input_rect2.y + 5))
|
||||||
|
# set width of textfield so that text cannot get
|
||||||
|
# outside of user's text input
|
||||||
|
input_rect1.w = max(100, text_surface1.get_width() + 10)
|
||||||
|
input_rect2.w = max(100, text_surface2.get_width() + 10)
|
||||||
|
|
||||||
|
# display.flip() will update only a portion of the
|
||||||
|
# screen to updated, not full area
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# clock.tick(60) means that for every second at most
|
||||||
|
# 60 frames should be passed.
|
||||||
|
clock.tick(60)
|
||||||
|
toy=int(user_text1)
|
||||||
|
tox = int(user_text2)
|
||||||
action_sequence = bfs.graphsearch(
|
action_sequence = bfs.graphsearch(
|
||||||
initial_state=bfs.State(
|
initial_state=bfs.State(
|
||||||
row=minefield.agent.position[0],
|
row=minefield.agent.position[0],
|
||||||
column=minefield.agent.position[1],
|
column=minefield.agent.position[1],
|
||||||
direction=const.Direction.UP),
|
direction=minefield.agent.direction),
|
||||||
minefield=minefield)
|
minefield=minefield, tox=tox, toy = toy)
|
||||||
|
|
||||||
running = True
|
|
||||||
while running:
|
while running:
|
||||||
|
|
||||||
# FPS control
|
# FPS control
|
||||||
@ -55,14 +168,17 @@ def main():
|
|||||||
elif action == const.Action.GO:
|
elif action == const.Action.GO:
|
||||||
minefield.agent.go()
|
minefield.agent.go()
|
||||||
|
|
||||||
time.sleep(const.ACTION_INTERVAL)
|
time.sleep(const.ACTION_INTERVAL/5)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
for event in pygame.event.get():
|
|
||||||
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
running = False
|
||||||
|
time.sleep(const.ACTION_INTERVAL/5)
|
||||||
|
#'for event in pygame.event.get():
|
||||||
|
# if event.type == pygame.QUIT:
|
||||||
|
# running = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -47,13 +47,15 @@ def get_successors(state: State, minefield: Minefield):
|
|||||||
return successors
|
return successors
|
||||||
|
|
||||||
|
|
||||||
def graphsearch(initial_state: State, minefield: Minefield, fringe: List[Node] = None, explored: List[Node] = None):
|
def graphsearch(initial_state: State, minefield: Minefield, fringe: List[Node] = None, explored: List[Node] = None, tox: int = None,toy: int = None):
|
||||||
# fringe and explored initialization
|
# fringe and explored initialization
|
||||||
|
global GOAL
|
||||||
if fringe is None:
|
if fringe is None:
|
||||||
fringe = list()
|
fringe = list()
|
||||||
if explored is None:
|
if explored is None:
|
||||||
explored = list()
|
explored = list()
|
||||||
|
if tox is not None and toy is not None:
|
||||||
|
GOAL = (tox, toy)
|
||||||
explored_states = set()
|
explored_states = set()
|
||||||
fringe_states = set()
|
fringe_states = set()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user