#畫棋盤
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['a3']!=' '):
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['a3']!=' '):
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['a3']!=' '):
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['a3']!=' '):
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['a3']!=' '):
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['a3']!=' '):
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['a3']!=' '):
if(tbp['c1']=='x'):
print('游戲結束,'+'玩家x獲勝')
return 1
else:
print('游戲結束,'+'玩家O獲勝')
return 2
else:
return 0
#下棋操作
turn='X'
for i in range(9):
print('玩家:'+turn+'請下棋:',end='')
move=input()
tbp[move]=turn
cb(tbp)
awd=aqw(tbp)
if awd>0:
break
#換人操作
if(turn=='X'):
turn='O'
else:
turn='X'
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/218784.html
上一篇:Datacom基本架構
下一篇:TCP擁塞控制原理
