我只想在开头说我是一个初学者,如果这是一个愚蠢的问题/明显的错误,我很抱歉。我正在制作一个人类与计算机的井字游戏,并且break语句没有打破最里面的循环。问题出现在最后一个循环中,即使人类获胜,其下面的 if 条件也不会执行。它继续下棋,然后宣布计算机赢了。如果我应该更改或添加一些内容到我的问题中,请通知我。谢谢boardkeys={9:' ',8:' ',7:' ',6:' ',5:' ',4:' ',3:' ',2:' ',1:' '}def wincon(): if boardkeys[1]==boardkeys[2]==boardkeys[3]!=' ': return True elif boardkeys[4]==boardkeys[5]==boardkeys[6]!=' ': return True elif boardkeys[7]==boardkeys[8]==boardkeys[9]!=' ': return True elif boardkeys[1]==boardkeys[4]==boardkeys[7]!=' ': return True elif boardkeys[2]==boardkeys[5]==boardkeys[8]!=' ': return True elif boardkeys[3]==boardkeys[6]==boardkeys[9]!=' ': return True elif boardkeys[1]==boardkeys[5]==boardkeys[9]!=' ': return True elif boardkeys[3]==boardkeys[5]==boardkeys[7]!=' ': return Truehsym=" O "csym=" X "def ai(): z=random.randrange(1,10) while boardkeys[z]!=" ": z=random.randrange(1,10) boardkeys[z]=csymdef move(): no=int(input("enter your move human")) if boardkeys[no]==" ": boardkeys[no]=hsym else: print("invalid move") move() for i in range(10): count=0 move() count+=1 printboard() if wincon==True: ???? print("Game Over you won") ???? break ???? elif count==9: print("TIED") break else: print() print("computer's turn") ai() printboard() if wincon()==True: print("Game Over computer won") break elif count==9: print("TIED") break
添加回答
举报
0/150
提交
取消