• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python maze.Maze类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中maze.Maze的典型用法代码示例。如果您正苦于以下问题:Python Maze类的具体用法?Python Maze怎么用?Python Maze使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Maze类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: Main

class Main(object):


	def __init__(self):
		size = (500, 500)
		self.surface = pygame.display.set_mode(size)
		mazeOrigin = (250, 250)		
		self.maze = Maze(mazeOrigin)

		done = False
		
		while(not done):
			self.surface.fill((255,255,255))
			self.maze.update()
			self.maze.draw(self.surface)
			pygame.display.flip()
			
			event = pygame.event.get()
		 
			for e in event:
				if(e.type == QUIT):
					done = True
		 
				elif(e.type == KEYDOWN):
		 
					if(e.key == K_q):
						done = True
				   
					if(e.key == K_r):
						self.maze = Maze(mazeOrigin)
开发者ID:Greymerk,项目名称:PyDungeon,代码行数:30,代码来源:main.py


示例2: test_neighbors

def test_neighbors():
  m = Maze(sample_layout)
  ns = m.get_neighbors(1,1)
  assert len(ns) == 2 # unintuitive method for set size
  assert (1,2) in ns
  assert (0,1) in ns
  ns = m.get_neighbors(4,0)
  assert ns == set([(3,0)])
开发者ID:zahanm,项目名称:teachingtools,代码行数:8,代码来源:test_maze.py


示例3: __init__

class Gui:

    def __init__(self, rows, cols):
        pygame.init()

        self.rows = rows
        self.cols = cols

        self.maze = Maze(self.rows, self.cols)
        self.maze.generate()
        self.screen = pygame.display.set_mode((self.cols * SIZE_CELL, self.rows*SIZE_CELL))

        pygame.display.set_caption("OnlineByrinth")

        self.show_solution = False

        self.quit = False

    def update(self):
        return

    def draw(self):
        self.screen.fill((WHITE))
        for pos, cell in self.maze.grid.items():
            row, col = pos
            row, col = row * SIZE_CELL, col * SIZE_CELL
            if cell.n_wall:
                pygame.draw.line(self.screen, RED, (col, row), (col + SIZE_CELL, row))
            if cell.s_wall:
                pygame.draw.line(self.screen, RED, (col, row + SIZE_CELL), (col + SIZE_CELL, row + SIZE_CELL))
            if cell.w_wall:
                pygame.draw.line(self.screen, RED, (col, row), (col, row + SIZE_CELL))
            if cell.e_wall:
                pygame.draw.line(self.screen, RED, (col + SIZE_CELL, row), (col + SIZE_CELL, row + SIZE_CELL))

        # Bordure sud et est
        pygame.draw.line(self.screen, RED, (0, self.rows * SIZE_CELL - 1), (self.cols * SIZE_CELL, self.rows * SIZE_CELL - 1))
        pygame.draw.line(self.screen, RED, (self.cols * SIZE_CELL - 1, self.rows), (self.cols * SIZE_CELL - 1, self.rows * SIZE_CELL - 1))

        if self.show_solution:
            for cell in self.maze.path:
                row, col = cell.row * SIZE_CELL, cell.col * SIZE_CELL
                pygame.draw.ellipse(self.screen, GREEN, pygame.Rect(col + SIZE_CELL / 4, row + SIZE_CELL / 4, SIZE_CELL / 2, SIZE_CELL / 2))

        pygame.display.flip()

    def main_loop(self):
        while not self.quit:
            for event in pygame.event.get():
                if event.type == QUIT:
                    self.quit = True
                if event.type == KEYDOWN and event.key == pygame.K_SPACE:
                    self.maze.generate()
                if event.type == KEYDOWN and event.key == pygame.K_s:
                    self.show_solution = not self.show_solution
            self.update()
            self.draw()
开发者ID:Mulix,项目名称:labyrinthe,代码行数:57,代码来源:gui.py


示例4: main

def main():
    files = os.listdir(MAZES)

   # for f in files:
    m = Maze(MAZES + "big.maze")
    solved = m.solveUsing(method=BFS, timeseries=True)

    if not solved:
        return "No solution"
    else:
        printMaze(solved)
