Ejemplo n.º 1
0
    def change_maze(self):
        self.total_time = 0

        maze_type = self.maze_value.get()
        if maze_type == RANDOM_MAZE:
            self.maze = generate_maze(size=MAZE_DIMENSION,
                                      multipath=random.randint(0, 1))
        elif maze_type == SINGLE_PATH_MAZE:
            self.maze = generate_maze(size=MAZE_DIMENSION)
        elif maze_type == MULTI_PATH_MAZE:
            self.maze = generate_maze(size=MAZE_DIMENSION, multipath=True)

        self.draw_maze()
        self.canvas.stop_simulation()
Ejemplo n.º 2
0
def gen_notreachable():
    random.seed(89)
    array = maze.generate_maze(8, 8)
    array = maze.remove_frame(array)
    array[5, 4] = -1
    array = maze.randomize(array)
    return maze.analyze(array)
Ejemplo n.º 3
0
    def test_maze_structure(self):

        # Test if sturcture is 15x15
        structure = generate_maze()

        # Count rows
        for row in structure:
            self.assertEqual(len(row), 15)
        # count columns
        self.assertEqual(len(structure), 15)
Ejemplo n.º 4
0
import random
import time

from maze import generate_maze
from mcpi.block import *
from mcpi.minecraft import Minecraft
from mcpi.vec3 import Vec3

maze_pos = Vec3(0, 100, 0)
width = 35
height = 35

mc = Minecraft.create()
my_id = mc.getPlayerEntityId('_Egor_S_')
m = generate_maze(width, height)

for i, row in enumerate(m):
    for j, mb in enumerate(row):
        if mb == 1:
            floor_block = WOOD
            wall_block = LEAVES
        else:
            floor_block = GLOWSTONE_BLOCK
            wall_block = AIR
        mc.setBlock(maze_pos + Vec3(i, 0, j), floor_block)
        mc.setBlocks(maze_pos + Vec3(i, 1, j), maze_pos + Vec3(i, 4, j), wall_block)

