井字棋游戏

#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=Nonewhile response not in
摘要由CSDN通过智能技术生成

#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 computer,human
#产生新的棋盘
def new_board():
board=[]
for square in range(9):
board.append(EMPTY)
return board
#显示棋盘
def display_board(board):
board2=bo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值