开发者ID:seadraa,项目名称:CS440-AI,代码行数:11,代码来源:bfs.py


示例5: main

def main():
    argv = sys.argv

    m = Maze(MAZES + argv[1] + '.maze')
    solved =m.solveUsing(A_Star, timeseries=True, heuristic=manhattanDist, comparisonFunc=comparisonFunc, costAssign=costAssignment)
    print m.expandedNodes()

    with open(argv[1] + '_a_star_+1forward_newheur.out', 'w') as f:
        for row in solved:
            for elem in row:
                f.write(elem)
            f.write('\n')
开发者ID:seadraa,项目名称:CS440-AI,代码行数:12,代码来源:a_star_penalize.py


示例6: main

def main():
    argv = sys.argv

    m = Maze(MAZES + argv[1] + '.maze')
    solved = m.solveUsing(greedyBFS, True, euclideanDist, comparisonFunc)

    print m.expandedNodes()

    with open(argv[1] + '_greedy_bfs.out', 'w') as f:
        for row in solved:
            for elem in row:
                f.write(elem)
            f.write('\n')
开发者ID:seadraa,项目名称:CS440-AI,代码行数:13,代码来源:greedy_bfs.py


示例7: main

def main():
    argv = sys.argv

    m = Maze(MAZES + argv[1] + ".maze")
    solved = m.solveUsing(DFS, True)

    print m.expandedNodes()

    with open(argv[1] + "_dfs.out", "w") as f:
        for row in solved:
            for elem in row:
                f.write(elem)
            f.write("\n")
开发者ID:seadraa,项目名称:CS440-AI,代码行数:13,代码来源:dfs.py


示例8: Pacman

class Pacman(object):
    
    Up, Right, Down, Left = range(4)

    tronches = {
        Up : 'V',
        Down : '^',
        Left : '>',
        Right : '<',
    }
    
    def __init__(self):
        self.maze = Maze(10, 10)
        self.x = 0
        self.y = 0
        self.direction = Pacman.Left
        self.score = 0

    def bouge(self):
        oldx = self.x
        oldy = self.y
        
        if self.direction == Pacman.Down:
            #if self.y < self.maze.longueur - 1:
            self.y = (self.y + 1)% self.maze.longueur
        elif self.direction == Pacman.Up:
            #if self.y > 0:
            self.y = (self.y - 1)% self.maze.longueur
        elif self.direction == Pacman.Left:
            #if self.x > 0:
            self.x = (self.x - 1)% self.maze.largeur
        elif self.direction == Pacman.Right:
            #if self.x < self.maze.largeur - 1:
            self.x = (self.x + 1)% self.maze.largeur

        if self.maze.get(self.x,self.y) == '+':
            self.x = oldx
            self.y = oldy
            return
        self.mange()
            

    def mange(self):
        if self.maze.get(self.x, self.y) == '*':
            self.score += 1
            self.maze.set(self.x, self.y, '.')
            
    
    @property
    def tronche(self):
        return self.tronches[self.direction]
开发者ID:code-club,项目名称:code-club,代码行数:51,代码来源:pacman.py


示例9: game_loop

    def game_loop(self):
        """Main loop. """

        pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

        score = 0
        high_score = 0
        maze = Maze(self.maze_tiles, HORIZONTAL_TILES, VERTICAL_TILES)
        maze.load_level(maze.MAZE)
        pac = PacMan(104, 204, self.pacman_tiles)
        delta = (0, 0)
        while True:
            event = pygame.event.poll()
            if event.type == pygame.QUIT:
                sys.exit(0)
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_ESCAPE:
                    sys.exit(0)

            pressed = pygame.key.get_pressed()
            if pressed[pygame.K_LEFT]:
                delta = (-1, 0)
            elif pressed[pygame.K_RIGHT]:
                delta = (1, 0)
            elif pressed[pygame.K_DOWN]:
                delta = (0, 1)
            elif pressed[pygame.K_UP]:
                delta = (0, -1)

            x, y = self.screen_to_tile(pac.x, pac.y)
            if maze[(x, y)] > 0:
                score += 10
                maze[(x, y)] = 0
                if score > high_score:
                    high_score = score

            if self.legal_move(maze, pac, delta):
                pac.delta = delta
            elif not self.legal_move(maze, pac, pac.delta):
                pac.delta = (0, 0)

            pac.move()
            maze.draw()
            pac.draw()
            self.write_message(3, 0, "1UP")
            self.write_message(4, 1, str(score))
            self.write_message(9, 0, "HIGH SCORE")
            self.write_message(10, 1, str(score))
            pygame.display.flip()
