Skip to content
Snippets Groups Projects
Commit 831c4799 authored by Clement Wang's avatar Clement Wang
Browse files

add imperfections in maze generator

parent 5e10b4c4
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -12,7 +12,7 @@ class Game(object): ...@@ -12,7 +12,7 @@ class Game(object):
# entrance : 2 # entrance : 2
# exit : 3 # exit : 3
def __init__(self, shape=(3, 7)): def __init__(self, shape=(3, 7), holes=0):
self.dist_factor = 5 self.dist_factor = 5
self.exploration_factor = 6 self.exploration_factor = 6
...@@ -65,6 +65,19 @@ class Game(object): ...@@ -65,6 +65,19 @@ class Game(object):
for i in temp: for i in temp:
queue.append(i) queue.append(i)
for _ in range(holes):
if random.random() < 0.5:
verti = 2 * random.randint(
1, self.maze.shape[1] // 2 - 1
) # odd between 0 and shape[1]-1
hori = 2 * random.randint(0, self.maze.shape[0] // 2 - 1) + 1
else:
hori = 2 * random.randint(1, self.maze.shape[0] // 2 - 1)
verti = 2 * random.randint(0, self.maze.shape[1] // 2 - 1) + 1
if self.maze[hori, verti] == 1:
self.maze[hori, verti] = 0
self.maze[self.entrance] = 2 self.maze[self.entrance] = 2
self.maze[self.exit] = 3 self.maze[self.exit] = 3
......
...@@ -18,6 +18,7 @@ show_path_color = (160, 225, 55) ...@@ -18,6 +18,7 @@ show_path_color = (160, 225, 55)
#### Back #### Back
shape = (10, 10) shape = (10, 10)
holes = 5
number_of_generations = 1000 number_of_generations = 1000
pop_card = 3000 pop_card = 3000
elite = 0.01 elite = 0.01
...@@ -33,7 +34,7 @@ pygame.init() ...@@ -33,7 +34,7 @@ pygame.init()
# Init game # Init game
t0 = time.time() t0 = time.time()
game = Game(shape) game = Game(shape=shape, holes=holes)
algo = GA( algo = GA(
game, game,
genome_length=max_moves, genome_length=max_moves,
......
...@@ -18,6 +18,7 @@ show_path_color = (160, 225, 55) ...@@ -18,6 +18,7 @@ show_path_color = (160, 225, 55)
#### Back #### Back
shape = (10, 20) shape = (10, 20)
holes = 10
number_of_generations = 1000 number_of_generations = 1000
pop_card = 3000 pop_card = 3000
elite = 0.01 elite = 0.01
...@@ -33,7 +34,7 @@ pygame.init() ...@@ -33,7 +34,7 @@ pygame.init()
# Init game # Init game
t0 = time.time() t0 = time.time()
game = Game(shape) game = Game(shape=shape, holes=holes)
algo = GA( algo = GA(
game, game,
genome_length=max_moves, genome_length=max_moves,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment