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

Python util.create_grid函数代码示例

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

本文整理汇总了Python中util.create_grid函数的典型用法代码示例。如果您正苦于以下问题:Python create_grid函数的具体用法?Python create_grid怎么用?Python create_grid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: 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


示例2: push_down

def push_down (grid):
    """merge grid values downwards"""
 
    new_grid=[]
    new_grid=util.create_grid(new_grid)
    
    while grid!=new_grid:
        new_grid=util.copy_grid(grid)
        
        for row in range(3,0,-1):
            for col in range(4):
                if grid[row][col]==0:
                    grid[row][col]=grid[row-1][col]
                    grid[row-1][col]=0
    for row in range(3,0,-1):
        for col in range(4):    
            if grid[row][col]==grid[row-1][col]:
                grid[row][col]= grid[row][col]+grid[row-1][col]
                grid[row-1][col]=0
    for row in range(3,0,-1):
        for col in range(4):
            if grid[row][col]==0:
                grid[row][col]=grid[row-1][col]
                grid[row-1][col]=0 
    return grid    
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:25,代码来源:push.py


示例3: push_up

def push_up (grid):
    """merge grid values upwards"""
    grid_copy=[]#grid_copy empty list 
    grid_copy=util.create_grid(grid_copy)
    
    while grid!=grid_copy:
        grid_copy=util.copy_grid(grid)#this calls util and creates a grid copy
        
        for y in range(3):#iterate throught the list in grid 
            for x in range(4):
                if grid[y][x]==0:#if the number is 0 we move the value to the right one unit 
                    grid[y][x]=grid[y+1][x]
                    grid[y+1][x]=0 #zero value is then put in.


    for y in range(3):
        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):
        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,代码行数:29,代码来源:push.py


示例4: push_left

def push_left(grid):  # Merge grid values right 
    old_grid = util.copy_grid(grid)     # Create a copy of the origional grid
    while len(grid) > 0:
        del grid[0]
    util.create_grid(grid)      # Grid with 0's
    for row in range(4): 
        pos = 0
        merge = 0
        for col in range(4):
            if old_grid[row][col] != 0:
                if old_grid[row][col] == grid[row][merge]:
                    grid[row][merge] += old_grid[row][col]
                    merge += 1
                else:
                    grid[row][pos] = old_grid[row][col]
                    pos += 1
                    if pos - merge >= 2:
                        merge += 1      
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:18,代码来源:push.py


示例5: push_right

def push_right(grid):   # Merge grid values left
    old_grid = util.copy_grid(grid)     # Create a copy of the origional grid
    while len(grid) > 0:
        del grid[0]
    util.create_grid(grid)      # Grid with 0's
    for row in range(4): 
        pos = 3
        merge = 3
        for col in range(3,-1,-1):
            if old_grid[row][col] != 0:
                if old_grid[row][col] == grid[row][merge]:
                    grid[row][merge] += old_grid[row][col]
                    merge -= 1
                else:
                    grid[row][pos] = old_grid[row][col]
                    pos -= 1
                    if merge - pos >= 2:
                        merge -= 1         
开发者ID:MrHamdulay,项目名称:csc3-capstone,代码行数:18,代码来源: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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.create_login_url函数代码示例发布时间:2022-05-27
下一篇:
Python util.create_dir函数代码示例发布时间: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