Бот в крестиках-ноликах не учитывает вариации

Написал крестики-нолики с помощью модуля pygame. Решил добавить игру с ботом(ходит за нолики). Для ходов бота написал функцию, которая учитывает различные вариации. Например если в 1й строке первые две клетки заняты крестиками или ноликами, то бот записывает нолик в 3ю клетку. Если ни одна вариация не подходит, то бот ходит рандомно(в самом начале, например). В случае со строками бот учитывает вариации при ходах, но абсолютно игнорирует связанные со столбцами. Заранее благодарю за помощь в решении проблемы.

В соответствии с данными строками, бот должен был бы записать нолик в 3 клетку 1го столбца, но он этого не делает.

    elif (mas[0][0] in tuple1) and (mas[1][0] in tuple1) and (mas[2][0] == 0):
        mas[2][0] = '0'

Пример - https://imgur.com/a/Tz8iZen

Полный код:

mas = [[0]*3 for i in range(3)]
def computer_move_twotwo():
    tuple1 = ['X', '0']
    no_combination = True

    if (mas[0][0] in tuple1) and (mas[0][1] in tuple1) and (mas[0][2] == 0):
        mas[0][2] = '0'
        no_combination = False
    elif (mas[0][0] in tuple1) and (mas[0][1] == 0) and (mas[0][2] in tuple1):
        mas[0][1] = '0'
        no_combination = False
    elif (mas[0][0] == 0) and (mas[0][1] in tuple1) and (mas[0][2] in tuple1):
        mas[0][0] = '0'
        no_combination = False
        # 2nd string
    elif (mas[1][0] in tuple1) and (mas[1][1] in tuple1) and (mas[1][2] == 0):
        mas[1][2] = '0'
        no_combination = False
    elif (mas[1][0] in tuple1) and (mas[1][1] == 0) and (mas[1][2] in tuple1):
        mas[1][1] = '0'
        no_combination = False
    elif (mas[1][0] == 0) and (mas[1][1] in tuple1) and (mas[1][2] in tuple1):
        mas[1][0] = '0'
        no_combination = False
    # 3rd string
    elif (mas[2][0] in tuple1) and (mas[2][1] in tuple1) and (mas[2][2] == 0):
        mas[2][2] = '0'
        no_combination = False
    elif (mas[2][0] in tuple1) and (mas[2][1] == 0) and (mas[2][2] in tuple1):
        mas[2][1] = '0'
        no_combination = False
    elif (mas[2][0] == 0) and (mas[2][1] in tuple1) and (mas[2][2] in tuple1):
        mas[2][0] = '0'
        no_combination = False
    # 1st col
    elif (mas[0][0] in tuple1) and (mas[1][0] in tuple1) and (mas[2][0] == 0):
        mas[2][0] = '0'
        no_combination = False
    elif (mas[0][0] in tuple1) and (mas[1][0] == 0) and (mas[2][0] in tuple1):
        mas[1][0] = '0'
        no_combination = False
    elif (mas[0][0] == 0) and (mas[1][0] in tuple1) and (mas[2][0] in tuple1):
        mas[0][0] = '0'
        no_combination = False
    # 2nd col
    elif (mas[0][1] in tuple1) and (mas[1][1] in tuple1) and (mas[2][1] == 0):
        mas[2][1] = '0'
        no_combination = False
    elif (mas[0][1] in tuple1) and (mas[1][1] == 0) and (mas[2][1] in tuple1):
        mas[1][1] = '0'
        no_combination = False
    elif (mas[0][1] == 0) and (mas[1][1] in tuple1) and (mas[2][1] in tuple1):
        mas[0][1] = '0'
        no_combination = False
    # 3rd col
    elif (mas[0][2] in tuple1) and (mas[1][2] in tuple1) and (mas[2][2] == 0):
        mas[2][2] = '0'
        no_combination = False
    elif (mas[0][2] in tuple1) and (mas[1][2] == 0) and (mas[2][2] in tuple1):
        mas[1][2] = '0'
        no_combination = False
    elif (mas[0][2] == 0) and (mas[1][2] in tuple1) and (mas[2][2] in tuple1):
        mas[0][2] = '0'
        no_combination = False
    elif no_combination:
        while True:
            row = random.randint(0, 2)
            col = random.randint(0, 2)
            if mas[row][col] == 0:
                mas[row][col] = '0'
                break

Ответы (0 шт):