当前位置: 首页>>代码示例>>Python>>正文


Python Board.getEmptyCells方法代码示例

本文整理汇总了Python中term2048.board.Board.getEmptyCells方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getEmptyCells方法的具体用法?Python Board.getEmptyCells怎么用?Python Board.getEmptyCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在term2048.board.Board的用法示例。


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

示例1: TestBoard

# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getEmptyCells [as 别名]

#.........这里部分代码省略.........
        b = Board(size=4)
        l = [42, 17, 12, 3]
        b.cells = [
            [0]*4,
            l,
            [0]*4,
            [0]*4
        ]
        self.assertSequenceEqual(b.getLine(1), l)

    # == .getCol == #
    def test_getCol(self):
        s = 4
        b = Board(size=s)
        l = [42, 17, 12, 3]
        b.cells = [[l[i], 4, 1, 2] for i in xrange(s)]
        self.assertSequenceEqual(b.getCol(0), l)

    # == .setLine == #
    def test_setLine(self):
        i = 2
        l = [1, 2, 3, 4]
        self.b.setLine(i, l)
        self.assertEqual(self.b.getLine(i), l)

    # == .setCol == #
    def test_setLine(self):
        i = 2
        l = [1, 2, 3, 4]
        self.b.setCol(i, l)
        self.assertEqual(self.b.getCol(i), l)

    # == .getEmptyCells == #
    def test_getEmptyCells(self):
        self.assertEqual(len(self.b.getEmptyCells()), Board.SIZE**2 - 2)

    def test_getEmptyCells_filled(self):
        b = Board(size=1)
        b.setCell(0, 0, 42)
        self.assertSequenceEqual(b.getEmptyCells(), [])

    # == .move == #
    def test_move_filled(self):
        b = Board(size=1)
        b.setCell(0, 0, 42)
        b.move(Board.UP)
        self.assertSequenceEqual(b.cells, [[42]])
        b.move(Board.LEFT)
        self.assertSequenceEqual(b.cells, [[42]])
        b.move(Board.RIGHT)
        self.assertSequenceEqual(b.cells, [[42]])
        b.move(Board.DOWN)
        self.assertSequenceEqual(b.cells, [[42]])

    def test_move_add_tile_if_collapse(self):
        b = Board(size=2)
        b.cells = [[2, 0],
                   [2, 0]]
        b.move(Board.UP)
        self.assertEqual(len([e for l in b.cells for e in l if e != 0]), 2)

    def test_move_add_tile_if_move(self):
        b = Board(size=2)
        b.cells = [[0, 0],
                   [2, 0]]
        b.move(Board.UP)
开发者ID:cychoi,项目名称:term2048,代码行数:70,代码来源:test_board.py

示例2: test_getEmptyCells_filled

# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getEmptyCells [as 别名]
 def test_getEmptyCells_filled(self):
     b = Board(size=1)
     b.setCell(0, 0, 42)
     self.assertSequenceEqual(b.getEmptyCells(), [])
开发者ID:cychoi,项目名称:term2048,代码行数:6,代码来源:test_board.py


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