• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.copy_grid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.copyfile函数代码示例发布时间:2022-05-27
下一篇:
Python util.cmd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap