嗨,我正在做這個井字遊戲,我看了一些教程,但沒有任何遊戲可以結束與領帶遊戲,我試圖做一個但遊戲凍結時,領帶遊戲中出現不擔心我的芬蘭變量和評論如何找到領帶遊戲蟒
import random
board = [0,1,2,
3,4,5,
6,7,8]
def show():
print board[0], '|',board[1],'|',board[2]
print '----------'
print board[3], '|',board[4],'|',board[5]
print '----------'
print board[6], '|',board[7],'|',board[8]
def checkLine(char, spot1, spot2, spot3):
if (board[spot1] == char) and (board[spot2] == char) and (board [spot3] == char) :
return True
else:
return False
def checkAll(char):
ret = False
if checkLine(char, 0, 1, 2):
ret = True
if checkLine(char, 0,3, 6):
ret = True
if checkLine(char, 1, 4, 7):
ret = True
if checkLine(char, 2, 5, 8):
ret = True
if checkLine(char, 6, 7, 8):
ret = True
if checkLine(char, 3, 4, 5):
ret = True
if checkLine(char, 2, 4, 6):
ret = True
if checkLine(char, 0, 4, 8):
ret = True
return ret
moves = range(9)
numindex = 1
ratkennut = False
while moves:
show()
input = raw_input("Put x: ")
try:
val = int(input)
input = int(input)
except ValueError:
print("Input number!")
input = raw_input("Put x: ")
input = int(input)
if input in moves:
moves.remove(input)
if board [input] != 'x' and board[input] != 'o':
board[input] = 'x'
if checkAll('x') == True:
print "~~ X Won ~~"
ratkennut = True
break;
while moves:
random.seed() #Gives opponents move
opponent = random.choice(moves)
moves.remove(opponent)
if board[opponent] != 'o' and board[opponent] != 'x':
board[opponent] = 'o'
if checkAll('o') == True:
print "~~ O Won ~~"
ratkennut = True
break;
else:
print 'This spot is taken'
else:
print "Tie!"
問題:當比賽戰成平手結束有什麼不對的代碼凍結,我需要CTRL + C如何讓它找到平手並打印「合作遊戲」 我編輯它,現在它真的很棒!
我們有什麼問題嗎? – hivert
編輯它。再讀一遍 – user3357580
「別擔心我的芬蘭變數」哈哈,真的嗎?看起來對我非常有幫助,你期望在打印遊戲時運行'打印'Tasapeli''語句,但通過用非英文名字和字符串混淆你的代碼,你不會幫助任何人幫助你。不知道'ratkennut'是什麼,但是你不需要檢查'numindex'而不是'6'而不是'9'嗎? – BartoszKP