⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 三子棋.htm

📁 VBSCRIPT的源码,相信很多html程序员都会用到,这些源码小小变动一下,可以用在很多地方,尤其在DHTML中!
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  If Board(5) = PLAYER_NONE Then
     MakeStandardMove = 5
     Exit Function
  End If
  '循环查看边角子,如果没下则下边角子
  For Square = 1 To 9 Step 2     
     If Board(Square) = PLAYER_NONE Then        
        MakeStandardMove = Square
        Exit Function     
     End If
  Next
  '最后,循环其他棋子,还有哪个没下就下哪一个
  For Square = 2 To 8 Step 2
    If Board(Square) = PLAYER_NONE Then        
        MakeStandardMove = Square
        Exit Function    
    End If
  Next
End Function
'如何下出制胜子
Function MakeWinningMove()
'定义临时变量
Dim computersquares 
Dim freesquare 
Dim Square 
Dim i 
 '寻找可以将一行联成三个的制胜子
For Square = 1 To 7 Step 3
  computersquares = 0
  freesquare = 0
    For i = 0 To 2
        Select Case Board(Square + i)
            Case PLAYER_COMPUTER
                 computersquares = computersquares + 1
            Case PLAYER_NONE
                 freesquare = Square + i
        End Select
    Next
    If computersquares = 2 And freesquare <> 0 Then        
           MakeWinningMove = freesquare
           Exit Function
    End If
Next 
'寻找可以将一列联成三个的制胜子
For Square = 1 To 3
  computersquares = 0
  freesquare = 0 
    For i = 0 To 6 Step 3        
        Select Case Board(Square + i)            
            Case PLAYER_COMPUTER
                 computersquares = computersquares + 1
            Case PLAYER_NONE
                 freesquare = Square + i
       End Select
    Next
    If computersquares = 2 And freesquare <> 0 Then       
       MakeWinningMove = freesquare
       Exit Function
    End If
Next
'寻找可以将某个斜边联成三个的制胜子
  computersquares = 0
  freesquare = 0
For i = 1 To 9 Step 4
        Select Case Board(i)            
            Case PLAYER_COMPUTER
                 computersquares = computersquares + 1
            Case PLAYER_NONE
                 freesquare = i
        End Select
    Next
    If computersquares = 2 And freesquare <> 0 Then
       MakeWinningMove = freesquare
       Exit Function
    End If
  computersquares = 0
  freesquare = 0
    For i = 3 To 7 Step 2
        Select Case Board(i)
            Case PLAYER_COMPUTER
                 computersquares = computersquares + 1
            Case PLAYER_NONE
                 freesquare = i
        End Select
    Next
    If computersquares = 2 And freesquare <> 0 Then
       MakeWinningMove = freesquare
       Exit Function
    End If
End Function
'如何下出一步内的救命子
Function MakeSavingMove()

'定义临时变量
Dim humansquares
Dim freesquare
Dim Square
Dim i
 '阻止对方将一行联成三个的救命子
  For Square = 1 To 7 Step 3
  humansquares = 0
  freesquare = 0
   For i = 0 To 2
        Select Case Board(Square + i)
            Case PLAYER_HUMAN
                 humansquares = humansquares + 1
            Case PLAYER_NONE
                 freesquare = Square + i
        End Select
    Next
    If humansquares = 2 And freesquare <> 0 Then
           MakeSavingMove = freesquare
           Exit Function
    End If
  Next
 '阻止对方将一列联成三个的救命子
  For Square = 1 To 3
  humansquares = 0
  freesquare = 0
    For i = 0 To 6 Step 3
        Select Case Board(Square + i)
            Case PLAYER_HUMAN
                 humansquares = humansquares + 1
            Case PLAYER_NONE
                 freesquare = Square + i
        End Select
    Next
    If humansquares = 2 And freesquare <> 0 Then
       MakeSavingMove = freesquare
       Exit Function
    End If
 Next
 '阻止对方将某个对角线联成三个的救命子
  humansquares = 0
  freesquare = 0
    For i = 1 To 9 Step 4
        Select Case Board(i)
            Case PLAYER_HUMAN
                 humansquares = humansquares + 1
            Case PLAYER_NONE
                 freesquare = i
        End Select
    Next
    If humansquares = 2 And freesquare <> 0 Then
       MakeSavingMove = freesquare
       Exit Function
    End If
  humansquares = 0
  freesquare = 0
    For i = 3 To 7 Step 2
        Select Case Board(i)
            Case PLAYER_HUMAN
                 humansquares = humansquares + 1
            Case PLAYER_NONE
                 freesquare = i
        End Select
    Next
    If humansquares = 2 And freesquare <> 0 Then
       MakeSavingMove = freesquare
       Exit Function
    End If