开发者ID:sral,项目名称:pacman,代码行数:49,代码来源:game.py


示例10: main

def main():
    win = Window(fullscreen=True, visible=False)
    camera = Camera(win.width, win.height, (0, 0), 100)
    renderer = Renderer()
    maze = Maze()
    maze.create(50, 30, 300)
    keyboard = Keyboard()
    keyboard.key_handlers[key.ESCAPE] = win.close
    keyboard.key_handlers.update(camera.key_handlers)
    clock.schedule(maze.update)
    win.on_draw = lambda: renderer.on_draw(maze, camera, win.width, win.height)
    win.on_key_press = keyboard.on_key_press
    keyboard.print_handlers()
    win.set_visible()
    app.run()
开发者ID:msarch,项目名称:py,代码行数:15,代码来源:run.py


示例11: TestMazeParsing

class TestMazeParsing(unittest.TestCase):
    def setUp(self):
        self.maze_repr_bad = """
        +-+-+-+
        |aaaaa|
        +-+-+-+
        """

        self.maze_repr_bad_semantic = """
        +-+-+-+
        | | |
        +-+-+-+
        """

        self.maze_repr = """
        +-+-+-+
        |   |*|
        + + + +
        |*|   |
        +-+-+-+
        """

        self.horiz_walls = [[True, True, True],
                       [False, False, False],
                       [True, True, True]]

        self.vert_walls = [[True, False, True, True],
                      [True, True, False, True]]

    def test_parse_bad(self):
        self.assertRaises(Maze.ParseError, Maze, self.maze_repr_bad)

    def test_parse_bad_semantic(self):
        self.assertRaises(Maze.SemanticError, Maze, self.maze_repr_bad_semantic)

    def test_parse(self):
        self.maze = Maze(self.maze_repr)
        self.assertEqual(self.horiz_walls, self.maze.horiz_walls)
        self.assertEqual(self.vert_walls, self.maze.vert_walls)
        self.assertEqual(3, self.maze.width())
        self.assertEqual(2, self.maze.height())

    def test_walls(self):
        self.maze = Maze(self.maze_repr)
        self.assertEqual([True, True, False, False], self.maze.walls(0, 1))
        self.assertEqual([False, True, True, True], self.maze.walls(1, 0))
开发者ID:findley,项目名称:mazular,代码行数:46,代码来源:maze_test.py


示例12: restart

 def restart(self):
   self.maze_obj = Maze(*self.dim)# pass args to change maze size: Maze(10, 10)
   if self.diff == 0:
     self.maze_obj.generate(self.maze_obj.maze[(0,0)])
   else:
     self.maze_obj.generate()
   self.draw_maze()
   self.reset_player()
开发者ID:Jach,项目名称:PyMaze,代码行数:8,代码来源:PyMaze.py


