reset mode, minefield mode
Co-authored-by: Marcin Matoga <marmat35@st.amu.edu.pl>
This commit is contained in:
parent
7719dfdc4e
commit
3f4b73373a
7
Looper_maps/sprite_map
Normal file
7
Looper_maps/sprite_map
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
>.....2
|
||||||
|
ppp....
|
||||||
|
p2pp...
|
||||||
|
..#2...
|
||||||
|
...#...
|
||||||
|
....ppp
|
||||||
|
2p.p...
|
55
astar2.py
55
astar2.py
@ -225,8 +225,10 @@ class SweeperAgent:
|
|||||||
self.puddle_points = set()
|
self.puddle_points = set()
|
||||||
|
|
||||||
|
|
||||||
def where_am_i(self):
|
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap("map.txt")]
|
|
||||||
|
def where_am_i(self, map_name = "map.txt"):
|
||||||
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
for row in range(MAP_SIZE):
|
for row in range(MAP_SIZE):
|
||||||
for column, pos in enumerate(temp_map[row]):
|
for column, pos in enumerate(temp_map[row]):
|
||||||
@ -238,8 +240,8 @@ class SweeperAgent:
|
|||||||
|
|
||||||
# add orientation
|
# add orientation
|
||||||
|
|
||||||
def where_to_go(self):
|
def where_to_go(self, map_name = "goal_map.txt"):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap("goal_map.txt")]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
for row in range(MAP_SIZE):
|
for row in range(MAP_SIZE):
|
||||||
for column, pos in enumerate(temp_map[row]):
|
for column, pos in enumerate(temp_map[row]):
|
||||||
@ -250,8 +252,8 @@ class SweeperAgent:
|
|||||||
return row, column
|
return row, column
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_allowed(allowed_points):
|
def set_allowed(allowed_points, map_name = 'map.txt'):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
a_row = 0
|
a_row = 0
|
||||||
a_column = 0
|
a_column = 0
|
||||||
@ -281,8 +283,8 @@ class SweeperAgent:
|
|||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_puddles(puddle_points):
|
def set_puddles(puddle_points, map_name = 'map.txt'):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
a_row = 0
|
a_row = 0
|
||||||
a_column = 0
|
a_column = 0
|
||||||
@ -297,8 +299,8 @@ class SweeperAgent:
|
|||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_goal():
|
def get_goal(map_name = 'goal_map.txt'):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('goal_map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
a_row = 0
|
a_row = 0
|
||||||
a_column = 0
|
a_column = 0
|
||||||
@ -311,6 +313,10 @@ class SweeperAgent:
|
|||||||
return a_row, a_column
|
return a_row, a_column
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_initial(initial):
|
def set_initial(initial):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap('map.txt')]
|
||||||
@ -330,8 +336,8 @@ class SweeperAgent:
|
|||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_orientation():
|
def set_orientation(map_name = 'map.txt'):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
orientation = ""
|
orientation = ""
|
||||||
|
|
||||||
@ -349,8 +355,8 @@ class SweeperAgent:
|
|||||||
return orientation
|
return orientation
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_goal_orientation():
|
def set_goal_orientation(map_name = 'goal_map.txt'):
|
||||||
temp_map = [list(item) for item in SweeperAgent.loadMap('goal_map.txt')]
|
temp_map = [list(item) for item in SweeperAgent.loadMap(map_name)]
|
||||||
|
|
||||||
orientation = ""
|
orientation = ""
|
||||||
|
|
||||||
@ -367,6 +373,10 @@ class SweeperAgent:
|
|||||||
|
|
||||||
return orientation
|
return orientation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_manual(self,
|
def run_manual(self,
|
||||||
given_orientation,
|
given_orientation,
|
||||||
@ -395,6 +405,23 @@ class SweeperAgent:
|
|||||||
return len(self.plan_route(agent_position, goal_position, self.allowed_points, self.puddle_points))
|
return len(self.plan_route(agent_position, goal_position, self.allowed_points, self.puddle_points))
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run_manual_map(self,start_map, goal_map):
|
||||||
|
self.orientation = SweeperAgent.set_orientation(start_map)
|
||||||
|
goal_orientation = SweeperAgent.set_goal_orientation(goal_map)
|
||||||
|
|
||||||
|
SweeperAgent.set_allowed(self.allowed_points, start_map)
|
||||||
|
SweeperAgent.set_puddles(self.puddle_points, start_map)
|
||||||
|
|
||||||
|
x, y = self.where_am_i(start_map)
|
||||||
|
x1, y1 = SweeperAgent.get_goal(goal_map)
|
||||||
|
|
||||||
|
agent_position = AgentPosition(x, y, self.orientation)
|
||||||
|
goal_position = AgentPosition(x1, y1, goal_orientation)
|
||||||
|
|
||||||
|
return self.plan_route(agent_position, goal_position, self.allowed_points, self.puddle_points)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(self):
|
def run(self):
|
||||||
|
73
main.py
73
main.py
@ -32,15 +32,18 @@ class Game:
|
|||||||
pg.key.set_repeat(500, 100)
|
pg.key.set_repeat(500, 100)
|
||||||
self.load_data()
|
self.load_data()
|
||||||
self.wentyl_bezpieczenstwa = 0
|
self.wentyl_bezpieczenstwa = 0
|
||||||
#ExampleGenerator.generate(ExampleGenerator)
|
self.minefield = False
|
||||||
|
self.minefield_start_map = "Looper_maps/start_map"
|
||||||
|
# ExampleGenerator.generate(ExampleGenerator)
|
||||||
|
|
||||||
def load_data(self):
|
def load_data(self, map_name = "main_map.txt"):
|
||||||
game_folder = path.dirname(__file__)
|
game_folder = path.dirname(__file__)
|
||||||
self.map_data = []
|
self.map_data = []
|
||||||
with open(path.join(game_folder, 'main_map.txt'), 'rt') as f:
|
with open(path.join(game_folder, map_name), 'rt') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
self.map_data.append(line)
|
self.map_data.append(line)
|
||||||
|
|
||||||
|
|
||||||
def new(self):
|
def new(self):
|
||||||
# initialize all variables and do all the setup for a new game
|
# initialize all variables and do all the setup for a new game
|
||||||
#glebokosc rozmiar masa moc szkodliwosc zabawka stan teledysk
|
#glebokosc rozmiar masa moc szkodliwosc zabawka stan teledysk
|
||||||
@ -168,8 +171,54 @@ class Game:
|
|||||||
self.player.ai_mode = "tree"
|
self.player.ai_mode = "tree"
|
||||||
self.player.check_bomb()
|
self.player.check_bomb()
|
||||||
self.wentyl_bezpieczenstwa = 1
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_F11 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
self.player.check_bomb_neural()
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_F12 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
g.load_data('Looper_maps/sprite_map')
|
||||||
|
g.new()
|
||||||
|
g.show_go_screen()
|
||||||
|
self.minefield = True
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_F1 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
self.player.reset()
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if self.minefield == True:
|
||||||
|
if event.key == pg.K_1 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
agent = SweeperAgent()
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine1_map")
|
||||||
|
self.minefield_start_map = "Looper_maps/mine1_map"
|
||||||
|
self.graph_move(player_moves)
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_2 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
agent = SweeperAgent()
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine2_map")
|
||||||
|
self.minefield_start_map = "Looper_maps/mine2_map"
|
||||||
|
self.graph_move(player_moves)
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_3 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
agent = SweeperAgent()
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine3_map")
|
||||||
|
self.minefield_start_map = "Looper_maps/mine3_map"
|
||||||
|
self.graph_move(player_moves)
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_4 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
agent = SweeperAgent()
|
||||||
|
player_moves = SweeperAgent.run_manual_map(agent, self.minefield_start_map, "Looper_maps/mine4_map")
|
||||||
|
self.minefield_start_map = "Looper_maps/mine4_map"
|
||||||
|
self.graph_move(player_moves)
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
if event.key == pg.K_F1 and self.wentyl_bezpieczenstwa == 0:
|
||||||
|
self.minefield_start_map = "Looper_maps/start_map"
|
||||||
|
self.wentyl_bezpieczenstwa = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if event.type == pg.KEYUP:
|
if event.type == pg.KEYUP:
|
||||||
|
if event.key == pg.K_F1:
|
||||||
|
self.wentyl_bezpieczenstwa = 0
|
||||||
if event.key == pg.K_F2:
|
if event.key == pg.K_F2:
|
||||||
self.wentyl_bezpieczenstwa = 0
|
self.wentyl_bezpieczenstwa = 0
|
||||||
if event.key == pg.K_F3:
|
if event.key == pg.K_F3:
|
||||||
@ -188,6 +237,24 @@ class Game:
|
|||||||
self.wentyl_bezpieczenstwa = 0
|
self.wentyl_bezpieczenstwa = 0
|
||||||
if event.key == pg.K_F10:
|
if event.key == pg.K_F10:
|
||||||
self.wentyl_bezpieczenstwa = 0
|
self.wentyl_bezpieczenstwa = 0
|
||||||
|
if event.key == pg.K_F11:
|
||||||
|
self.wentyl_bezpieczenstwa = 0
|
||||||
|
if event.key == pg.K_F12:
|
||||||
|
self.wentyl_bezpieczenstwa = 0
|
||||||
|
if self.minefield == True:
|
||||||
|
if event.key == pg.K_1:
|
||||||
|
self.wentyl_bezpieczenstwa = 0
|
||||||
|
if event.key == pg.K_2:
|
||||||
|
self.wentyl_bezpieczenstwa == 0
|
||||||
|
if event.key == pg.K_3:
|
||||||
|
self.wentyl_bezpieczenstwa == 0
|
||||||
|
if event.key == pg.K_4:
|
||||||
|
self.wentyl_bezpieczenstwa == 0
|
||||||
|
|
||||||
|
|
||||||
|
def minefield_looping(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def graph_move(self, moves):
|
def graph_move(self, moves):
|
||||||
|
12
sprites.py
12
sprites.py
@ -3,6 +3,7 @@ import enum
|
|||||||
import ctypes
|
import ctypes
|
||||||
import ast
|
import ast
|
||||||
import time
|
import time
|
||||||
|
import copy
|
||||||
from settings import *
|
from settings import *
|
||||||
from maze import *
|
from maze import *
|
||||||
from learning import *
|
from learning import *
|
||||||
@ -23,13 +24,22 @@ class Player(pg.sprite.Sprite):
|
|||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
self.resetX = copy.deepcopy(x)
|
||||||
|
self.resetY = copy.deepcopy(y)
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
self.resetDirection = copy.deepcopy(direction)
|
||||||
self.maze = Maze()
|
self.maze = Maze()
|
||||||
self.moves = ''
|
self.moves = ''
|
||||||
self.my_learning = Learning()
|
self.my_learning = Learning()
|
||||||
self.ai_mode = "none"
|
self.ai_mode = "none"
|
||||||
#self.decision_tree_learning()
|
#self.decision_tree_learning()
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.x = copy.deepcopy(self.resetX)
|
||||||
|
self.y = copy.deepcopy(self.resetY)
|
||||||
|
self.direction = copy.deepcopy(self.resetDirection)
|
||||||
|
|
||||||
|
|
||||||
def set_direction(self, direction):
|
def set_direction(self, direction):
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
|
||||||
@ -100,6 +110,8 @@ class Player(pg.sprite.Sprite):
|
|||||||
self.check_bomb()
|
self.check_bomb()
|
||||||
if str(self.ai_mode) == "neural":
|
if str(self.ai_mode) == "neural":
|
||||||
self.check_bomb_neural()
|
self.check_bomb_neural()
|
||||||
|
if str(self.ai_mode) == "off":
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user