End Function

'如何下出两步内的救命子
Function MakeSavingMove2()
'定义临时变量
Dim pick 
Select Case Board(5) = PLAYER_HUMAN
   '如果中央子是玩家的
   Case True
	   '如果左上角棋子是玩家的
       If Board(1) = PLAYER_HUMAN Then
			'如果左下角棋子是空的
            If Board(7) = PLAYER_NONE Then
              '则下左下角
              pick = 7
            '否则如果正左边的棋子是空的
            ElseIf Board(4) = PLAYER_NONE Then
              '则下正左边
              pick = 4
            End If
       '否则,若右上角的棋子是玩家的
       ElseIf Board(3) = PLAYER_HUMAN Then
            '此时,若右下角是空的
            If Board(9) = PLAYER_NONE Then
              '下右下角
              pick = 9
            '否则若正右边的棋子是空的
            ElseIf Board(6) = PLAYER_NONE Then
              '下正右边
              pick = 6
            End If
       '再否,若左下角棋子是玩家的
       ElseIf Board(7) = PLAYER_HUMAN Then
            '此时,若左上角是空的
            If Board(1) = PLAYER_NONE Then
              '下左上角
              pick = 1
            '否则,若正左边的棋子是空的
            ElseIf Board(4) = PLAYER_NONE Then
              '下正左边
              pick = 4
            End If
       '最后,若右下角的棋子是玩家的
       ElseIf Board(9) = PLAYER_HUMAN Then
            '如果右上角是空的
            If Board(3) = PLAYER_NONE Then
              '下右上角
              pick = 3
            '否则,若正右边棋子为空
            ElseIf Board(6) = PLAYER_NONE Then
              '下正右边
              pick = 6
            End If
       End If
End Select
'下出决定的一步棋   
MakeSavingMove2 = pick
End Function

'如何下出随机子
Function MakeRandomMove()
'定义临时变量
Dim pick
Dim Square
'每次随机一个位置,直到这个位子原来为空
Do Until pick <> 0
 Square = Int(Rnd * 8) + 1
 If Board(Square) = PLAYER_NONE Then pick = Square
Loop
'下出找到的一步
MakeRandomMove = pick
End Function
-->
</script>

<BODY onload="initialize" background="1.jpg">
<table valign = middle align=center>
<tr>
<td>
<h1>传统游戏:三子棋</h1>
</td>
</tr>
<tr>
<td  align=middle>
<img name="square" onclick="clicksquare 1" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 2" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; LEFT: 141px; TOP: 1px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 3" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" ><br>
<img name="square" onclick="clicksquare 4" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 5" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 6" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" ><br>
<img name="square" onclick="clicksquare 7" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 8" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" >
<img name="square" onclick="clicksquare 9" src="blank.jpg" style="BORDER-BOTTOM: lime outset 0.5pt; BORDER-LEFT: lime outset 0.5pt; BORDER-RIGHT: lime outset 0.5pt; BORDER-TOP: lime outset 0.5pt; CURSOR: hand; HEIGHT: 50px; WIDTH: 50px" ><br>
</td>
</tr>
<tr>
<td>
<p><font color=blue>
	<strong>选择玩方:</strong>
    </font>
<input type=button id=playX value="玩家一">
<input type=button id=playO value="玩家二"></p>
<p><font color=blue>
<strong>选择难度:</strong>
</font>
<select id=sel1 onchange="skillLevel=sel1.selectedIndex+1">
<option selected>容 易
<option>一 般
<option>最 难
</select></p>
<p><font color=blue>
<strong>信息提示:</strong>
</font>
<input id=msg ></p>
<p><font color=blue>
<strong>重新开始:
<input type=button id=restr onclick="initialize" value="重新开始">
</strong>
</font>
</p>
</td>
</tr>
</table>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -