# python基础入门游戏之“#”字棋

## 作者的第一次创作，有不好、不理解的地方尽管提

``````#要用的函数，可以在主程序用到时再看
def panduan1(a,b):
x=0
if x==0:
for i in range(3):
q=0;p=0
for j in range(3):
if a[i][j]==b:
q+=1
if q==3:
return 1
if a[j][i]==b:
p+=1
if p==3:
return 1
q=0;w=0
for i in range(3):
if a[i][i]==b:
q+=1
if a[i][2-i]==b:
w+=1
if q==3 or w==3:
return 1
return 0
def xiaqi(all,qi,a):
all[int(qi[1])-1][int(qi[0])-1]=a
def shuru1():
x=input()
suoyou='123456789'
if suoyou.find(x)==-1:
print('输入不符合要求:')
return 'no'
y=0
sum=''
for j in range(1,4):
for z in range(1,4):
y+=1
sum=str(z)+','+str(j)
if y==int(x):
return(sum.split(','))
break
def panduan2(all,x):
hang=int(x[1])
lie=int(x[0])
if all[hang-1][lie-1]!='-':
return 1
else:
return 0
def dayin(all):
for i in range(3):
print(' '.join(all[i]))
#主程序开始
all=[['-','-','-'],['-','-','-'],['-','-','-']]
t=0;w=0
print('游戏开始!n黑棋先:')
while t==0 and w==0:
dayin(all)
print('轮到黑棋了:')
hei=shuru1()
while hei=='no' or panduan2(all,hei)==1:
dayin(all)
print('请重新输入:')
hei=shuru1()
xiaqi(all,hei,'1')
t=panduan1(all,'1')
dayin(all)
if t==1:
print('黑棋赢!')
break
all1=all[0]+all[1]+all[2]
if all1.count('-')==0:
dayin(all)
print('平局!')
break
print('轮到白棋了:')
bai=shuru1()
while bai=='no' or panduan2(all,bai)==1:
dayin(all)
print('请重新输入:')
bai=shuru1()
xiaqi(all,bai,'0')
w=panduan1(all,'0')
if w==1:
print('白棋赢!')
dayin(all)
all1=all[0]+all[1]+all[2]
if all1.count('-')==0:
dayin(all)
print('平局!')
break
print('游戏结束!')
``````

THE END