diff --git a/__pycache__/gen_algo.cpython-38.pyc b/__pycache__/gen_algo.cpython-38.pyc index 405cda6c515797b0d78076361d961454e2fab437..e443f1958249d7a16fd85be2d5794cce403be55b 100644 Binary files a/__pycache__/gen_algo.cpython-38.pyc and b/__pycache__/gen_algo.cpython-38.pyc differ diff --git a/gen_algo.py b/gen_algo.py index 5aba5f06ad5ca2fc675cec194302d9bb0d9a09ef..2c5be1144fa18832c9dd43f119273f49a2602ebb 100644 --- a/gen_algo.py +++ b/gen_algo.py @@ -12,7 +12,7 @@ class Game(object): # entrance : 2 # exit : 3 - def __init__(self, shape=(3, 7)): + def __init__(self, shape=(3, 7), holes=0): self.dist_factor = 5 self.exploration_factor = 6 @@ -65,6 +65,19 @@ class Game(object): for i in temp: 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.exit] = 3 diff --git a/main.py b/main.py index 5aef399df4166997ec6b3c719b5665f1c1a1f280..af171804639aac15c64b9c3b1c435b22cbb6a4cc 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,7 @@ show_path_color = (160, 225, 55) #### Back shape = (10, 10) +holes = 5 number_of_generations = 1000 pop_card = 3000 elite = 0.01 @@ -33,7 +34,7 @@ pygame.init() # Init game t0 = time.time() -game = Game(shape) +game = Game(shape=shape, holes=holes) algo = GA( game, genome_length=max_moves, diff --git a/main_seq.py b/main_seq.py index ad07dc4468a81d64c7f2bb84e7eaab3b63081fc2..307c032607dd999f80fe5c9fe708ab8017ee878b 100644 --- a/main_seq.py +++ b/main_seq.py @@ -18,6 +18,7 @@ show_path_color = (160, 225, 55) #### Back shape = (10, 20) +holes = 10 number_of_generations = 1000 pop_card = 3000 elite = 0.01 @@ -33,7 +34,7 @@ pygame.init() # Init game t0 = time.time() -game = Game(shape) +game = Game(shape=shape, holes=holes) algo = GA( game, genome_length=max_moves,