用python实现的一个井字棋游戏,供大家参考,具体内容如下 #Tic-Tac-Toe 井字棋游戏
#全局常量
X="X"
O="O"
EMPTY=" "
#询问是否继续
def ask_yes_no(question):
response=None;
while response not in("y","n"):
response=input(question).lower()
return response
#输入位置数字
def ask_number(question ,low,high):
response=None
while response not in range(low,high):
response=int(input(question))
return response
#询问谁先走,先走方为X,后走方为O
#函数返回计算机方,玩家的角色代号
def pieces():
go_first=ask_yes_no("玩家你是否先走(y/n):")
if go_first=="y":
print("\n玩家你先走.")
human=X
computer=O
else:
print("\n计算机先走.")
computer=X
human=O
return comp