●若双方已经分出胜负,则显示胜方及连成五子的第一颗棋子的位置(行号及列号)。
●若双方未分出胜负,则显示当前状态下将下棋的一方。
Constn= 10
Dim s(1 To 400) As String
Private Sub Command1_ Click)
‘读取棋盘数据存储在数组s中,●表示黑子,o表示白子,o表示空位,代码略
End Sub
Private Sub Command2_ Click()
Dim i As Integer, j As Integer, fag As Boolean
flag= False:i= 1
Do While i <= n And flag = False
For j= 1 Ton
If Then flag = True: Exit For
Next j
i=i+ 1
Loop
i=i- 1
If flag Then
If (i-1)*n+j) = "o" Then
Label1.Caption = "白方胜" + Str(i) + Str(j)
Else
Label1.Caption = "黑方胜" + St(i) + Str(j)
End If
Else
If counts() Then Label1.Caption="黑方下" Else Label1.Caption ="白方下"
End If
End Sub
Function judge(x As Integer, y As Integer) As Boolean
Dim dx(1 To 4) As Integer, dy(1 To 4) As Integer
Dim flag As Boolean,j As Integer, i As Integer, ux As Integer, uy As Integer
dx(1)= 1: dx(2)= 1: dx(3)= 1:dx(4)= 0
dy(1)= 1: dy(2)= 0: dy(3)=-1: dy(4)= I
flag = False:i= 1
If s((x-1)*n+y) <> "o" Then
Do While i<= 4 And flag = False
flag = True
For j= 1 To 4
ux= dx(i)*j+x
uy=dy(i)*j+y
If Not (ux>= 1 And ux <= nAnd uy>= I And uy <= n) Then flag = False: Exit For
If Then flag = False: Exit For
Next j
i=i+ 1
Loop
End If
judge = flag
End Function
Function counts() As Boolean
Dim iAs Integer, j As Integer, white As Integer, black As Integer
counts = False:white = 0: black= 0
For i=1 To n
For j= 1 Ton
If(i-1)* n+j)= "o" Then white = white+ 1
If((i-1)*n+j)= "●" Then black = black + 1
Next j
Next i
If Then counts = True
End Function