HackChart
12/23/2019 - 4:06 AM

Connect 4: Positive Diagonal Check

Returns True if 4 instances of the target chip are aligned diagonally using positive integers (top left to bottom right). Can be used with a board of any size because index errors are handled within the function

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