本文整理汇总了Python中maze.Maze.is_permissible方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.is_permissible方法的具体用法?Python Maze.is_permissible怎么用?Python Maze.is_permissible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maze.Maze
的用法示例。
在下文中一共展示了Maze.is_permissible方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: abs
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import is_permissible [as 别名]
if rotation == -90:
robot_pos['heading'] = dir_sensors[robot_pos['heading']][0]
elif rotation == 90:
robot_pos['heading'] = dir_sensors[robot_pos['heading']][2]
elif rotation == 0:
pass
else:
print 'Invalid rotation value, no rotation performed.'
# perform movement
if abs(movement) > 3:
print 'Movement limited to three squares in a turn.'
movement = max(min(int(movement), 3), -3) # fix to range [-3, 3]
while movement:
if movement > 0:
if testmaze.is_permissible(robot_pos['location'], robot_pos['heading']):
robot_pos['location'][0] += dir_move[robot_pos['heading']][0]
robot_pos['location'][1] += dir_move[robot_pos['heading']][1]
movement -= 1
else:
print 'Movement stopped by wall.'
movement = 0
else:
rev_heading = dir_reverse[robot_pos['heading']]
if testmaze.is_permissible(robot_pos['location'], rev_heading):
robot_pos['location'][0] += dir_move[rev_heading][0]
robot_pos['location'][1] += dir_move[rev_heading][1]
movement += 1
else:
print 'Movement stopped by wall.'
movement = 0
示例2: on
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import is_permissible [as 别名]
# Intialize the window and drawing turtle.
window = turtle.Screen()
wally = turtle.Turtle()
wally.speed(0)
wally.hideturtle()
wally.penup()
# maze centered on (0,0), squares are 20 units in length.
sq_size = 20
origin = testmaze.dim * sq_size / -2
# iterate through squares one by one to decide where to draw walls
for x in range(testmaze.dim):
for y in range(testmaze.dim):
if not testmaze.is_permissible([x, y], "up"):
wally.goto(origin + sq_size * x, origin + sq_size * (y + 1))
wally.setheading(0)
wally.pendown()
wally.forward(sq_size)
wally.penup()
if not testmaze.is_permissible([x, y], "right"):
wally.goto(origin + sq_size * (x + 1), origin + sq_size * y)
wally.setheading(90)
wally.pendown()
wally.forward(sq_size)
wally.penup()
# only check bottom wall if on lowest row
if y == 0 and not testmaze.is_permissible([x, y], "down"):
示例3: main
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import is_permissible [as 别名]
def main():
# Initialise screen
pygame.init()
# Create a maze based on input argument on command line.
testmaze = Maze( str(sys.argv[1]) )
size = 50 * testmaze.dim + 100
screen = pygame.display.set_mode((size, size))
pygame.display.set_caption('Basic Pygame program')
# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))
foreground = pygame.Surface(screen.get_size())
centr_x = background.get_rect().centerx
centr_y = background.get_rect().centery
# Blit everything to the screen
screen.blit(background, (0, 0))
pygame.display.flip()
sq_size = 50
# maze centered on (centr_x, centr_y), squares are 40 pixels in length.
origin = numpy.asarray([centr_x, centr_y]) + [(testmaze.dim * sq_size / -2) for x in range(2)]
max_coord = origin + testmaze.dim * sq_size
arrow = pygame.transform.scale(pygame.image.load('./arrow up.png'), [sq_size - sq_size/4 for _ in range(2)])
box = arrow.get_rect()
pos = origin + [box.width/4, box.height]
print pos
def flip_y(array):
return array * [1, -1] + [0, max_coord[1] + origin[1]]
# iterate through squares one by one to decide where to draw walls
for x in range(testmaze.dim):
for y in range(testmaze.dim):
if not testmaze.is_permissible([x,y], 'up'):
start_pos = origin + [sq_size * x, sq_size * (y+1)]
end_pos = start_pos + [sq_size, 0]
pygame.draw.line(background, (0,0,0), flip_y(start_pos), flip_y(end_pos))
if not testmaze.is_permissible([x,y], 'right'):
start_pos = origin + [sq_size * (x+1), sq_size * y]
end_pos = start_pos + [0, sq_size]
pygame.draw.line(background, (0,0,0), flip_y(start_pos), flip_y(end_pos))
# only check bottom wall if on lowest row
if y == 0 and not testmaze.is_permissible([x,y], 'down'):
start_pos = origin + [sq_size * x, 0]
end_pos = start_pos + [sq_size, 0]
pygame.draw.line(background, (0,0,0), flip_y(start_pos), flip_y(end_pos))
# only check left wall if on leftmost column
if x == 0 and not testmaze.is_permissible([x,y], 'left'):
start_pos = origin + [0, sq_size * y]
end_pos = start_pos + [0, sq_size]
pygame.draw.line(background, (0,0,0), flip_y(start_pos), flip_y(end_pos))
newx = 15
# Event loop
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
screen.blit(background, (0, 0))
#screen.blit(arrow, flip_y(pos))
pygame.display.update()
示例4: run
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import is_permissible [as 别名]
def run():
'''
This script tests a robot based on the code in robot.py on a maze given
as an argument when running the script.
'''
gui = False
if 3 <= len(sys.argv) and sys.argv[2] == '--gui':
gui = True
# Create a maze based on input argument on command line.
testmaze = Maze( str(sys.argv[1]) )
if gui:
pygame.init()
size = 50 * testmaze.dim + 100
screen = pygame.display.set_mode((size, size))
image = Image(testmaze.dim, screen)
thread = threading.Thread(target=pygame_loop)
thread.start()
else:
image = DummyImage()
# Intitialize a robot; robot receives info about maze dimensions.
game_objects.append(image)
testrobot = Robot(testmaze.dim, image)
# Record robot performance over two runs.
runtimes = []
total_time = 0
for run in range(2):
print "Starting run {}.".format(run)
# Set the robot in the start position. Note that robot position
# parameters are independent of the robot itself.
robot_pos = {'location': [0, 0], 'heading': 'up'}
run_active = True
hit_goal = False
while run_active:
total_time += 1
# check for end of time
if total_time > max_time:
run_active = False
print "Allotted time exceeded."
break
# provide robot with sensor information, get actions
sensing = [testmaze.dist_to_wall(robot_pos['location'], heading)
for heading in dir_sensors[robot_pos['heading']]]
rotation, movement = testrobot.next_move(sensing)
# check for a reset
if (rotation, movement) == ('Reset', 'Reset'):
if run == 0 and hit_goal:
run_active = False
runtimes.append(total_time)
print "Ending first run. Starting next run."
break
elif run == 0 and not hit_goal:
print "Cannot reset - robot has not hit goal yet."
continue
else:
print "Cannot reset on runs after the first."
continue
# perform rotation
if rotation == -90:
robot_pos['heading'] = dir_sensors[robot_pos['heading']][0]
elif rotation == 90:
robot_pos['heading'] = dir_sensors[robot_pos['heading']][2]
elif rotation == 0:
pass
else:
print "Invalid rotation value, no rotation performed."
# perform movement
if abs(movement) > 3:
print "Movement limited to three squares in a turn."
movement = max(min(int(movement), 3), -3) # fix to range [-3, 3]
while movement:
if movement > 0:
if testmaze.is_permissible(robot_pos['location'], robot_pos['heading']):
robot_pos['location'][0] += dir_move[robot_pos['heading']][0]
robot_pos['location'][1] += dir_move[robot_pos['heading']][1]
movement -= 1
else:
print "Movement stopped by wall."
movement = 0
else:
rev_heading = dir_reverse[robot_pos['heading']]
if testmaze.is_permissible(robot_pos['location'], rev_heading):
robot_pos['location'][0] += dir_move[rev_heading][0]
robot_pos['location'][1] += dir_move[rev_heading][1]
movement += 1
else:
print "Movement stopped by wall."
movement = 0
# check for goal entered
goal_bounds = [testmaze.dim/2 - 1, testmaze.dim/2]
if robot_pos['location'][0] in goal_bounds and robot_pos['location'][1] in goal_bounds:
hit_goal = True
#.........这里部分代码省略.........