本文整理汇总了Python中util.print_grid函数的典型用法代码示例。如果您正苦于以下问题:Python print_grid函数的具体用法?Python print_grid怎么用?Python print_grid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_grid函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: push_right
def push_right (grid):
#merging them
for col in range(4):
for row in range(3,-1,-1):
if grid[col][row] == grid[col][row-1]:
#merges them
grid[col][row] = grid[col][row] + grid[col][row-1]
grid[col][row-1] = 0
#shifting
util.print_grid(grid)
count = 1
while count < 4:
for col in range(4):
for row in range(3,0,-1):
if grid[col][row] == 0:
if grid[col][row-1] != 0:
grid[col][row] = grid[col][row-1]
grid[col][row-1] = 0
count = count + 1
#merging again
for col in range(4):
for row in range(3,0,-1):
if grid[col][row] == grid[col][row-1]:
#merges them
grid[col][row] = grid[col][row] + grid[col][row-1]
grid[col][row-1] = 0
util.print_grid(grid)
return grid
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:31,代码来源:attempt.py
示例2: play
def play ():
grid = []
util.create_grid (grid)
add_block (grid)
add_block (grid)
won_message = False
while (True):
util.print_grid (grid)
key = input ("Enter a direction:\n")
if (key in ['x', 'u', 'd', 'l', 'r']):
saved_grid = util.copy_grid (grid)
if (key == 'x'):
return
elif (key == 'u'):
push.push_up (grid)
elif (key == 'd'):
push.push_down (grid)
elif (key == 'r'):
push.push_right (grid)
elif (key == 'l'):
push.push_left (grid)
if util.check_lost (grid):
print ("Game Over!")
return
elif util.check_won (grid) and not won_message:
print ("Won!")
won_message = True
if not util.grid_equal (saved_grid, grid):
add_block (grid)
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:30,代码来源:2048.py
示例3: push_left
def push_left(grid):
"""merge grid values left"""
count=0
for row in range(4):
for col in range(3):
block= grid[row][col]
if block!= 0:
#if adjacent block equals current block
if (grid[row][col+1]==grid[row][col]):
#newblock is equal to the combination of the blocks
newblock= (grid[row][col+1]+grid[row][col])
position=grid[row][col]
#make old blocks equal to 0
grid[row][col]=0
grid[row][col+1]=0
for column in range(4):
if grid[row][column]==0:
zeropos=column
break
grid[row][column]=newblock
else:
for col in range(4):
#counts the number of zero's
if grid[row][col]==0:
count=count+1
break
if grid[row][col+1]==0:
count=count+1
if grid[row][col+2]==0:
count=count+1
#current block equals adjacent values
grid[row][col]=grid[row][col+count]
grid[row][col+count]=0
count=0
#same as top, which merges adjacent values after they have been shifted
for col in range(3):
block= grid[row][col]
if block!= 0:
if (grid[row][col+1]==grid[row][col]):
newblock= (grid[row][col+1]+grid[row][col])
position=grid[row][col]
grid[row][col]=0
grid[row][col+1]=0
for column in range(4):
if grid[row][column]==0:
zeropos=column
break
grid[row][column]=newblock
util.print_grid(grid)
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:58,代码来源:push.py
示例4: push_Right
def push_Right(grid):
for y in range(3,0,-1):
for x in range(3,0,-1):
if grid[x][y]==0:
continue
else:
for i in range(x,0,-1):
#make sure not out of range
if x-1 >= 0:
if gird[x+1][y]==0:
grid[x+1][y]=grid[x][y]
grid[x][y]=0
for y in range(3,0,-1):
for x in range(3,0,-1):
if grid[x][y]== grid[x-1][y]:
grid[x-1][y]= grid[x][y]+grid[x-1][y]
util.print_grid(grid)
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:19,代码来源:push.py
示例5: push_down
def push_down(grid):
for y in range(3):
for x in range(3):
if grid[x][y]==0:
continue
else:
for i in range(x,0,-1):
#make sure not out of range
if x-1 >= 0:
if gird[x][y+1]==0:
grid[x][y+1]=grid[x][y]
grid[x][y]=0
for y2 in range(3):
for x2 in range(3):
if grid[x][y]== grid[x][y+1]:
grid[x][y+1]= grid[x][y]+grid[x][y+1]
util.print_grid(grid)
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:20,代码来源:push.py
示例6: run_test
def run_test (test):
if test == 0:
grid = []
util.create_grid (grid)
print(grid)
print (len (grid))
print (len (grid[0]))
print (len (grid[1]))
print (len (grid[2]))
print (len (grid[3]))
print (grid[0][0])
print (grid[1][2])
print (grid[2][1])
print (grid[3][3])
elif test == 1:
grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
util.print_grid (grid)
elif test == 2:
grid = [[2,0,2,0],[0,4,0,8],[0,16,0,128],[2,2,2,2]]
util.print_grid (grid)
elif test == 3:
grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print (util.check_lost (grid))
elif test == 4:
grid = [[2,0,2,0],[0,4,0,8],[0,16,0,128],[2,2,2,2]]
print (util.check_lost (grid))
elif test == 5:
grid = [[2,2,2,2],[2,2,2,2],[2,2,2,2],[2,2,2,2]]
print (util.check_lost (grid))
elif test == 6:
grid = [[4,16,2,4],[2,4,16,2],[2,4,8,4],[4,8,4,2]]
print (util.check_lost (grid))
elif test == 7:
grid = [[4,2,8,2],[2,8,16,8],[16,32,8,4],[4,8,4,2]]
print (util.check_lost (grid))
elif test == 8:
grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print (util.check_won (grid))
elif test == 9:
grid = [[2,0,2,0],[0,4,0,8],[0,16,0,128],[2,2,2,2]]
print (util.check_won (grid))
elif test == 10:
grid = [[2,2,2,2],[2,2,2,2],[2,2,2,2],[2,2,2,2]]
print (util.check_won (grid))
elif test == 11:
grid = [[4,16,2,4],[2,4,16,2],[2,4,8,4],[4,8,4,2]]
print (util.check_won (grid))
elif test == 12:
grid = [[2,32,2,4],[4,2,16,2],[8,0,8,4],[2,0,4,2]]
print (util.check_won (grid))
elif test == 13:
grid = [[2,2,8,0],[0,8,16,0],[16,32,8,8],[2,8,4,4]]
print (util.check_won (grid))
elif test == 14:
grid = [[64,32,32,2],[8,4,2,0],[4,2,0,0],[2,0,0,0]]
print (util.check_won (grid))
elif test == 15:
grid = [[64,32,32,2],[8,4,2,0],[4,2,0,0],[2,0,0,0]]
print (util.check_won (grid))
elif test == 16:
grid = [[128,4,0,0],[8,4,2,0],[4,2,0,2],[2,0,0,0]]
print (util.check_won (grid))
elif test == 17:
grid = [[4,2,8,2],[2,8,16,8],[16,32,8,4],[4,8,4,2]]
test_grid = util.copy_grid (grid)
print (grid[0][0],test_grid[0][0])
print (grid[1][2],test_grid[1][2])
print (grid[3][3],test_grid[3][3])
grid[0][0] = 64
grid[1][2] = 64
grid[3][3] = 64
print (grid[0][0],test_grid[0][0])
print (grid[1][2],test_grid[1][2])
print (grid[3][3],test_grid[3][3])
elif test == 18:
grid1 = [[4,2,8,2],[2,8,16,8],[16,32,8,4],[4,8,4,2]]
grid2 = [[4,2,8,2],[2,8,16,8],[16,32,8,4],[4,8,4,2]]
print (util.grid_equal (grid1, grid2))
elif test == 19:
grid1 = [[4,2,8,2],[2,8,16,8],[16,32,8,4],[4,8,4,2]]
grid2 = [[4,2,8,2],[2,8,16,4],[16,32,8,4],[4,8,4,2]]
print (util.grid_equal (grid1, grid2))
elif test == 20:
grid1 = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
grid2 = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print (util.grid_equal (grid1, grid2))
elif test == 21:
grid1 = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
grid2 = [[2,4,8,16],[32,64,128,256],[512,1024,2048,4096],[8192,16384,32768,65536]]
print (util.grid_equal (grid1, grid2))
elif test == 22:
grid1 = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
grid2 = [[2,2,2,2],[2,2,2,2],[2,2,2,2],[2,2,2,2]]
print (util.grid_equal (grid1, grid2))
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:94,代码来源:question2.py
示例7: while
# get random number
chosen = options[random.randint(0,len(options)-1)]
found = False
while (not found):
# get random location
x = random.randint (0, 3)
y = random.randint (0, 3)
# check and insert number
if (grid[x][y] == 0):
grid[x][y] = chosen
found = True
#grid = [[0,0,0,0],[0,0,0,0],[0,0,2,0],[2,0,0,0]]
grid = [[3,3,4,5],[3,5,5,2],[0,5,2,2],[2,0,2,0]]
util.print_grid(grid)
#merge grid values upwards
def push_right (grid):
#merging them
for col in range(4):
for row in range(3,-1,-1):
if grid[col][row] == grid[col][row-1]:
#merges them
grid[col][row] = grid[col][row] + grid[col][row-1]
grid[col][row-1] = 0
#shifting
util.print_grid(grid)
count = 1
while count < 4:
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:31,代码来源:attempt.py
注:本文中的util.print_grid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论