本文整理汇总了Python中util.copy_grid函数的典型用法代码示例。如果您正苦于以下问题:Python copy_grid函数的具体用法?Python copy_grid怎么用?Python copy_grid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copy_grid函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: push_right
def push_right (grid):
"""merges grid values right"""
#moves values to the right
old_grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
while util.grid_equal(grid,old_grid) == False:
old_grid = util.copy_grid(grid)
for row in range(3,-1,-1):
for col in range(3,0,-1):
if grid[row][col] == 0 and grid[row][col-1] != 0:
grid[row][col] = grid[row][col-1]
grid[row][col-1] = 0
#merges values to the right
for row in range (3,-1,-1):
for col in range(3,0,-1):
if grid[row][col] == grid[row][col-1]:
grid[row][col] += grid[row][col-1]
grid[row][col-1] = 0
#moves values to the right
for row in range(3,-1,-1):
for col in range(3,0,-1):
if grid[row][col] == 0 and grid[row][col-1] != 0:
grid[row][col] = grid[row][col-1]
grid[row][col-1] = 0
return grid
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:25,代码来源:push.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_up
def push_up (grid):
"""merges grid values upwards"""
#moves values upwards
old_grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
while util.grid_equal(grid,old_grid) == False:
old_grid = util.copy_grid(grid)
for row in range(3):
for col in range(4):
if grid[row][col] == 0 and grid[row+1][col] != 0:
grid[row][col] = grid[row+1][col]
grid[row+1][col] = 0
#merges like values upwards
for row in range (3):
for col in range(4):
if grid[row][col] == grid[row+1][col]:
grid[row][col] += grid[row+1][col]
grid[row+1][col] = 0
#moves values upwards
for row in range(3):
for col in range(4):
if grid[row][col] == 0 and grid[row+1][col] != 0:
grid[row][col] = grid[row+1][col]
grid[row+1][col] = 0
return grid
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:25,代码来源:push.py
示例4: push_down
def push_down (grid):
"""merge grid values downwards"""
grid_copy=[]
grid_copy=util.create_grid(grid_copy)
while grid!=grid_copy:
grid_copy=util.copy_grid(grid)
for y in range(3,0,-1):
for x in range(4):
if grid[y][x]==0:
grid[y][x]=grid[y-1][x]
grid[y-1][x]=0
for x in range(4):
if grid[y][x]==grid[y-1][x]:
grid[y][x]= grid[y][x]+grid[y-1][x]
grid[y-1][x]=0
for y in range(3,0,-1):
for x in range(4):
if grid[y][x]==0:
grid[y][x]=grid[y-1][x]
grid[y-1][x]=0
return grid
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:26,代码来源:push.py
示例5: push_left
def push_left (grid):
"""merge grid values left"""
newGrid = util.copy_grid (grid)
for Row in range(4):
ListRow = []
for Column in range(4):
ListRow.append(grid[Row][Column])
for p in range(3):
for Column in range(4):
if (Column!=3 and ListRow[Column]==0):
for i in range(Column, 3):
ListRow[i]=ListRow[i+1]
ListRow[i+1]=0
for Column in range(4):
if (Column!=3 and ListRow[Column]==ListRow[Column+1]):
ListRow[Column]+=ListRow[Column+1]
ListRow[Column+1]=0
for i in range(Column+1, 3):
ListRow[i]=ListRow[i+1]
ListRow[i+1]=0
for Column in range(4):
grid[Row][Column]=ListRow[Column]
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:27,代码来源:push.py
注:本文中的util.copy_grid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论