看你们全是发布关于爬虫的代码,我这个都不好意思发了。但是又想分享给别人索性还是发了。不求点赞,只求大佬们如果有好的意见可以给出。
代码有我学的教程上的,有我查资料选用的,也有我自己想到的,如果涉及侵权,请联系我删帖。
最后上代码:
#画棋盘,定义棋子
tbp={'a1':' ','a2':' ','a3':' ','b1':' ','b2':' ','b3':' ','c1':' ','c2':' ','c3':' '}
def cb(board):
print(board['a1']+'|'+board['a2']+'|'+board['a3'])
print('------')
print(board['b1']+'|'+board['b2']+'|'+board['b3'])
print('------')
print(board['c1']+'|'+board['c2']+'|'+board['c3'])
#判断输赢
def aqw(tbp):
#dicts=dict(tbp)
if(tbp['a1'] == tbp['a2'] and tbp['a2'] == tbp['a3'] and tbp['a3']!=' '):
if(tbp['a1']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['a1'] == tbp['b2'] and tbp['b2'] == tbp['c3'] and tbp['c3']!=' '):
if(tbp['a1']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['a1'] == tbp['b1'] and tbp['b1'] == tbp['c1'] and tbp['c1']!=' '):
if(tbp['a1']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['a2'] == tbp['b2'] and tbp['b2'] == tbp['c2'] and tbp['c2']!=' '):
if(tbp['a2']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['a3'] == tbp['b3'] and tbp['b3'] == tbp['c3'] and tbp['c3']!=' '):
if(tbp['a3']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['a3'] == tbp['b2'] and tbp['b3'] == tbp['c1'] and tbp['c1']!=' '):
if(tbp['a3']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['b1'] == tbp['b2'] and tbp['b2'] == tbp['b3'] and tbp['b3']!=' '):
if(tbp['b1']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
elif (tbp['c1'] == tbp['c2'] and tbp['c2'] == tbp['c3'] and tbp['c3']!=' '):
if(tbp['c1']=='x'):
print('游戏结束,玩家x获胜')
return 1
else:
print('游戏结束,玩家o获胜')
return 2
else:
return 0
#下棋操作
turn='x'
num=-1
for i in range(9):
print('玩家:'+turn+'请下棋:',end='')
move=input()
if(move not in tbp):#误落子落错子处理
print('没有该棋子请玩家:'+turn+'重新落子:',end='')
move=input()
if(tbp[move]!=' '):
print('此处已落子请玩家:'+turn+'重新落子:',end='')
move=input()
num+=1
tbp[move]=turn
cb(tbp)
awd=aqw(tbp)
#判断是否为平局
if(awd==0):
if(num==8):
print('游戏结束,该局为平局')
if(awd>0):
break
#换人操作
if(turn=='x'):
turn='o'
else:
turn='x'
|