用python可以做一些小游戏,不如飞机,比如五子棋
今天就看一看,用python怎么做五子棋吧
(1) 五子棋界面实现;
(2) 智能判定棋盘走势;
(3) 改进了棋盘扫描方式;
(4) 改良了系统评分表评估方式;
(5) 实现了基于点评分表估值找出最佳落子方式。
今天发的这个是如果有问题请大家指出,我好修改
代码如下:
screen = []
screen_change=0
def into():#初始空白棋盘
for i in range(screen_change):
list_width=[]
for j in range(screen_change):
list_width.append(' '+' |')
screen.append(list_width)
def user_black():
while True:
coordinate = input("黑方请输入你想填下子的坐标 例1,2或者5,5")
coordinate=coordinate.split(',')
width_num = int(coordinate[0]) - 1
high_num = int(coordinate[1]) - 1
if screen[width_num][high_num][1]!=' ':
print('你输入的地方已经有棋子了,请重新输入')
continue
screen[width_num][high_num] = ' ' + '@' + ' |'
break
screen_print()
def user_white():
while True:
coordinate = input("白方请输入你想填下子的坐标 例1,2或者5,5")
coordinate = coordinate.split(',')
width_num = int(coordinate[0]) - 1
high_num = int(coordinate[1]) - 1
if screen[width_num][high_num][1] != ' ':
print('你输入的地方已经有棋子了,请重新输入')
continue
screen[width_num][high_num] = ' ' + '#' + ' |'
break
screen_print()
def eeferee():#判断输赢
#判断行
for i in range(screen_change):
for j in range(screen_change-4):
if screen[i][j][1]==screen[i][j+1][1]==screen[i][j+2][1]==screen[i][j+3][1]==screen[i][j+4][1] and screen[i][j][1]!=' ':
return False
for i in range(screen_change - 4):
for j in range(screen_change):
if screen[i][j][1]==screen[i+1][j][1]==screen[i+2][j][1]==screen[i+3][j][1]==screen[i+4][j][1] and screen[i][j][1]!=' ':
return False
for i in range(screen_change - 4):
for j in range(screen_change - 4):
if screen[i][j][1]==screen[i+1][j+1][1]==screen[i+2][j+2][1]==screen[i+3][j+3][1]==screen[i+4][j+4][1] and screen[i][j][1]!=' ':
return False
for k in range(4,screen_change):
if k>=4:
if screen[i][k][1] == screen[i+1][k-1][1] == screen[i+2][k-2][1] == screen[i+3][k-3][1] == screen[i+4][k-4][1] and screen[i][k][1] != ' ':
return False
return True
def screen_print():#打印棋盘
print('——' * (screen_change*3+1))
for i in range(screen_change):
print('|',end=' ')
for j in range(screen_change):
print(screen[i][j],end=' ')
print()
print('——'*(screen_change*3+1))
def main():
global screen_change
screen_change = int(input('请输入你设定的棋盘大小:'))
into()
screen_print()
while eeferee():
user_black()
if not eeferee():
break
user_white()
print('游戏结束')
if __name__=='__main__':
main()
更多小游戏可以看这里哦http://www.daimaketang.com/register?inviteCode=XPGQQ