Beispiel #1
0
 def test_canMove_no_empty_cell_can_collapse(self):
     b = Board(size=2)
     b.cells = [
         [2, 2],
         [4, 8]
     ]
     self.assertTrue(b.canMove())
Beispiel #2
0
 def test_canMove_no_empty_cell_can_collapse(self):
     b = Board(size=2)
     b.cells = [
         [2, 2],
         [4, 8]
     ]
     self.assertTrue(b.canMove())
Beispiel #3
0
 def test_move_collapse_and_win(self):
     b = Board(size=2, goal=4)
     b.cells = [
         [2, 2],
         [0, 0]
     ]
     b.move(Board.LEFT, add_tile=False)
     self.assertTrue(b.won())
Beispiel #4
0
 def test_move_collapse_and_win(self):
     b = Board(size=2, goal=4)
     b.cells = [
         [2, 2],
         [0, 0]
     ]
     b.move(Board.LEFT, add_tile=False)
     self.assertTrue(b.won())
Beispiel #5
0
 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)
Beispiel #6
0
 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])
Beispiel #7
0
 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])
Beispiel #8
0
 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])
Beispiel #9
0
 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])
Beispiel #10
0
 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])
Beispiel #11
0
 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])
Beispiel #12
0
 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)
Beispiel #13
0
 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])
Beispiel #14
0
 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])
Beispiel #15
0
 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])
Beispiel #16
0
    def test_move_collapse(self):
        b = Board(size=2)
        b.cells = [
            [2, 2],
            [0, 0]
        ]

        b.move(Board.LEFT, add_tile=False)
        self.assertSequenceEqual(b.cells, [
            [4, 0],
            [0, 0]
        ])
Beispiel #17
0
    def test_move_collapse(self):
        b = Board(size=2)
        b.cells = [
            [2, 2],
            [0, 0]
        ]

        b.move(Board.LEFT, add_tile=False)
        self.assertSequenceEqual(b.cells, [
            [4, 0],
            [0, 0]
        ])
Beispiel #18
0
 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)
Beispiel #19
0
 def test_move_dont_add_tile_if_nothing_move(self):
     b = Board(size=2)
     b.cells = [[2, 0],
                [0, 0]]
     b.move(Board.UP)
     self.assertEqual(len([e for l in b.cells for e in l if e != 0]), 1)
Beispiel #20
0
 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)
Beispiel #21
0
 def test_move_dont_add_tile_if_nothing_move(self):
     b = Board(size=2)
     b.cells = [[2, 0],
                [0, 0]]
     b.move(Board.UP)
     self.assertEqual(len([e for l in b.cells for e in l if e != 0]), 1)
Beispiel #22
0
 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)
Beispiel #23
0
 def test_addTile(self):
     b = Board(size=1)
     b.cells = [[0]]
     b.addTile(value=42)
     self.assertEqual(b.cells[0][0], 42)
Beispiel #24
0
 def test_addTile(self):
     b = Board(size=1)
     b.cells = [[0]]
     b.addTile(value=42)
     self.assertEqual(b.cells[0][0], 42)
Beispiel #25
0
 def get_state_fake(self, action):
     b = Board()
     b.cells=self.board.cells
     b.move(action+1)
     return b.cells
Beispiel #26
0
 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)