本文整理汇总了Python中term2048.board.Board.getLine方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getLine方法的具体用法?Python Board.getLine怎么用?Python Board.getLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类term2048.board.Board
的用法示例。
在下文中一共展示了Board.getLine方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getLine
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_getLine(self):
b = Board(size=4)
l = [42, 17, 12, 3]
b.cells = [
[0]*4,
l,
[0]*4,
[0]*4
]
self.assertSequenceEqual(b.getLine(1), l)
示例2: test_move_collapse_chain_four_same_tiles
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_chain_four_same_tiles(self):
b = Board()
b.cells = [
[2, 2, 2, 2],
[0]*4,
[0]*4,
[0]*4
]
self.assertEqual(b.move(Board.LEFT, add_tile=False), 8)
self.assertSequenceEqual(b.getLine(0), [4, 4, 0, 0])
示例3: test_move_collapse_chain_line_left
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_chain_line_left(self):
b = Board()
b.cells = [
[0, 2, 2, 4],
[0]*4,
[0]*4,
[0]*4
]
self.assertEqual(b.move(Board.LEFT, add_tile=False), 4)
self.assertSequenceEqual(b.getLine(0), [4, 4, 0, 0])
示例4: test_move_collapse_chain_line_right2
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_chain_line_right2(self):
b = Board()
b.cells = [
[0, 4, 2, 2],
[0]*4,
[0]*4,
[0]*4
]
self.assertEqual(b.move(Board.RIGHT, add_tile=False), 4)
self.assertSequenceEqual(b.getLine(0), [0, 0, 4, 4])
示例5: test_move_collapse_chain_line
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_chain_line(self):
# from https://news.ycombinator.com/item?id=7398249
b = Board()
b.cells = [
[0, 2, 2, 4],
[0]*4,
[0]*4,
[0]*4
]
self.assertEqual(b.move(Board.RIGHT, add_tile=False), 4)
self.assertSequenceEqual(b.getLine(0), [0, 0, 4, 4])
示例6: test_move_dont_add_tile_if_nothing_move2
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_dont_add_tile_if_nothing_move2(self):
b = Board()
b.cells = [
[8, 4, 4, 2],
[0, 2, 2, 0],
[0]*4,
[0]*4
]
self.assertEqual(b.move(Board.UP), 0)
self.assertEqual(len([e for l in b.cells for e in l if e != 0]), 6)
self.assertEqual(b.getLine(0), [8, 4, 4, 2])
self.assertEqual(b.getLine(1), [0, 2, 2, 0])
示例7: TestBoard
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
class TestBoard(unittest.TestCase):
def setUp(self):
self.b = Board()
# == init == #
def test_init_dimensions(self):
self.assertEqual(len(self.b.cells), Board.SIZE)
self.assertEqual(len(self.b.cells[0]), Board.SIZE)
if Board.SIZE > 1:
self.assertEqual(len(self.b.cells[1]), Board.SIZE)
def test_init_dimensions_1(self):
b = Board(size=1)
c = b.cells[0][0]
self.assertTrue(c in [2, 4])
def test_init_dimensions_3_goal_4(self):
b = Board(size=3, goal=4)
self.assertEqual(b.size(), 3)
def test_init_only_two_tiles(self):
t = 0
for x in xrange(Board.SIZE):
for y in xrange(Board.SIZE):
c = self.b.cells[y][x]
if not c == 0:
t += 1
else:
self.assertEqual(c, 0, 'board[%d][%d] should be 0' % (y, x))
self.assertEqual(t, 2)
def test_init_not_won(self):
self.assertFalse(self.b.won())
def test_init_not_filled(self):
self.assertFalse(self.b.filled())
# == .size == #
def test_size(self):
s = 42
b = Board(size=s)
self.assertEqual(b.size(), s)
# == .won == #
def test_won(self):
self.b._Board__won = True
self.assertTrue(self.b.won())
self.b._Board__won = False
self.assertFalse(self.b.won())
# == .canMove == #
def test_canMove_no_empty_cell(self):
b = Board(size=1)
b.setCell(0, 0, 42)
self.assertFalse(b.canMove())
def test_canMove_empty_cell(self):
b = Board(size=2)
self.assertTrue(b.canMove())
def test_canMove_no_empty_cell_can_collapse(self):
b = Board(size=2)
b.cells = [
[2, 2],
[4, 8]
]
self.assertTrue(b.canMove())
# == .filled == #
def test_filled(self):
self.b.cells = [[1]*Board.SIZE for _ in xrange(Board.SIZE)]
self.assertTrue(self.b.filled())
# == .addTile == #
def test_addTile(self):
b = Board(size=1)
b.cells = [[0]]
b.addTile(value=42)
self.assertEqual(b.cells[0][0], 42)
# == .getCell == #
def test_getCell(self):
x, y = 3, 1
v = 42
self.b.cells[y][x] = v
self.assertEqual(self.b.getCell(x, y), v)
# == .setCell == #
def test_setCell(self):
x, y = 2, 3
v = 42
self.b.setCell(x, y, v)
self.assertEqual(self.b.cells[y][x], v)
# == .getLine == #
def test_getLine(self):
b = Board(size=4)
l = [42, 17, 12, 3]
#.........这里部分代码省略.........
示例8: test_move_collapse_with_empty_cell_in_between2
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_with_empty_cell_in_between2(self):
b = Board(size=3)
b.setLine(0, [2, 0, 2])
b.move(Board.LEFT, add_tile=False)
self.assertSequenceEqual(b.getLine(0), [4, 0, 0])
示例9: test_move_collapse_triplet2
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import getLine [as 别名]
def test_move_collapse_triplet2(self):
b = Board(size=3)
b.setLine(0, [2, 2, 2])
b.move(Board.RIGHT, add_tile=False)
self.assertSequenceEqual(b.getLine(0), [0, 2, 4])