如何检查子数组中是否有一组匹配的元素

问题描述

我正在制作一个井字游戏应用程序,我想知道是否有办法创建一个函数来检查棋盘并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道它非常草率。 P.S我为此使用python 3.9.5,没有其他语言 '''

tic_tac_toe =[
    [[0],[0],[0]],[[0],]
print(tic_tac_toe[1][1:4])
print(tic_tac_toe[2][1:4])
print(tic_tac_toe[3][1:4])
while True:
    print("where do you want to put X")
    while True:
        try:
            print("y-axis")
            input1 = int(input())
            print("x-axis")
            input2 = int(input())
            if "O" in tic_tac_toe[input1][input2]:
                print("there is already a varible there") 
            elif "X" in tic_tac_toe[input1][input2]:
                print("there is already a varible there")
            elif input1 == 0:
                print("out of range")
            elif input2 == 0:
                print("out of range")
            else:enter code here
                tic_tac_toe[input1][input2] = "X"
                print(tic_tac_toe[1][1:4])
                print(tic_tac_toe[2][1:4])
                print(tic_tac_toe[3][1:4])
                break
        except:
            print("out of range")
    print("where do you want to put O")
    while True:
        try:
            print("y-axis")
            input3 = int(input())
            print("x-axis")
            input4 = int(input())
            if "X" in tic_tac_toe[input3][input4]:
                    print("there is already a varible there") 
            elif "O" in tic_tac_toe[input3][input4]:
                print("there is already a varible there")
            elif input3 == 0:
                print("out of range")
            elif input4 == 0:
                print("out of range")
            else:
                tic_tac_toe[input3][input4] = "O"
                print(tic_tac_toe[1][1:4])
                print(tic_tac_toe[2][1:4])
                print(tic_tac_toe[3][1:4])
                break
        except:
            print("out of range")

'''

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)