windows.py负责处理素材图片以及将图片导入pygame。menu.py负责各级菜单的具体功能实现,包括菜单的绘制,点击效果,鼠标移动效果,点击返回等等。easypc.py是实现简单人机对战的主要程序,我采用了最简单的打分表,没有录入棋谱,也没有用博弈论决策树alphabeta剪枝,但是同样达到了较好的效果。judgewin.py主要实现对终局棋盘胜负判断。因为python无法直接实现跨文件的全局变量传输,(global 关键字可以定义一个变量为全局变量,但是这个仅限于在一个模块(py文件)中调用全局变量,在另外一个py文件 再次使用 global x 也是无法访问到的)所以我专门定义了一个全局变量管理模块gloval.py来管理全局变量。
在实现人机对战功能时,核心思想是电脑计算出棋盘上每个格子的分数,之后选择分数最高的格子落子,这也就意味着需要通过一张打分表来进行评分。打分规则具体设计如下。
在不同游戏状态下进行相同的操作可能会产生不同的结果,所以处理事件响应时要先判断游戏状态,再作出相应的反馈,这里我把游戏状态一共分成七类。
#--coding:utf-8--
import pygame as pg
from sys import exit #用exit来退出程序
import windows as wd
import menu
import gloval
import numpy
import judgewin
import easy_pc
gloval.init()
def main():
wd.Image_PreProcessing()
wd.windows()
mainloop()
if __name__=='__main__':
while 1:
main()
while restart == 0之前,是进行各种参数的初始化。将在用到每个参数时详细说明,这里不过多赘述,下面介绍循环内的详细过程
gamestate是游戏状态的标识符,默认为1。1为主菜单状态,2为人机和双人对战选择菜单状态,3为人机对战先后手选择菜单,4,5,6为对战菜单,7为结束游戏菜单,以下图为例,这是对战菜单状态,也就是说gamestate==4或者5,6,在这种状态下才会显示“悔棋”菜单,“重新开始”菜单,而且当光标移到棋盘上时,会将光标变成棋子的图标,而在其他状态下kennel不会显示“悔棋”菜单和“重新开始”菜单,而且当光标移动到棋盘上时,外观不会发生改变。
之后按照画背景,画菜单,顺序运行两个函数,这样可以保证棋盘和菜单显示在背景图片之上。
在画好界面后,需要实现相关的功能,这些功能全部都是通过鼠标反馈的,包括鼠标的移动和点击事件。比如,当鼠标在不同游戏状态下移动到棋盘或者移动到菜单位置上,光标的样式都会不同。点击菜单,落子,也会产生不同的反馈。这些功能全部是通过drawpress和drawmove两个函数实现的。
之后判断是否赢棋,以及更新赢棋后的界面。
在完成一帧内的所有操作以及判断后,刷新界面,查看restart的状态以判断用户是否退出程序或者点击重新开始
def mainloop():
#设置默认光标样式
pg.mouse.set_cursor(*pg.cursors.arrow)
gloval.setval('restart',0)
global restart
restart=gloval.getval('restart')
gloval.setval('press_intro', 0)
gloval.setval('press_regret', 0)
global gamestate
gamestate=1
gloval.setval('gamestate', 1)
global press,button
press=(0,0,0)
button=(132,71,34)#字体颜色
global screen
screen=gloval.getval('screen')
global imBackground
imBackground=gloval.getval('imBackground')
global imChessboard
imChessboard=gloval.getval('imChessboard')
global imBlackPiece
imBlackPiece=gloval.getval('imBlackPiece')
global imWhitePiece
imWhitePiece=gloval.getval('imWhitePiece')
global whiteround #回合,黑子先走,whiteround为-1
whiteround=[-1]
global chess_array#储存双方落子信息,0246先手,1357后手
chess_array=[]
global chess_num
chess_num=0
global piece_x,piece_y,piece
FPS = 60
piece_x=[]
piece_y=[]
piece=[]
while restart == 0:
#刷新gamestate
gamestate=gloval.getval('gamestate')
#画背景,左上角是坐标
drawbg()
#画菜单
drawmenu()
#鼠标事件按键情况
drawpress()
# 画鼠标移动的相关效果
drawmove()
#判断是否赢棋
judgewin.check_win(chess_array)
#刷新画面
pg.display.update()
#调整游戏帧数
FPSClock=pg.time.Clock()
FPSClock.tick(FPS)
restart=gloval.getval('restart')
def drawbg():
##画背景
screen.blit(imBackground,(0,0))
global chessboard_start_x
global chessboard_start_y
chessboard_start_x=50 #(1024-(1024-540))/2
chessboard_start_y=(768-540)/2
screen.blit(imChessboard,(chessboard_start_x,chessboard_start_y))
对于每一种游戏状态下的菜单都不相同,具体实现方法见menu模块
def drawmenu():
##画菜单
if gamestate==1:
menu.menu1() #画’开始游戏‘,‘游戏说明’,’结束游戏‘按钮
elif gamestate==2:
menu.menu2() #画 ‘人机对战’,‘双人对战’,'返回上级菜单',‘结束游戏’
elif gamestate==3:
menu.menu3() #画 ‘玩家先手’,‘电脑先手’,'返回上级菜单',‘结束游戏’
elif gamestate==4 or gamestate==5 or gamestate==6 :
menu.menu4() #画‘悔棋’,‘重新开始’,‘结束游戏’按钮
elif gamestate==7:
menu.menu7() #画‘重新开始’,‘结束游戏’按钮
##画鼠标移动的相关效果
def drawmove():
gloval.setval('mouse_x', pg.mouse.get_pos()[0]) # 鼠标的坐标
gloval.setval('mouse_y', pg.mouse.get_pos()[1])
mouse_x,mouse_y = pg.mouse.get_pos() # 棋子跟随鼠标移动
if chessboard_start_x<mouse_x<chessboard_start_x+540 and chessboard_start_y<mouse_y<chessboard_start_y+540 and (gamestate==4 or gamestate== 5 or gamestate== 6):
if whiteround[chess_num]==1:
screen.blit(imWhitePiece,(mouse_x-16,mouse_y-16))
else:
screen.blit(imBlackPiece,(mouse_x-16,mouse_y-16))
elif gamestate==1:
menu.movemenu1()
elif gamestate==2:
menu.movemenu2()
elif gamestate==3:
menu.movemenu3()
elif gamestate==4 or gamestate==5 or gamestate==6 :
menu.movemenu4()
elif gamestate==7:
menu.movemenu7()
def drawpress():
global whiteround
global chess_array
global d
global chess_num
global piece_x,piece_y,piece
press_intro=gloval.getval('press_intro')
press_regret=gloval.getval('press_regret')
d = (518-22)/14 #(1,1)的实际坐标为(22,22),(15,15)的实际坐标为(518,518),有14个间隔
for event in pg.event.get(): #获取鼠标点击事件
if event.type==pg.QUIT:
pg.quit()
exit()
if event.type == pg.MOUSEBUTTONDOWN:
gloval.setval('pressed_x', event.pos[0])
gloval.setval('pressed_y', event.pos[1])
pressed_x,pressed_y=event.pos[0],event.pos[1]
#第一种情况,人人对战
if chessboard_start_x<pressed_x<chessboard_start_x+540 and chessboard_start_y<pressed_y<chessboard_start_y+540 and gamestate==4 :
player_pos_chess(pressed_x,pressed_y)
#第二种情况,玩家先手
elif chessboard_start_x<pressed_x<chessboard_start_x+540 and chessboard_start_y<pressed_y<chessboard_start_y+540 and gamestate==5 :
ifem=player_pos_chess(pressed_x, pressed_y) #玩家下棋
if ifem!=False:
pc_pos_chess() #电脑下棋
#第三种情况,电脑先手
elif chessboard_start_x<pressed_x<chessboard_start_x+540 and chessboard_start_y<pressed_y<chessboard_start_y+540 and gamestate==6:
ifem=player_pos_chess(pressed_x, pressed_y) #玩家下棋
if ifem!=False:
pc_pos_chess() #电脑下棋
#第四种情况,点击菜单
else:
if gamestate==1:
menu.pressmenu1()
elif gamestate==2:
menu.pressmenu2()
elif gamestate==3:
if 6==menu.pressmenu3():
pc_pos_chess()
elif gamestate==4 or gamestate==5 or gamestate==6 :
menu.pressmenu4()
elif gamestate==7:
menu.pressmenu7()
restart=gloval.getval('restart')#是否重启游戏
if chess_array : #画棋子和棋子上面的数字不为空,有落子
draw_chess(chess_num,whiteround) #画棋子和上面的数字
if press_intro==1: #游戏简介信息
draw_intro_text()
if press_regret==1: #悔棋
regret()
draw_chesscross(chess_num)#画最后一个落子位置
当在主菜单页面点击“游戏说明”时显示相关内容。我在使用系统默认字体的时候总是报错,所以使用了网上下载的字体文件。
blit函数是把图片放到对象上screen.blit(image,position)表示将image放置到screen对象上,位置的两个坐标由position确定,pygame官方文档对blit的解释如下
def draw_intro_text():
my_font=pg.font.Font('mufont.ttf',25)
text1=my_font.render("双方分别使用黑白两色的棋子,",True,button)
text2=my_font.render("下在棋盘直线与横线的交叉点上,",True,button)
text3=my_font.render("先形成五子连线者获胜。",True,button)
screen.blit(text1,(640,100))
screen.blit(text2,(640,140))
screen.blit(text3,(640,180))
def regret():
global chess_num,chess_array,piece_y,piece_x,piece,whiteround
if chess_num!=0: #删除所有储存的数组
if gamestate==4:
del chess_array[-1]
del piece_x[-1]
del piece_y[-1]
del piece[-1]
del whiteround[-1]
chess_num=chess_num-1
if gamestate==5 or gamestate==6:
del chess_array[-1]
del chess_array[-1]
del piece_x[-1]
del piece_y[-1]
del piece_x[-1]
del piece_y[-1]
del piece[-1]
del piece[-1]
del whiteround[-1]
del whiteround[-1]
chess_num=chess_num-2
gloval.setval('press_regret', 0)
chess_num储存了棋面上的棋子总数。
不管是人机对战还是双人对战,第一个落子的总是黑子。
whileround间隔储存1和-1,1代表白子回合,-1代表黑子回合。
以黑子落子为例,screen.blit(imBlackPiece,(piece_x[i]-16,piece_y[i]-16))将黑子的中心恰好放到网格线的交叉点上。
i从0开始计数,所以第i 个子上的数字为i+1。
将数字恰好放到棋子上,而且先显示棋子,后显示数字,这样数字就不会被棋子覆盖。
def draw_chess(chess_num,whiteround):
my_font=pg.font.Font('mufont.ttf',18)
for i in range(chess_num):
if whiteround[i]==-1: #黑子
screen.blit(imBlackPiece,(piece_x[i]-16,piece_y[i]-16))
text_w=my_font.render(str(i+1),True,(255,255,255))
screen.blit(text_w,(piece_x[i]-7,piece_y[i]-12))
else: #白子
screen.blit(imWhitePiece,(piece_x[i]-16,piece_y[i]-16))
text_b=my_font.render(str(i+1),True,(0,0,0))
screen.blit(text_b,(piece_x[i]-7,piece_y[i]-12))
def draw_chesscross(chess_num):
if chess_num!=0:
pg.draw.rect(screen,button,[int(piece_x[chess_num-1]-16),int(piece_y[chess_num-1]-16),33,33],2)
##二维坐标转一维索引值
##二维坐标值转一维索引
def array2index(array):
return (array[0]-1)*15+array[1]
##一维索引值转二维坐标
def index2array(index):
i,j = int((index-index%15)/15+1),int(index%15)
if j == 0 :
i -= 1
j = 15
return i,j
输入变量是落子的横纵坐标,和piece中存储的棋面上已落子的坐标列表对比
##判断是否为空
def if_isempty(i,j):
if [i,j] not in piece:
return True
else:
return False
##得到棋盘上棋子的数组位置
def getpos(pressed_x,pressed_y):
mouse_chessboard_x = pressed_x-chessboard_start_x# 鼠标在棋盘中的坐标
mouse_chessboard_y = pressed_y-chessboard_start_y
i_tmp = round((mouse_chessboard_y-22)/d)+1 # 计算鼠标最接近的格点
j_tmp = round((mouse_chessboard_x-22)/d)+1
if i_tmp in range(1,16) and j_tmp in range(1,16):#1到15判断标号是否有效
chess_i = i_tmp
chess_j = j_tmp
return chess_i,chess_j
##二维坐标转化为棋盘内的真实坐标(计算棋子在棋盘中的位置)(计算棋子的实际位置)
def getrealpos(array):
piece_chessboard_x,piece_chessboard_y = 22+(array[1]-1)*d,22+(array[0]-1)*d
piece_x,piece_y = piece_chessboard_x+chessboard_start_x,piece_chessboard_y+chessboard_start_y
return piece_x,piece_y
def player_pos_chess(pressed_x,pressed_y):
global whiteround
global chess_array
global chess_num
global piece_x,piece_y,piece
chess_array.append(list(getpos(pressed_x,pressed_y)))#记录位置,黑棋白棋数组交替
piece_i,piece_j=getrealpos(chess_array[chess_num])#已处理的位置
isempty=if_isempty(piece_i,piece_j)
if isempty==True: #如果这个地方没有棋子
whiteround.append(-whiteround[chess_num])
piece_x.append(piece_i)
piece_y.append(piece_j)
piece.append([piece_i,piece_j])
chess_num+=1
gloval.setval("chess_array", chess_array)
return 1
else: # 如果这个地方有棋子
del chess_array[chess_num] #删除那个重复的数组
return 0
电脑落子的处理步骤和玩家落子相比唯一的不同是不需要处理鼠标点击信息,因为电脑通过算法得到的落子位置就是相对于棋盘的位置,由pc_pressed()得到。
def pc_pos_chess():
global whiteround
global chess_array
global chess_num
global piece_x,piece_y,piece
pc_pressed=easy_pc.find_maxscore(chess_array,whiteround[-1])
chess_array.append(pc_pressed)#记录电脑下棋位置
piece_i,piece_j=getrealpos(chess_array[chess_num])#已处理的位置
isempty=if_isempty(piece_i,piece_j)
print(isempty)
if isempty==True: #如果这个地方没有棋子
whiteround.append(-whiteround[chess_num])
piece_x.append(piece_i)
piece_y.append(piece_j)
piece.append([piece_i,piece_j])
chess_num+=1
gloval.setval("chess_array", chess_array)
else: # 如果这个地方有棋子
del chess_array[chess_num] #删除那个重复的数组
#--coding:utf-8--
from PIL import Image
import pygame as pg
from sys import * #用exit来退出程序
import gloval
gloval.init()
def Image_PreProcessing():
# 图片存储路径
im = Image.open('background.jpeg')
# Resize图片大小,入口参数为一个tuple,为新的图片大小
imBackground = im.resize((424,300))
imBackground.save('1111.jpg','JPEG')
im = Image.open('chessboard.jpeg')
# Resize图片大小,入口参数为一个tuple,为新的图片大小
imBackground = im.resize((540,540))
imBackground.save('new_chessboard.jpg','JPEG')
im = Image.open('chessblack.png')
# Resize图片大小,入口参数为一个tuple,为新的图片大小
imBackground = im.resize((32,32))
imBackground.save('new_chessblack.png','PNG')
im = Image.open('chesswhite.png')
# Resize图片大小,入口参数为一个tuple,为新的图片大小
imBackground = im.resize((32,32))
imBackground.save('new_chesswhite.png','PNG')
def windows():
pg.init() #初始化pygame,为使用硬件做准备
# screen=pg.display.set_mode((1024,768),0,32)#分辨率,标志位,色深
#加载背景和光标图片
gloval.setval('screen', pg.display.set_mode((1024,768),0,32))
gloval.setval('imBackground', pg.image.load('new_background.jpg').convert())
gloval.setval('imChessboard', pg.image.load('new_chessboard.jpg').convert())
gloval.setval('imBlackPiece', pg.image.load('new_chessblack.png').convert_alpha())
gloval.setval('imWhitePiece', pg.image.load('new_chesswhite.png').convert_alpha())
pg.display.set_caption('五子棋 by Ace Cheney') #设置窗口标题
def init():
global glodic
glodic = {}
def setval(name,val):
glodic[name]=val
def getval(name,defva=None):
return glodic[name]
颜色定义:press=(0,0,0),button=(132,71,34)
这一块主要是实现各个游戏状态下的菜单界面以及功能,因为4,5,6号游戏状态菜单相同,所以通过menu4来实现。
def menu1():
screen=gloval.getval('screen')
#画’开始游戏‘,‘游戏说明’,’结束游戏‘按钮
pg.draw.rect(screen,button,[670,260,200,80],5)
pg.draw.rect(screen,button,[670,410,200,80],5)
pg.draw.rect(screen,button,[670,560,200,80],5)
my_font=pg.font.Font('mufont.ttf',45)
text1=my_font.render("开始游戏",True,button)
text2=my_font.render("游戏说明",True,button)
text3=my_font.render("结束游戏",True,button)
screen.blit(text1,(680,270))
screen.blit(text2,(680,420))
screen.blit(text3,(680,570))
def movemenu1():
mouse_x=gloval.getval('mouse_x')
mouse_y=gloval.getval('mouse_y')
screen=gloval.getval('screen')
my_font=pg.font.Font('mufont.ttf',45)
if 670<mouse_x<870 and 260<mouse_y<340:
pg.mouse.set_cursor(*pg.cursors.broken_x)
pg.draw.rect(screen,press,[670,260,200,80],5)
text1=my_font.render("开始游戏",True,press)
screen.blit(text1,(680,270))
elif 670<mouse_x<870 and 410<mouse_y<490:
pg.mouse.set_cursor(*pg.cursors.broken_x)
pg.draw.rect(screen,press,[670,410,200,80],5)
text2=my_font.render("游戏说明",True,press)
screen.blit(text2,(680,420))
elif 670<mouse_x<870 and 560<mouse_y<640:
pg.mouse.set_cursor(*pg.cursors.broken_x)
pg.draw.rect(screen,press,[670,560,200,80],5)
text3=my_font.render("结束游戏",True,press)
screen.blit(text3,(680,570))
else:
pg.mouse.set_cursor(*pg.cursors.arrow)
def pressmenu1():
screen=gloval.getval('screen')
my_font=pg.font.Font('mufont.ttf',45)
pressed_x=gloval.getval('pressed_x')
pressed_y=gloval.getval('pressed_y')
if 670<pressed_x<870 and 260<pressed_y<340:#开始游戏,进入菜单2
gloval.setval('gamestate', 2)
gloval.setval('press_intro', 0)
elif 670<pressed_x<870 and 410<pressed_y<490:#游戏介绍
gloval.setval('press_intro', 1)
elif 670<pressed_x<870 and 560<pressed_y<640:#退出游戏
pg.quit()
exit()
else :
gloval.setval('press_intro', 0)
其他部分原理相同,不再赘述,有特殊功能的特殊解决即可,比如游戏状态二的“返回上级菜单”功能,只需要gloval.setval(‘gamestate’, 1)即可,比如悔棋,只需要gloval.setval(‘press_regret’, 1)即可。
值得注意的是:
#--coding:utf-8--
from PIL import Image
import pygame as pg
from sys import exit #用exit来退出程序
import gloval
import random
gloval.init()
##打分表
tuple_score=[None]*10
tuple_score[0]=7 #没有子
tuple_score[1]=35 #一个己方子
tuple_score[2]=800 #两个己方子
tuple_score[3]=15000 #三个己方子
tuple_score[4]=800000 #四个己方子
tuple_score[5]=15 #一个对方子
tuple_score[6]=400 #两个对方子
tuple_score[7]=8000 #三个对方子
tuple_score[8]=100000 #四个对方子
tuple_score[9]=0 #又有白又有黑
##计算一个空位的分数(需要棋谱数组和空位位置,返回该位置的分数)
def chess_score(array,chess_pos,whiteround):
pos_score=0
x=chess_pos[0]
y=chess_pos[1]
black_num=0
white_num=0
##竖列
for i in range(5):#1234 统计竖列所有五元组的得分总和
for j in range(5):#01234 统计一个五元组的得分
if [x-j+i,y] in array[::2]:#黑子判断 #横向
black_num+=1
if [x-j+i,y] in array[1::2]:#白子判断 #横向
white_num+=1
pos_score=pos_score+chess_tuple_score(black_num, white_num,whiteround)#计算一个元组
white_num=0
black_num=0
##横列
for i in range(5):
for j in range(5):
if [x,y-j+i] in array[::2]:#黑子判断 #横向
black_num+=1
if [x,y-j+i] in array[1::2]:#白子判断 #横向
white_num+=1
pos_score=pos_score+chess_tuple_score(black_num, white_num,whiteround)
white_num=0
black_num=0
##左斜/
for i in range(5):
for j in range(5):
if [x+j-i,y-j+i] in array[::2]:#黑子判断 #横向
black_num+=1
if [x+j-i,y-j+i] in array[1::2]:#白子判断 #横向
white_num+=1
pos_score=pos_score+chess_tuple_score(black_num, white_num, whiteround)
white_num=0
black_num=0
##右斜\
for i in range(5):
for j in range(5):
if [x-j+i,y-j+i] in array[::2]:#黑子判断 #横向
black_num+=1
if [x-j+i,y-j+i] in array[1::2]:#白子判断 #横向
white_num+=1
pos_score=pos_score+chess_tuple_score(black_num, white_num, whiteround)
white_num=0
black_num=0
return pos_score
字面意思,计算一个五连的分数,别忘了在计算之前先判断自己是白子还是黑子,判断方法很简单,在白方回合的白子就是己方子,黑子就是敌方子,反之亦然。
def chess_tuple_score(black_num,white_num,whiteround):
if black_num==0 and white_num==0: #没有子
pos_tuple_score=tuple_score[0]
elif black_num>0 and white_num>0: #又有白又有黑
pos_tuple_score=tuple_score[9]
else: #只有黑或者只有白
if whiteround == -1:
if black_num != 0: #计算横着一格黑子
pos_tuple_score=tuple_score[black_num]
if white_num != 0: #计算横着一格白子
pos_tuple_score=tuple_score[white_num+4]
if whiteround == 1:
if black_num != 0: #计算横着一格黑子
pos_tuple_score=tuple_score[black_num+4]
if white_num != 0: #计算横着一格白子
pos_tuple_score=tuple_score[white_num]
return pos_tuple_score
def find_maxscore(array,whiteround):
if array==[]:
best_pos=[8,8]
else:
chess_score_array=[]
for row in range(1,15):
for col in range(1,15):
chess_pos = [row,col]
if chess_pos not in array:
pos_score=chess_score(array,chess_pos,whiteround)
chess_score_array.append([pos_score, row, col])
chess_score_array.sort(reverse=True)
#随机落子
if chess_score_array[0][0]-chess_score_array[2][0]<50:
choose_pos=random.randint(0,2)
elif chess_score_array[0][0]-chess_score_array[1][0]<100:
choose_pos=random.randint(0,1)
else :
choose_pos=0
pc_pressed_x=chess_score_array[choose_pos][1]
pc_pressed_y=chess_score_array[choose_pos][2]
best_pos=[pc_pressed_x,pc_pressed_y]
#print(best_pos)
print(chess_score_array)
return best_pos
#--coding:utf-8--
from PIL import Image
import pygame as pg
#from pygame.locals import *#导入一些常用的函数和常量
from sys import exit #用exit来退出程序
import easygui
import gloval
gloval.init()
def check_win(chess_array):#黑色白色棋子的索引值列表
press=(0,0,0)
black_array=chess_array[::2]#偶数
white_array=chess_array[1::2]#奇数
screen=gloval.getval('screen')
if five_pieces(black_array)==1:
# 黑方胜利
my_font=pg.font.Font('mufont.ttf',55)
text2=my_font.render("黑方胜利",True,press)
screen.blit(text2,(680,100))
game_end()
if five_pieces(white_array)==1:
# 白方胜利
my_font=pg.font.Font('mufont.ttf',55)
text2=my_font.render("白方胜利",True,press)
screen.blit(text2,(680,100))
game_end()
if len(chess_array)== 225:
# 平局
my_font=pg.font.Font('mufont.ttf',55)
text2=my_font.render("和棋",True,press)
screen.blit(text2,(680,100))
game_end()#状态置七
def five_pieces(array):
# 提取最后一颗棋子,负一
if array:
x=array[-1][0]
y=array[-1][1]
for j in range(1,12):
#竖五连
if [x,j] in array and [x,j+1] in array and [x,j+2] in array and [x,j+3] in array and [x,j+4] in array :
return 1
#横五连
if [j,y] in array and [j+1,y] in array and [j+2,y] in array and [j+3,y] in array and [j+4,y] in array :
return 1
for j in range(5):
#\五连
if [x-j,y-j] in array and [x-j+1,y-j+1] in array and [x-j+2,y-j+2] in array and [x-j+3,y-j+3] in array and [x-j+4,y-j+4] in array :
return 1
#/五连
if [x-j,y+j] in array and [x-j+1,y+j-1] in array and [x-j+2,y+j-2] in array and [x-j+3,y+j-3] in array and [x-j+4,y+j-4] in array :
return 1
return 0
源码及材料已上传CSDN,全剧终,共计两万三千余字。