start_pos = maze_pos + Vec3(2 * random.randint(0, height // 2) + 1, 1, 2 * random.randint(0, width // 2) + 1)
end_pos = maze_pos + Vec3(2 * random.randint(0, height // 2) + 1, 1, 2 * random.randint(0, width // 2) + 1)

mc.entity.setTilePos(my_id, start_pos)
Ejemplo n.º 5
0
                    for i in isVisited:
                        for j in i:
                            if j == 1:
                                expandPoints += 1
                    return [path, expandPoints, maxQueueSize]
                if (newI >= 0 and newI < len(maze) and newJ >= 0
                        and newJ < len(maze) and maze[newI][newJ] == 0
                        and isVisited[newI][newJ] == 0):
                    dict[newI * len(maze[0]) +
                         newJ] = pos[0] * len(maze[0]) + pos[1]
                    queue.append([newI, newJ])
                    isVisited[newI][newJ] = 1
    expandPoints = 0
    for i in isVisited:
        for j in i:
            if j == 1:
                expandPoints += 1
    return [path, expandPoints, maxQueueSize]


def bfs(maze):
    result = bfs_find_path(maze)
    return [len(result[0]), result[1], result[2]]


if __name__ == "__main__":
    # mazeFile = np.load('./mazeFile/4x4_0.5.npy')
    # for i in range(len(mazeFile)):
    # 	print(mazeFile[i])
    matrix = maze.generate_maze(8, 0.2)
    print(dfs(matrix))
Ejemplo n.º 6
0
Archivo: game.py Proyecto: 7aske/metpy
screen = pygame.display.set_mode(window_size)
running = True

spritesheet = Spritesheet()

player_sprite = spritesheet.sprite_at(4, 8)
wall_sprite = spritesheet.sprite_at(0, 1)
floor_sprite = spritesheet.sprite_at(4, 6)

player = Player(player_sprite, 1, 1)
player_speed = 2

fps = int(1000 / 60)

level = maze.generate_maze(env.LEVEL_W, env.LEVEL_H)


def user_input():
    global running
    for ev in pygame.event.get():
        if ev.type == pygame.QUIT:
            running = False
        elif ev.type == pygame.KEYDOWN:
            if ev.key == pygame.K_q:
                running = False

    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        if level[player.y * env.LEVEL_W + player.x - 1] == 0:
Ejemplo n.º 7
0
def gen_norm():
    random.seed(11)
    array = maze.generate_maze(10, 10)
    return maze.analyze(array)
Ejemplo n.º 8
0
def gen_randomized():
    random.seed(66)
    array = maze.generate_maze(10, 10)
    array = maze.remove_frame(array)
    array = maze.randomize(array)
    return maze.analyze(array)
Ejemplo n.º 9
0
def gen_noframe():
    random.seed(42)
    array = maze.generate_maze(10, 10)
    array = maze.remove_frame(array)
    return maze.analyze(array)
Ejemplo n.º 10
0
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

times = 1000

dims = np.arange(45, 53, 1)
p = np.arange(0.3, 0.6, 0.1)
passRate = []
for i in dims:
    for j in p:
        repeate_times = times
        passCount = 0
        print('dims: ' + str(i))
        print('p: ' + str(j))
        while repeate_times > 0:
            matrix = maze.generate_maze(i, j)
            astar = ased.aStar(matrix)
            hasPath = astar.find_path()
            if hasPath:
                passCount += 1
            repeate_times -= 1
        passRate.append(passCount / times)

# plot the 3D figure
passRate = np.array(passRate)
passRate = np.reshape(passRate, (len(p), len(dims)))
dims, p = np.meshgrid(dims, p)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(dims, p, passRate, rstride=1, cstride=1, cmap='rainbow')
plt.show()
Ejemplo n.º 11
0
import matplotlib.pyplot as plt
import maze
import numpy as np
import time

times = 10000
dim = 8
step_length = 0.01
p = np.arange(0.1, 0.9, step_length)
passRate = []
for j in p:
    repeate_times = times
    passCount = 0
    print('p: ' + str(j))
    while repeate_times > 0:
        matrix = maze.generate_maze(dim, j)
        astar = ased.aStar(matrix)
        hasPath = astar.find_path()
        if not hasPath:
            repeate_times -= 1
            continue
        passCount += 1
        repeate_times -= 1
    passRate.append(passCount / times)
passRate = np.array(passRate)

np.save(
    './result/q2/q3/p_' +
    time.strftime('%Y-%m-%d %H-%M-%S', time.localtime(time.time())) + '.npy',
    p)
np.save(
Ejemplo n.º 12
0
    def print_Path(self):
        for i in range(len(self.path) - 1):
            print(self.path[i], end="-> ")
        print(self.path[len(self.path) - 1])


if __name__ == "__main__":
    # maze = [[0,1,1,1],
    #         [0,0,1,0],
    #         [0,0,0,1],
    #         [1,1,0,0]]
    astMDCost = []
    astEDCost = []
    thinCost = 0
    for i in range(50):
        matrix = maze.generate_maze(20, 0.4)
        astMD = aStarMD.aStar(matrix)
        resultMD = astMD.find_path()
        while resultMD[0] == 0:
            matrix = maze.generate_maze(20, 0.4)
            astMD = aStarMD.aStar(matrix)
            resultMD = astMD.find_path()
        
        astED = aStarED.aStar(matrix)
        resultED = astED.find_path()
        astMDCost.append(resultMD[1])
        astEDCost.append(resultED[1])
        q = 0.7
        test = aStarThin(matrix, q)
        thinCost += test.find_path()[1]
        print(i)
Ejemplo n.º 13
0
import maze
import copy
import random
import pathfinding as pf
import aStarED
import aStarMD

init_dim = 8
init_p = 0.5
init_maze = maze.generate_maze(init_dim, init_p)
dx = [-1, 0, 1]
dy = [-1, 0, 1]


def hill_climbing(maze, method, param):
    #repeate n times
    for i in range(10):
        # choose a random point for starting running hill_climbing algorithm
        x = random.randint(0, init_dim - 1)
        y = random.randint(0, init_dim - 1)
        maze[x][y] = 1 if maze[x][y] == 0 else 0
        complex = evaluate(maze, method, param)
        while True:
            prev_x = copy.deepcopy(x)
            prev_y = copy.deepcopy(y)

            # evaluate 8 neighbour point for hill_climbing
            for i in range(3):
                for j in range(3):
                    if (dx[i] != 0 and dy[j] != 0):
                        new_x = x + dx[i]
Ejemplo n.º 14
0
from maze import generate_maze
from mcpi.block import *
from mcpi.minecraft import Minecraft
from mcpi.vec3 import Vec3

maze_pos = Vec3(0, 100, 0)

mc = Minecraft.create()
m = generate_maze(35, 35)

for i, row in enumerate(m):
    for j, mb in enumerate(row):
        if mb == 1:
            floor_block = WOOD
            wall_block = LEAVES
        else:
            floor_block = GLOWSTONE_BLOCK
            wall_block = AIR
        mc.setBlock(maze_pos + Vec3(i, 0, j), floor_block)
        mc.setBlocks(maze_pos + Vec3(i, 1, j), maze_pos + Vec3(i, 4, j), wall_block)
Ejemplo n.º 15
0
    pygame.display.flip()
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_1:
                mode = 'easy'
                initiate = 1
            elif event.key == pygame.K_2:
                mode = 'hard'
                initiate = 1
        if event.type == pygame.QUIT:
            sys.exit()

    # Initiate the maze
    while initiate:
        # auto-generate Maze
        structure = generate_maze()
        maze = Maze(structure)
        # Create Wall
        maze.blit_walls(window)
        # Create MacGyver
        myplayer = Player(maze)
        # Create Medoc
        guard = Guard(maze)
        guard.set_guard_position()
        # Randomly position items in the maze
        item = Item(maze)
        item.set_item_positions()
        # Guard kill count
        guard_killed = 0
        # Ture  condition for wile loop
        done = 1