Ejemplo n.º 1
0
    def test_move_outcome_equals_move_executed(self):
        game = TetrisGame()
        # starts with empty board
        self.assertEqual(game.grid, Grid())
        after_drop_grid = game.get_move_outcome(Tetromino("I"), 2)

        # state of board should be == to after_drop_grid_check
        after_drop_grid_check_cols = [0] * 10
        after_drop_grid_check_cols[6] = 0xf
        after_drop_grid_check = Grid(after_drop_grid_check_cols)
        self.assertEqual(after_drop_grid, after_drop_grid_check)

        # execute move for real
        game.execute_move(Tetromino("I"), 2)
        self.assertEqual(game.grid, after_drop_grid_check)
Ejemplo n.º 2
0
 def test_t_as_shape(self):
     block = Tetromino("T")
     self.assertEqual(
         block.as_shape(),
         [[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
     block.rotate()
     self.assertEqual(
         block.as_shape(),
         [[0, 1, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]])
     block.rotate()
     self.assertEqual(
         block.as_shape(),
         [[0, 0, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]])
Ejemplo n.º 3
0
    def test_possible_outcomes(self):
        game = TetrisGame()
        move_options = game.get_move_options(Tetromino("I"))

        for option in move_options:
            game = TetrisGame()
            game.execute_move(option.tetromino, option.x)
            self.assertEqual(game.grid, option.result)
Ejemplo n.º 4
0
 def test_turn_increment(self):
     game = TetrisGame()
     self.assertEqual(game.turns_elapsed, 0)
     self.assertEqual(game.grid, Grid())
     grid_start = game.grid
     game.execute_move(Tetromino("I"), 2)
     # TODO assert grid correctly reflects move above
     self.assertNotEqual(grid_start, game.grid)
     self.assertEqual(game.turns_elapsed, 1)
Ejemplo n.º 5
0
 def test_s_spin(self):
     block = Tetromino("S")
     self.assertEqual(block.layout, [6, 7, 9, 10])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 6, 10])
     block.rotate()
     self.assertEqual(block.layout, [6, 7, 9, 10])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 6, 10])
     block.rotate()
     self.assertEqual(block.layout, [6, 7, 9, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 6, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [6, 7, 9, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 6, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [6, 7, 9, 10])
Ejemplo n.º 6
0
 def test_i_spin(self):
     block = Tetromino("I")
     self.assertEqual(block.layout, [1, 5, 9, 13])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 6, 7])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 9, 13])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 6, 7])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 9, 13])
     block.rotate(-1)
     self.assertEqual(block.layout, [4, 5, 6, 7])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 9, 13])
     block.rotate(-1)
     self.assertEqual(block.layout, [4, 5, 6, 7])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 9, 13])
Ejemplo n.º 7
0
 def test_o_spin(self):
     block = Tetromino("O")
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 5, 6])
Ejemplo n.º 8
0
 def test_l_spin(self):
     block = Tetromino("L")
     self.assertEqual(block.layout, [1, 2, 6, 10])
     block.rotate()
     self.assertEqual(block.layout, [5, 6, 7, 9])
     block.rotate()
     self.assertEqual(block.layout, [2, 6, 10, 11])
     block.rotate()
     self.assertEqual(block.layout, [3, 5, 6, 7])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 6, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [3, 5, 6, 7])
     block.rotate(-1)
     self.assertEqual(block.layout, [2, 6, 10, 11])
     block.rotate(-1)
     self.assertEqual(block.layout, [5, 6, 7, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 6, 10])
Ejemplo n.º 9
0
 def test_j_spin(self):
     block = Tetromino("J")
     self.assertEqual(block.layout, [1, 2, 5, 9])
     block.rotate()
     self.assertEqual(block.layout, [0, 4, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 9, 8])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 6, 10])
     block.rotate()
     self.assertEqual(block.layout, [1, 2, 5, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [4, 5, 6, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 9, 8])
     block.rotate(-1)
     self.assertEqual(block.layout, [0, 4, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 2, 5, 9])
Ejemplo n.º 10
0
 def test_z_spin(self):
     block = Tetromino("Z")
     self.assertEqual(block.layout, [4, 5, 9, 10])
     block.rotate()
     self.assertEqual(block.layout, [2, 5, 6, 9])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 9, 10])
     block.rotate()
     self.assertEqual(block.layout, [2, 5, 6, 9])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 9, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [2, 5, 6, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [4, 5, 9, 10])
     block.rotate(-1)
     self.assertEqual(block.layout, [2, 5, 6, 9])
     block.rotate(-1)
Ejemplo n.º 11
0
 def test_t_spin(self):
     block = Tetromino("T")
     self.assertEqual(block.layout, [1, 4, 5, 6])
     block.rotate()
     self.assertEqual(block.layout, [1, 4, 5, 9])
     block.rotate()
     self.assertEqual(block.layout, [4, 5, 6, 9])
     block.rotate()
     self.assertEqual(block.layout, [1, 5, 6, 9])
     block.rotate()
     self.assertEqual(block.layout, [1, 4, 5, 6])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 5, 6, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [4, 5, 6, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 4, 5, 9])
     block.rotate(-1)
     self.assertEqual(block.layout, [1, 4, 5, 6])