HackChart
12/23/2019 - 4:08 AM

Connect 4: Negative Diagonal Check

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

def check_negative_diagonal(board, row_number, chip_location, target_chip):
    try:
        # Checks negative 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