示例13: build

    def build(self):

        material = self.material
        min_x, max_x = self.mc.min_x, self.mc.max_x
        min_z, max_z = self.mc.min_z, self.mc.max_z

        # Don't forget the zero block! 1 - -1 == 2, but it is 3 blocks!
        x_width = max_x - min_x + 1
        z_width = max_z - min_z + 1

        c_dim, c_height = 6, 3  # in world block units

        # in labyrinth cell units (remember walls overlap, need exact fit + 1 for outermost wall)
        x_cells, z_cells = (x_width - 1) / (c_dim - 1), (z_width - 1) / (c_dim - 1)
        castle_cells = 13

        maze = Maze(z_cells, x_cells)

        # Disconnect cells where castle resides, ensures compatible maze
        blk_x, blk_z = (x_cells - castle_cells) / 2, (z_cells - castle_cells) / 2
        for bx in xrange(blk_x, blk_x + castle_cells):
            for bz in xrange(blk_z, blk_z + castle_cells):
                maze[bz, bx].disconnect()

        maze.generate()

        # Remove the wall from graph where the labyrinth will meet with castle
        maze[blk_z + castle_cells / 2, blk_x + castle_cells].remove_wall(NORTH)

        # Render the labyrinth by generating blocks where there are walls
        for cell_x in xrange(0, x_cells):
            for cell_z in xrange(0, z_cells):
                walls = maze[cell_z, cell_x].walls
                north, west = min_x + cell_x * (c_dim - 1), min_z + cell_z * (c_dim - 1)
                if walls[NORTH] and walls[SOUTH] and walls[EAST] and walls[WEST]:
                    self.mc.make_cube(north, 0, west, c_dim, c_height, c_dim, material)
                else:
                    if walls[NORTH]:
                        self.mc.make_cube(north, 0, west, 1, c_height, c_dim, material)
                    if walls[SOUTH]:
                        self.mc.make_cube(north + (c_dim - 1), 0, west, 1, c_height, c_dim, material)
                    if walls[EAST]:
                        self.mc.make_cube(north, 0, west + (c_dim - 1), c_dim, c_height, 1, material)
                    if walls[WEST]:
                        self.mc.make_cube(north, 0, west, c_dim, c_height, 1, material)
开发者ID:batkinson,项目名称:minecraft-labyrinth,代码行数:45,代码来源:minecraft_labyrinth.py


示例14: init_maze

    def init_maze(self):
    #  custom map is a list containing each row
    #  and the width is the length of the first row
        custom_map = []
        f = open('map.txt', 'r')
        for line in f.readlines():
            custom_map.append(line)
        f.close()
        width = len(custom_map[0]) 
        height  = len(custom_map)

        self.maze = Maze(width, height, custom_map)
 
        hbox = QHBoxLayout()
        hbox.setContentsMargins(0, 0, 10, 0)
        hbox.addWidget(self.maze)
        vbox = QVBoxLayout()
        vbox.setContentsMargins(0, 10, 0, 0)
        hbox.addLayout(vbox)
 
        self.agents = QLineEdit("s")
        vbox.addWidget(QLabel("agent to watch:"))
        vbox.addWidget(self.agents)

        self.btn_watch = QPushButton("Watch Agent")
        self.btn_watch.clicked.connect(self.watchAgent)
        vbox.addWidget(self.btn_watch)

        self.btn_remove = QPushButton("Remove path")
        self.btn_remove.clicked.connect(self.remove)
        vbox.addWidget(self.btn_remove)        
 
        self.btn_solve = QPushButton("Start")
        self.btn_solve.clicked.connect(self.startSolving)
        vbox.addWidget(self.btn_solve)
 
        self.btn_step = QPushButton("Next Step")  
        self.btn_step.clicked.connect(self.doStep)
        vbox.addWidget(self.btn_step)
        
        self.btn_stop = QPushButton("Stop")
        self.btn_stop.setEnabled(False)
        self.btn_stop.clicked.connect(self.stopSolving)
        vbox.addWidget(self.btn_stop)
        
        self.btn_restart = QPushButton("Restart")
        self.btn_restart.setEnabled(True)
        self.btn_restart.clicked.connect(self.restart)
        vbox.addWidget(self.btn_restart)

        vbox.addStretch()
 
        proxy_widget = QWidget()
        proxy_widget.setLayout(hbox)
        self.setCentralWidget(proxy_widget)
 
        self.maze.init()
开发者ID:kroustou,项目名称:bomb_seek,代码行数:57,代码来源:run.py


示例15: test_construction

def test_construction():
  if len(sys.argv) == 2:
    parsed_info = Maze.parse_layout(sys.argv[1])
    test_layout = parsed_info[0]
    test_info = parsed_info[1]
  else:
    test_layout = sample_layout
    test_info = None
  m = Maze(test_layout)
  assert str(m).strip() == test_layout.strip()
开发者ID:zahanm,项目名称:teachingtools,代码行数:10,代码来源:test_maze.py


