Exemple #1
0
def test_piece_can_not_move_if_one_cell_has_obstacle(piece_blueprint,
                                                     direction):
    b = Board(
        size=(10, 24),
        deactivated_cells=[
            Cell((2, 1), (0, 0, 0)),
            Cell((4, 2), (0, 0, 0)),
            Cell((1, 3), (0, 0, 0)),
            Cell((3, 4), (0, 0, 0)),
        ],
    )
    p = Piece(piece_blueprint)
    # Overwrite piece's cells
    p.cells = [
        Cell((2, 2), (0, 0, 0)),
        Cell((3, 2), (0, 0, 0)),
        Cell((2, 3), (0, 0, 0)),
        Cell((3, 3), (0, 0, 0)),
    ]

    with pytest.raises(CanNotMove):
        p.move(b, direction)

    # Assert piece hasn't moved
    assert [c.position for c in p.cells] == [(2, 2), (3, 2), (2, 3), (3, 3)]
Exemple #2
0
def test_piece_can_not_move_if_one_cell_is_on_the_border(
        piece_blueprint, direction):
    b = Board(size=(2, 2))
    p = Piece(piece_blueprint)
    # Overwrite piece's cells
    p.cells = [
        Cell((0, 0), (0, 0, 0)),
        Cell((1, 0), (0, 0, 0)),
        Cell((0, 1), (0, 0, 0)),
        Cell((1, 1), (0, 0, 0)),
    ]

    with pytest.raises(CanNotMove):
        p.move(b, direction)

    # Assert piece hasn't moved
    assert [c.position for c in p.cells] == [(0, 0), (1, 0), (0, 1), (1, 1)]
Exemple #3
0
def test_piece_can_move(piece_blueprint, direction):
    b = Board(
        size=(10, 24),
        deactivated_cells=[Cell((0, 24), color=(0, 0, 0))],
    )
    p = Piece(piece_blueprint)
    # Overwrite piece's cells
    p.cells = [Cell((1, 1), (0, 0, 0)), Cell((1, 2), (0, 0, 0))]

    p.move(b, direction)

    if direction == (1, 0):
        new_positions = [(2, 1), (2, 2)]
    elif direction == (-1, 0):
        new_positions = [(0, 1), (0, 2)]
    elif direction == (0, 1):
        new_positions = [(1, 2), (1, 3)]
    else:
        new_positions = [(1, 0), (1, 1)]
    assert [c.position for c in p.cells] == new_positions