当前位置: 高中信息技术 / 综合题
  • 1. (2021·柯桥模拟) 五子棋游戏规则:⒈对局双方各执一色棋子(黑和白);⒉每局黑方先下:⒊双方交替下子,每次只能下一子:⒋当一方棋子先连成五子即获胜(即横、竖或斜任意一个方向均可)。编写一个VB程序,单击“读取”按钮Command1读取五子棋某个状态的棋盘数据,单击“判断”按钮Command2,显示判断结果。运行界面如图所示:

    ●若双方已经分出胜负,则显示胜方及连成五子的第一颗棋子的位置(行号及列号)。

    ●若双方未分出胜负,则显示当前状态下将下棋的一方。

    1. (1) 若棋盘上的黑白棋子数量不相等时,则将下子的一方是
    2. (2) 编写如下VB程序,请在划线处填入合适的代码。

      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

微信扫码预览、分享更方便