示例16: __init__

 def __init__(self, **kwargs):
     super(Dungeon, self).__init__(**kwargs)
     self.gameworld.init_gameworld(
         ['cymunk_physics', 'rotate_renderer', 'rotate', 'position',
          # 'cymunk_touch',
          'camera1'],
         callback=self.init_game)
     self.mazeobj = Maze()
     self.mazeobj.makeMap(50, 50, 100, 10, 30)
     self.maze = self.mazeobj.mapArr
开发者ID:dev-tacchinardi,项目名称:dungeon,代码行数:10,代码来源:main.py


示例17: create_maze

def create_maze():
    """Series of operations which create our Maze."""
    maze = Maze()
    room1 = Room(1)
    room2 = Room(2)
    thedoor = Door(room1, room2)

    maze.add_room(room1)
    maze.add_room(room2)

    room1.set_side(Direction.NORTH, Wall())
    room1.set_side(Direction.EAST, thedoor)
    room1.set_side(Direction.SOUTH, Wall())
    room1.set_side(Direction.WEST, Wall())

    room2.set_side(Direction.NORTH, Wall())
    room2.set_side(Direction.EAST, Wall())
    room2.set_side(Direction.SOUTH, Wall())
    room2.set_side(Direction.WEST, thedoor)

    return maze
开发者ID:AdamFlores,项目名称:python-design-patterns,代码行数:21,代码来源:basic_creator.py


示例18: detect_maze

def detect_maze(vertex, width, height):
    """Try to detect maze with given maze size, starting at given vertex."""

    maze = Maze(width, height)
    dualmaze = Maze(width, height)

    last_vertex = vertex
    stack = [vertex]

    while len(stack) > 0:
        vertex = stack.pop()
        if is_done(vertex, maze, dualmaze): continue

        if vertex != last_vertex: run(maze.bfs(last_vertex, vertex), maze)
        last_vertex = detect_walls(vertex, maze, dualmaze)

        # Fill stack; avoid unnecessary paths
        stack.extend([v for v in maze.get_reachables(*vertex) if v != last_vertex and not is_done(v, maze, dualmaze)])
        if vertex != last_vertex: stack.append(last_vertex)

    return maze
开发者ID:flo7210,项目名称:WegfLaby_AP,代码行数:21,代码来源:main.py


示例19: maze

def maze(request, size):
    '''
    creates a maze. accepts a 'size' param on the querysting
    Generates an image that is sent as the whole reponse
    Should experiment with displaying a html page within which an image
    is displayed, the source of which is this
    '''
    try:

        size = int(size)
        if size > 30:
            size = 30
            
            
        m = Maze(size, size)
        image = m.as_image()
        response = HttpResponse(mimetype="image/png")
        image.save(response, "PNG")
        return response
    except:
        pass
开发者ID:diarmuidw,项目名称:lessongen,代码行数:21,代码来源:views.py


示例20: MazeTests

class MazeTests(unittest.TestCase):
    def setUp(self):
        self.maze = Maze(10, 10)

    def test_le_laby_possede_des_supers_attributs(self):
        assert self.maze.largeur
        assert self.maze.longueur
        assert self.maze.tableau

    def test_on_peut_regarder_dans_le_laby(self):
        self.maze.largeur = 3
        self.maze.longueur = 2
        self.maze.tableau = [0,1,2,3,4,5]

        self.assertEqual(self.maze.get(1,1), 4)

    def test_import_maze_from_string(self):
        mazeString = "+..*+.*\n+..*+.*\n+..*+.*\n"
        self.maze.loadMaze(mazeString)
        self.assertEqual(self.maze.longueur,3)
        self.assertEqual(self.maze.largeur,7)
        self.assertEqual(self.maze.tableau[0],'+')
        self.assertEqual(self.maze.tableau[6],'*')
        self.assertEqual(self.maze.tableau[14],'+')

    def test_on_peut_modifier_le_laby(self):
        self.maze.set(2,2,'*')
        self.assertEqual(self.maze.get(2,2), '*')
开发者ID:code-club,项目名称:code-club,代码行数:28,代码来源:tests_maze.py



注:本文中的maze.Maze类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mbcharsetprober.MultiByteCharSetProber类代码示例发布时间:2022-05-27
下一篇:
Python maybe.T类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap