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


Python Maze.get方法代码示例

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


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

示例1: MazeTests

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import get [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 get [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:

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import get [as 别名]
	
	# 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:
			direction = around.index('.')
			# Place an explored breadcrumb and go back
			maze.set(current, '-')
			current = maze.advance(current, direction)
		except ValueError:
			print("Something went wrong! ", current)
			maze.debug()
			sys.exit(1)

mazec = ""
开发者ID:stevenleeg,项目名称:Maze-Solver,代码行数:33,代码来源:solver.py


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