misc changes
Co-authored-by: Marcin Matoga <marmat35@st.amu.edu.pl> Co-authored-by: Sebastian Piotrowski <sebpio@st.amu.edu.pl>
This commit is contained in:
parent
3f4b73373a
commit
512e20b52e
12
astar2.py
12
astar2.py
@ -406,8 +406,14 @@ class SweeperAgent:
|
|||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_manual_map(self,start_map, goal_map):
|
def run_manual_map(self,start_map, goal_map, orientation = "default"):
|
||||||
self.orientation = SweeperAgent.set_orientation(start_map)
|
if orientation == "default":
|
||||||
|
self.orientation = SweeperAgent.set_orientation(start_map)
|
||||||
|
else:
|
||||||
|
self.orientation = orientation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
goal_orientation = SweeperAgent.set_goal_orientation(goal_map)
|
goal_orientation = SweeperAgent.set_goal_orientation(goal_map)
|
||||||
|
|
||||||
SweeperAgent.set_allowed(self.allowed_points, start_map)
|
SweeperAgent.set_allowed(self.allowed_points, start_map)
|
||||||
@ -423,6 +429,8 @@ class SweeperAgent:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(self):
|
def run(self):
|
||||||
self.orientation = SweeperAgent.set_orientation()
|
self.orientation = SweeperAgent.set_orientation()
|
||||||
|
38
main.py
38
main.py
@ -34,6 +34,7 @@ class Game:
|
|||||||
self.wentyl_bezpieczenstwa = 0
|
self.wentyl_bezpieczenstwa = 0
|
||||||
self.minefield = False
|
self.minefield = False
|
||||||
self.minefield_start_map = "Looper_maps/start_map"
|
self.minefield_start_map = "Looper_maps/start_map"
|
||||||
|
self.orientation_save = "default"
|
||||||
# ExampleGenerator.generate(ExampleGenerator)
|
# ExampleGenerator.generate(ExampleGenerator)
|
||||||
|
|
||||||
def load_data(self, map_name = "main_map.txt"):
|
def load_data(self, map_name = "main_map.txt"):
|
||||||
@ -166,6 +167,9 @@ class Game:
|
|||||||
if event.key == pg.K_F9 and self.wentyl_bezpieczenstwa == 0:
|
if event.key == pg.K_F9 and self.wentyl_bezpieczenstwa == 0:
|
||||||
#genetic_lib_runner = GeneticalWithLib()
|
#genetic_lib_runner = GeneticalWithLib()
|
||||||
#genetic_lib_runner.run()
|
#genetic_lib_runner.run()
|
||||||
|
|
||||||
|
#print(str(self.player.get_direction()).upper())
|
||||||
|
|
||||||
self.wentyl_bezpieczenstwa = 1
|
self.wentyl_bezpieczenstwa = 1
|
||||||
if event.key == pg.K_F10 and self.wentyl_bezpieczenstwa == 0:
|
if event.key == pg.K_F10 and self.wentyl_bezpieczenstwa == 0:
|
||||||
self.player.ai_mode = "tree"
|
self.player.ai_mode = "tree"
|
||||||
@ -186,15 +190,30 @@ class Game:
|
|||||||
if self.minefield == True:
|
if self.minefield == True:
|
||||||
if event.key == pg.K_1 and self.wentyl_bezpieczenstwa == 0:
|
if event.key == pg.K_1 and self.wentyl_bezpieczenstwa == 0:
|
||||||
agent = SweeperAgent()
|
agent = SweeperAgent()
|
||||||
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine1_map")
|
if self.minefield_start_map == "Looper_maps/start_map":
|
||||||
self.minefield_start_map = "Looper_maps/mine1_map"
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine1_map")
|
||||||
|
else:
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine1_map", orientation=self.orientation_save)
|
||||||
|
|
||||||
|
self.minefield_start_map = 'Looper_maps/mine1_map'
|
||||||
|
self.orientation_save = self.orientation_reverse(str(self.player.get_direction()).upper())
|
||||||
|
|
||||||
|
|
||||||
self.graph_move(player_moves)
|
self.graph_move(player_moves)
|
||||||
|
|
||||||
self.wentyl_bezpieczenstwa = 1
|
self.wentyl_bezpieczenstwa = 1
|
||||||
if event.key == pg.K_2 and self.wentyl_bezpieczenstwa == 0:
|
if event.key == pg.K_2 and self.wentyl_bezpieczenstwa == 0:
|
||||||
agent = SweeperAgent()
|
agent = SweeperAgent()
|
||||||
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine2_map")
|
if self.minefield_start_map == "Looper_maps/start_map":
|
||||||
self.minefield_start_map = "Looper_maps/mine2_map"
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine2_map")
|
||||||
|
else:
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine2_map", orientation=self.orientation_save)
|
||||||
|
|
||||||
|
self.minefield_start_map = 'Looper_maps/mine2_map'
|
||||||
|
self.orientation_save = self.orientation_reverse(str(self.player.get_direction).upper())
|
||||||
|
|
||||||
self.graph_move(player_moves)
|
self.graph_move(player_moves)
|
||||||
|
|
||||||
self.wentyl_bezpieczenstwa = 1
|
self.wentyl_bezpieczenstwa = 1
|
||||||
if event.key == pg.K_3 and self.wentyl_bezpieczenstwa == 0:
|
if event.key == pg.K_3 and self.wentyl_bezpieczenstwa == 0:
|
||||||
agent = SweeperAgent()
|
agent = SweeperAgent()
|
||||||
@ -255,7 +274,16 @@ class Game:
|
|||||||
def minefield_looping(self):
|
def minefield_looping(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def orientation_reverse(self, orientation):
|
||||||
|
if orientation == 'LEFT':
|
||||||
|
return 'RIGHT'
|
||||||
|
if orientation == 'RIGHT':
|
||||||
|
return 'LEFT'
|
||||||
|
if orientation == 'UP':
|
||||||
|
return 'DOWN'
|
||||||
|
if orientation == 'DOWN':
|
||||||
|
return 'UP'
|
||||||
|
pass
|
||||||
|
|
||||||
def graph_move(self, moves):
|
def graph_move(self, moves):
|
||||||
for i in moves:
|
for i in moves:
|
||||||
|
@ -39,6 +39,8 @@ class Player(pg.sprite.Sprite):
|
|||||||
self.y = copy.deepcopy(self.resetY)
|
self.y = copy.deepcopy(self.resetY)
|
||||||
self.direction = copy.deepcopy(self.resetDirection)
|
self.direction = copy.deepcopy(self.resetDirection)
|
||||||
|
|
||||||
|
def get_direction(self):
|
||||||
|
return self.direction
|
||||||
|
|
||||||
def set_direction(self, direction):
|
def set_direction(self, direction):
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
Loading…
Reference in New Issue
Block a user