当前位置: 首页>>代码示例>>Python>>正文


Python Maze.set方法代码示例

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


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

示例1: MazeTests

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import set [as 别名]
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,代码行数:30,代码来源:tests_maze.py

示例2: Pacman

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import set [as 别名]
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,代码行数:53,代码来源:pacman.py

示例3: Maze

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import set [as 别名]
# LET'S DO IT!
maze = Maze()
maze.from_file(sys.argv[1])

current = maze.start

solved = False
while solved is False:
	# Scan around us
	around = maze.scan(current)
	
	# First, let's see if we're finished with the maze
	try:
		finish = around.index('F')
		# Mark off the last breadcrumb
		maze.set(current, '.')
		solved = True
		break
	except ValueError:
		pass
	
	# Guess not, let's go on
	try:
		direction = around.index(' ')
		# Place a breadcrumb and move forward one space in that direction
		if maze.get(current) != 'S':
			maze.set(current, '.')
		current = maze.advance(current, direction)
	except ValueError:
		# There's no space, so we're going to have to go back a space
		try:
开发者ID:stevenleeg,项目名称:Maze-Solver,代码行数:33,代码来源:solver.py

示例4: filter

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import set [as 别名]
	not_visited = filter(lambda x: x not in visited, around)
	
	# Pick a random direction to proceed in that hasn't been visited
	try:
		direction = around.index(choice(not_visited))
	except IndexError:
		# Are we finished?
		if len(path) is 0:
			break
		# All directions have been visited, go back a space
		current = path[-1]
		path.remove(current)
		continue
	# Place a space as long as we're not on an edge
	if ((current[0] != 0) and (current[0] != maze.size[0])) and ((current[1] != 0) and (current[1] != maze.size[1])):
		maze.set(current, ' ')
	
	# Direction shit. I'm writing this at 12:44AM while listening to Radiohead - Sepeartor
	# Needless to say I have no fucking idea why it works...
	if (direction is 0) or (direction is 2):
		visited.append(around[1])
		visited.append(around[3])
	else:
		visited.append(around[0])
		visited.append(around[2])
	
	# Move on!
	path.append(current)
	current = maze.advance(current, direction)

# Now we need to place the start/finish points
开发者ID:stevenleeg,项目名称:Maze-Solver,代码行数:33,代码来源:generator.py


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