HackChart
12/23/2019 - 4:04 AM

Connect 4: Vertical Check

Returns True if 4 instances of the target chip are aligned vertically. Can be used with a board of any size because index errors are handled within the function

def check_vertical(board, row_number, chip_location, target_chip):
    try:
        # Checks vertical connection
        if board[row_number +1][chip_location] == target_chip and board[row_number +2][chip_location] == target_chip and board[row_number + 3][chip_location] == target_chip:
            return True
    except IndexError:
        pass