Пример #1
0
def game_won(game_board, symbol):
    """ (str, str) -> bool

    Return True if and only if the player using symbol has won the 
    tic-tac-toe game represented by game_board.

    >>> game_won('XXX-O-O--', 'X')
    True
    >>> game_won('XOXOXOOXO', 'X')
    False
    """

    board_size = tictactoe_functions.get_board_size(game_board)
    winning_string = symbol * board_size

    for col in range(1, board_size + 1):
        extract = tictactoe_functions.extract_line(game_board, 'down', col)
        if extract == winning_string:
            return True

    for row in range(1, board_size + 1):
        extract = tictactoe_functions.extract_line(game_board, 'across', row)
        if extract == winning_string:
            return True

    extract = tictactoe_functions.extract_line(game_board, 'down_diagonal', 1)
    if extract == winning_string:
        return True

    extract = tictactoe_functions.extract_line(game_board, 'up_diagonal', 1)
    if extract == winning_string:
        return True

    return False
Пример #2
0
def game_won(game_board, symbol):
    """ (str, str) -> bool

    Return True if and only if the player using symbol has won the 
    tic-tac-toe game represented by game_board.

    >>> game_won('XXX-O-O--', 'X')
    True
    >>> game_won('XOXOXOOXO', 'X')
    False
    """

    board_size = tictactoe_functions.get_board_size(game_board)
    winning_string = symbol * board_size

    for col in range(1, board_size + 1):
        extract = tictactoe_functions.extract_line(game_board, 'down', col)
        if extract == winning_string:
            return True

    for row in range(1, board_size + 1):
        extract = tictactoe_functions.extract_line(game_board, 'across', row)
        if extract == winning_string:
            return True

    extract = tictactoe_functions.extract_line(game_board, 'down_diagonal', 1)
    if extract == winning_string:
        return True

    extract = tictactoe_functions.extract_line(game_board, 'up_diagonal', 1)
    if extract == winning_string:
        return True

    return False
Пример #3
0
       '{0}.'.format(type(result))
assert result == 0, \
       'tictactoe_functions.get_position(1, 1, 3) should return 0, but ' \
       'returned {0}.'.format(result)

# Type check and simple test for tictactoe_functions.make_move
result = tictactoe_functions.make_move('X', 1, 1, '-')
assert isinstance(result, str), \
       'tictactoe_functions.make_move should return a str, but returned {0}.' \
       .format(type(result))
assert result == 'X', \
       "tictactoe_functions.make_move('X', 1, 1, '-') should return 'X', "\
       "but returned '{0}'.".format(result)

# Type check and simple test for tictactoe_functions.extract_line
result = tictactoe_functions.extract_line('abcd', 'across', 1)
assert isinstance(result, str), \
       "tictactoe_functions.extract_line('abcd', 'across', 1) should return " \
       'a str, but returned {0}.'.format(type(result))
assert result == 'ab', \
       "tictactoe_functions.extract_line('abcd', 'across', 1) should return " \
       "'ab', but returned '{0}'.".format(result)

result = tictactoe_functions.extract_line('abcd', 'down', 1)
assert isinstance(result, str), \
       "tictactoe_functions.extract_line('abcd', 'down', 1) should return " \
       'a str, but returned {0}.'.format(type(result))
assert result == 'ac', \
       "tictactoe_functions.extract_line('abcd', 'down', 1) should return " \
       "'ac', but returned '{0}'.".format(result)
Пример #4
0
       '{0}.'.format(type(result))
assert result == 0, \
       'tictactoe_functions.get_position(1, 1, 3) should return 0, but ' \
       'returned {0}.'.format(result)

# Type check and simple test for tictactoe_functions.make_move
result = tictactoe_functions.make_move('X', 1, 1, '-')
assert isinstance(result, str), \
       'tictactoe_functions.make_move should return a str, but returned {0}.' \
       .format(type(result))
assert result == 'X', \
       "tictactoe_functions.make_move('X', 1, 1, '-') should return 'X', "\
       "but returned '{0}'.".format(result)

# Type check and simple test for tictactoe_functions.extract_line
result = tictactoe_functions.extract_line('abcd', 'across', 1)
assert isinstance(result, str), \
       "tictactoe_functions.extract_line('abcd', 'across', 1) should return " \
       'a str, but returned {0}.'.format(type(result))
assert result == 'ab', \
       "tictactoe_functions.extract_line('abcd', 'across', 1) should return " \
       "'ab', but returned '{0}'.".format(result)

result = tictactoe_functions.extract_line('abcd', 'down', 1)
assert isinstance(result, str), \
       "tictactoe_functions.extract_line('abcd', 'down', 1) should return " \
       'a str, but returned {0}.'.format(type(result))
assert result == 'ac', \
       "tictactoe_functions.extract_line('abcd', 'down', 1) should return " \
       "'ac', but returned '{0}'.".format(result)