微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在制作一个井字游戏应用程序,我想知道是否有办法创建一个函数来检查棋盘并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道它非常草率。 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 举报,一经查实,本站将立刻删除。