Exemple #1
0
def test_four_in_a_diagonal_is_a_lose():
    """
        - - - b -
        - b b b -
        - b b - -
        b b - - -
        b - - - -
    """
    grid = [[1, 6, 11, 'b', 'b'], [2, 'b', 'b', 'b', 22],
            [3, 'b', 'b', 18, 23], ['b', 'b', 14, 19, 24], [5, 10, 15, 20, 25]]

    assert is_win(grid, (0, 3), 'b', 5) is False
    assert is_win(grid, (1, 3), 'b', 5) is False
Exemple #2
0
def test_five_in_a_row_is_a_win():
    """
        - - - - - -
        - - - - - -
        b b b b b -
        - b - - - -
        b - - - - -
        - - - - - -
    """
    grid = [['e', 'e', 'b', 'e', 'b', 'e'], ['e', 'e', 'b', 'b', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'b', 'e', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'e', 'e', 'e', 'e']]

    assert is_win(grid, (0, 2), 'b', 5)
    assert is_win(grid, (2, 2), 'b', 5)
Exemple #3
0
def test_five_in_a_column_is_a_win():
    """
        - b - - - -
        - b - - - -
        b b b - b -
        - b - - - -
        b b - - - -
        - - - - - -
    """
    grid = [['e', 'e', 'b', 'e', 'b', 'e'], ['b', 'b', 'b', 'b', 'b', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'e', 'e', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'e', 'e', 'e', 'e']]

    assert is_win(grid, (1, 0), 'b', 5)
    assert is_win(grid, (1, 4), 'b', 5)
    assert is_win(grid, (1, 2), 'b', 5)
Exemple #4
0
def test_four_in_a_row_is_a_lose():
    """
        - - - - - -
        - - - - - -
        - b b b b -
        - b - - - -
        b - - - - -
        - - - - - -
    """
    grid = [['e', 'e', 'e', 'e', 'b', 'e'], ['e', 'e', 'b', 'b', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'b', 'e', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'e', 'e', 'e', 'e']]

    assert is_win(grid, (1, 2), 'b', 5) is False
    assert is_win(grid, (4, 2), 'b', 5) is False
    assert is_win(grid, (3, 2), 'b', 5) is False
Exemple #5
0
def test_six_in_a_diagonal_is_a_win():
    """
        - - - b b b
        - b b b b w
        - b w b - -
        b b b - - b
        b b - - - w
        b - w w - w
    """
    grid = [[1, 6, 11, 'b', 'b', 'b'], [2, 'b', 'b', 'b', 'b', 'e'],
            [3, 'b', 'w', 'b', 23, 'w'], ['b', 'b', 'b', 19, 24, 'w'],
            ['b', 'b', 15, 20, 25, 'e'], ['b', 'w', 'e', 'b', 'w', 'w']]

    assert is_win(grid, (0, 5), 'b', 5)
    assert is_win(grid, (2, 3), 'b', 5)
    assert is_win(grid, (5, 0), 'b', 5)
Exemple #6
0
def test_four_in_a_column_is_a_lose():
    """
        - - - - - -
        - - b - - -
        - b b b - -
        - b b - - -
        b - b - - -
        - - - - - -
    """
    grid = [['e', 'e', 'e', 'e', 'e', 'e'], ['e', 'e', 'b', 'b', 'e', 'e'],
            ['e', 'b', 'b', 'e', 'e', 'e'], ['e', 'b', 'b', 'e', 'e', 'e'],
            ['e', 'e', 'b', 'e', 'e', 'e'], ['e', 'e', 'e', 'e', 'e', 'e']]

    assert is_win(grid, (2, 1), 'b', 5) is False
    assert is_win(grid, (2, 4), 'b', 5) is False
    assert is_win(grid, (2, 2), 'b', 5) is False
Exemple #7
0
 def is_win(board, player):
     grid = board.get_grid()
     for i in range(board.get_width()):
         for j in range(board.get_height()):
             if win.is_win(grid, (i, j), player, 5):
                 return True
     return False
Exemple #8
0
def test_five_in_a_diagonal_is_a_win():
    """
        - - - - b
        - - - b -
        - - b - -
        - b - - -
        b - - - -
    """
    grid = [[1, 6, 11, 16, 'b'], [2, 7, 12, 'b', 22], [3, 8, 'b', 18, 23],
            [4, 'b', 14, 19, 24], ['b', 10, 15, 20, 25]]

    # starting at the corners
    assert is_win(grid, (0, 4), 'b', 5)
    assert is_win(grid, (4, 0), 'b', 5)

    # starting at the inner point
    assert is_win(grid, (2, 2), 'b', 5)