China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-21 00:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Gobang Man-machine Battle Batch Game View 13,554 Replies 73
Floor 16 Posted 2009-05-09 20:29 ·  中国 广东 深圳 电信
新手上路
Credits 15
Posts 6
Joined 2007-04-12 22:41
19-year member
UID 84916
Gender Male
Status Offline
This is quite amazing. I don't understand it, but it's fun to play.
Floor 17 Posted 2009-05-10 07:24 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I copy zh159



If Not (IsObject(Navigator)) Then
Dim Ie
Set Ie=WScript.CreateObject("InternetExplorer.Application","Event_")
'Msgbox "WSH"
MainF()
Else
'Msgbox "IEE"
End IF


Sub MainF()

Path="file://" & WScript.ScriptFullName


With Ie
.Navigate ("about:blank")
.Document.Write ("<Script Language=VBScript Src=""" & Path & """></Script><Script Langage=JavaScript></Script>") 'Content to be written
.Document.Write ("<style>.GUIwh{width:24;height:24;cursor:hand;}</style><Body></Body>")


'Window size\position
.Width = 660 'Width
.Height = 550 'Height
.Resizable = 0 'Do not allow users to change window size'
.Left = Fix((.Document.ParentWindow.Screen.AvailWidth-.Width)/2) 'Horizontally centered
.Top = Fix((.Document.ParentWindow.Screen.AvailHeight-.Height)/2) 'Vertically centered


.Document.Title = " " 'Title
.Document.Body.Scroll = "no" 'Close scroll bar
.Document.Body.OnconTextMenu = GetRef("Disabled") 'Disable right click
.Document.Body.OnSelectStart = GetRef("Disabled") 'Disable selection
.Document.Body.Style.CssText = "background: SteelBlue ;color:#ffffff;"
.Document.Body.InnerHtml = "<table id=aT><tr><td><TABLE id=bT></TABLE></td><td id=sD></td></tr></table>"
.Document.ParentWindow.ExecScript "build(19)","VBScript"
With.Document.Body.All
.aT.Align = "Center"
.aT.Width = "630"
.aT.Border = "1"
.aT.BorderColor = "#ffffff"
.aT.CellSpacing = "0"
.aT.CellPadding = "10"
.aT.Style.CssText = "font: 13px SimSun;border-collapse:collapse;"

.aT.Rows(0).Align = "Center"
.aT.Rows(0).Cells(0).Width = "450"
.aT.Rows(0).Cells(0).Height = "450"

.bT.Align = "Center"
.bT.Border = "0"
.bT.BorderColor = "#ffffff"
.bT.CellSpacing = "0"
.bT.CellPadding = "0"
.bT.Style.CssText = "font: 21px SimSun;border:2px solid #ffffff;"
End With


'Form
'.FullScreen=1
.MenuBar = 0 'Cancel menu bar'
.AddressBar = 0 'Cancel address bar'
.ToolBar = 0 'Cancel toolbar'
.StatusBar = 0 'Cancel status bar'
.Visible = 1 'Show IE page'
Set window=.Document.ParentWindow
End With
'.Document.OnClick = GetRef("Test1")
'window.ExecScript "fun()","VBScript"
'Ie.Document.ParentWindow.ExecScript "build(19)","VBScript"


Do
WScript.Sleep 200
Loop

End Sub


Function Test1()
'msgbox "event_boundElements"
End Function

Function Disabled()
Disabled=True
End Function

Function Event_OnQuit()
WScript.Quit
End Function


Function Build(N)
PS=N-1
While (S < N)
If S <= 1 Then charA=chr(43440):charB=chr(43472):charC=chr(43444)
If S >= 1 Then charA=chr(43456):charB=chr(43488):charC=chr(43464)
If S = PS Then charA=chr(43448):charB=chr(43480):charC=chr(43452)
Document.All.bT.insertrow(S)
For j = 0 To PS
If ((S*N+j) Mod PS) = (S Mod PS) Then
Char=charA:charA=charC
Else
Char=charB
End If

Document.All.bT.Rows(S).insertcell(j)
Document.All.bT.Rows(S).Cells(j).ID = S*N+j
Document.All.bT.Rows(S).Cells(j).CLASSName = "GUIwh"
Document.All.bT.Rows(S).Cells(j).InnerHtml = "<span onclick=Ts(this) onMouseOver='innerText=""" &chr(41457)& """;style.color=""blue""' onMouseOut='innerText=""" &chr(43488)& """;style.color=""""'>" &char& "</span>"
'Document.All.bT.Rows(S).Cells(j).InnerHtml = "<span id=mm onclick='Ts(this)' onMouseOver='innerText=X' onMouseOut='innerText=Y'>+</span>"
Next
S=S+1
Wend
End Function

Function Ts(this)

msgbox this.ParentNode.ID

this.parentNode.style.cursor = "default"
this.parentNode.innerHtml = chr(41457)
'PC.style.display = "none"

End Function


Function fun()
Msgbox "this is fun!"
End Function

Haha
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 18 Posted 2009-05-10 13:50 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The code can only be used when IE browser is the default one, and there is a bug: after the mouse moves away from the edge checkerboard, it does not return to the appearance of the edge checkerboard, but becomes the appearance of the middle checkerboard.
Floor 19 Posted 2009-05-10 13:56 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Re: 17th floor
What's the file extension for saving? I can't run it. I've tried.vbs,.js,.html,.bat and none of them work.
精简
=> 个人网志
Floor 20 Posted 2009-05-10 23:19 ·  新加坡
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
System: XP SP2 EN
Default browser: IE 6
Attachments
2009-05-11_100903.png
Floor 21 Posted 2009-05-11 02:21 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Originally posted by zh159 at 2009-5-10 01:50 PM:
The code of the previous poster can only be used when IE is the default browser, and there is a bug: after the mouse moves away from the edge checkerboard, it does not return to the appearance of the edge checkerboard, but becomes the appearance of the middle checkerboard



Copied incorrectly, haha
The text for the mouseout event should be char, I didn't look at the code you replaced later and directly filled it with +
This script I modified also works normally with the default browser
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 22 Posted 2009-05-11 02:21 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 23 Posted 2009-05-11 02:23 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I also encountered this error. It turned out to be caused by several double-byte symbols in the script. I changed them to cha(ascii) to solve it. Maybe it's because your system is in English version.
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 24 Posted 2009-05-11 08:56 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Can you modify the code to make it compatible with both Chinese and English systems at the same time?
Floor 25 Posted 2009-05-11 10:44 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I can't see the specific content of "?????", so I can't complete the full translation. Please provide the complete content with the specific characters.
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 26 Posted 2009-05-11 11:38 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
After struggling for a long time, I wrote the following code, which is mainly used to obtain the horizontal, vertical, diagonal, and anti-diagonal lines of the Gobang move coordinates.

My idea is that the computer does not compare the entire chessboard, but judges the risk of five in a row in four lines following the opponent's move. It only reaches extracting the four-line array.

Using a one-dimensional array, if the chessboard is two-dimensional, it can be converted to one-dimensional using row number * total columns (19) + column number. Because it is convenient to identify four lines with a one-dimensional array, the horizontal line steps by 1, the vertical line steps by 19, the diagonal line steps by 18, and the anti-diagonal line steps by 20.

For the relationship of coordinates, you can use the following code to observe:

Display two-dimensional coordinates

@echo off
setlocal enabledelayedexpansion
mode con: lines=100 cols=100
for /l %%i in (0,1,18) do (
for /l %%j in (0,1,18) do (
if %%i LSS 10 set x=0
if %%j LSS 10 set y=0
set/p=!x!%%i!y!%%j <nul
set x=&set y=
)
echo.
)

pause


Display one-dimensional coordinates

@echo off
setlocal enabledelayedexpansion
for /l %%i in (0,1,18) do (
for /l %%j in (0,1,18) do (
set /a f=%%i*19+%%j
if !f! LSS 10 set f=0!f!
if !f! Lss 100 set f=0!f!
call set /p =%%f%% <nul
)
echo.
)

pause




Const N = 19
Const msg = 1
If Ucase(Right(WScript.FullName,11)) = "WSCRIPT.EXE" Then
CreateObject("WScript.Shell").Run "Cmd.exe /K Cscript """ & Wscript.ScriptFullName & """"
WScript.Quit
End If

ReDim arry(N*N-1)


For i =0 To N*N-1
arry(i)=i
Next

Function PriArry()
For i = 0 To 18
For j = 0 To 18
k="00"
If i*N+j > 9 Then k="0"
If i*N+j > 99 Then k=""
s=s & k & arry(i*N+j) & " "
Next
p s
s=""
Next
End Function


While True
PriArry
p xypn(gcon)
Wend

Function xypn(a)
M=N-1 'Custom coordinate Standard x_ord * total columns + standard y_ord
x_ord = a\N 'Horizontal standard coordinate Custom coordinate / total columns
y_ord = a Mod N 'Vertical standard coordinate Remainder of custom coordinate / total columns
x_base_value = x_ord*N 'Row start coordinate value of the coordinate (row number * total columns)
y_base_value = a-x_base_value 'Column start coordinate value of the coordinate (coordinate value - row start coordinate value)

For i = 0 To N-1
hen=hen & x_base_value+i & " " 'Horizontal line = row start coordinate value (x_base_value) incremented by 1 to the end of the row
shu=shu & y_base_value+i*N & " " 'Vertical line = column start coordinate value (y_base_value) incremented by N to the end of the column
Next
str = "Horizontal:" & hen & vbCrLf & "Vertical:" & shu & vcCrLf

px_ord = (Abs(x_ord+y_ord-M)+(x_ord+y_ord-M))\2 'Diagonal line start standard coordinate x ((standard x + y) > 18)?(px_ord=(x+y) mod 18):(0)
py_ord = x_ord+y_ord-px_ord 'Diagonal line start standard coordinate y ((standard x + y) > 18)?(x+y-px_ord):(x+y)
p_base_value = px_ord*N+py_ord 'Diagonal line start custom coordinate value Standard x_ord * total columns + standard y_ord

For i = 0 To py_ord-px_ord 'Diagonal line length is py_ord-px_ord
pie=pie & p_base_value+i*(N-1) & " " 'Diagonal line self-increment is N-1
Next
str = str & vbCrLf & "Diagonal:" & pie & vbCrLf

nx_ord = (Abs(x_ord-y_ord)+(x_ord-y_ord))\2 'Anti-diagonal line start standard coordinate x nx_ord=((x_ord-y_ord) > 0)?(x_ord-y_ord):(0)
ny_ord = (x_ord-y_ord)*(Sgn(x_ord-y_ord)-1)\2 'Anti-diagonal line start standard coordinate y ny_ord=((x_ord-y_ord) < 0)?(x_ord-y_ord):(0)
n_base_value = nx_ord*N+ny_ord 'Anti-diagonal line start custom coordinate value Standard x_ord * total columns + standard y_ord

For i = 0 To 18-nx_ord-ny_ord 'Anti-diagonal line length is 18-(nx_ord+ny_ord)
na = na & n_base_value+i*(N+1) & " " 'Anti-diagonal line self-increment is N+1
Next
str = str & "Anti-diagonal:" & na
xypn=str
End Function

Function p(str)
If msg Then WScript.Echo str Else InputBox "","",str
End Function

Function gcon()
gcon=WScript.StdIn.ReadLine
End Function


49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 27 Posted 2009-05-11 12:17 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Whether using the two-dimensional coordinate method or the one-dimensional cross-marking method, in the end, it is still necessary to perform string grouping and then match with the rule string. Because when performing rule string matching, it is done by string. Actually, it would be better to define display cache, horizontal, vertical,撇, and 捺 as array strings. There is no need to perform multiple string grouping operations.

The computer side makes a move according to the matched optimal rule string. According to which array (horizontal/vertical/撇/捺) and which string in which array and which character position it is matched, it can be converted into the actual coordinates.

Because five arrays are defined, as long as one move is made, the corresponding positions of these five arrays need to be replaced respectively. Each array only needs to replace one character in a row.

Displaying by row unit is definitely much faster than displaying by character unit. Because the video memory string method is used, it can be directly displayed by row unit.
精简
=> 个人网志
Floor 28 Posted 2009-05-11 12:42 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
My idea is that the computer does not compare the entire chessboard, but follows the opponent's move to judge whether there is a five-in-a-row risk in the four rows where the move is made

In this case, is the computer's playing strength too weak? Usually, the Gomoku algorithm sorts the possible situations for both sides in the next step (like four-three, double-three, etc.) in order of priority, and then selects the landing point with the highest priority.
Floor 29 Posted 2009-05-12 08:09 ·  中国 北京 电信
初级用户
Credits 23
Posts 15
Joined 2009-05-06 22:31
17-year member
UID 144510
Gender Male
Status Offline
That's amazing, batch processing also has such powerful functions!
Floor 30 Posted 2009-05-12 08:33 ·  中国 广东 广州 天河区 电信
初级用户
Credits 31
Posts 16
Joined 2009-05-06 04:32
17-year member
UID 144467
Gender Male
Status Offline
Originally posted by rubble at 2009-5-12 08:09:
It's so amazing that batch processing can have such powerful functions!

I really didn't expect to come up with this thing, but I find the code hard to understand.
SNSB is Not Simply a Biologist!
Forum Jump: