|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
     『楼 主』:
[原创]五子棋人机对战批处理游戏
使用 LLM 解释/回答一下
这个批处理花了我两天时间,所以打上了原创。
我还在批处理之家发表有这个批处理,若还有与其它贴子雷同,纯属巧合。
欢迎大家指正,谢谢。
41楼
增加了背景音乐《春江花月夜》,如高山流水般的声音,听着下五棋子,太爽了,包含播放代码及音乐文件仅96K。
鼠标操作版
50楼
最新在60楼 2009.8.1
@echo off&setlocal enabledelayedexpansion
set li0=┌───────────────────┐
set li1=│┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐│1
for /l %%a in (2,1,18) do (set li%%a=│├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤│%%a)
set li19=│└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘│19
set li20=└───────────────────┘
set li21= A B C D E F G H I J K L M N O P Q R S
for %%a in (%li21%) do (set/a .+=1,%%a=.&set z!.!=%%a)
set z0= &set z20= &set "z21= "
set li5=!li5! 五 棋 子 人 机 对 战
set li7=!li7! 批 处 理
set li9=!li9! 电 脑 水 平 中 等
set li12=!li12! 由 netbenton 编写完成
set li14=!li14! 棋盘设计参照了 batman
title 批处理五子棋
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :eof
if /i "!var!" equ "W" (set zhi=●) else (set zhi=○)
echo.
:loop
if %zhi% equ ● goto :men
set .=&set put1=
for %%a in (!idea!) do (
for %%b in (he sh) do (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
for %%b in (pi ni) do (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
if defined put1 set put=%%a&goto :get
)
echo. 已经和棋了
pause
goto :restart
:men
for /l %%a in (0,1,21) do (echo !z%%a!!li%%a!)
set /p user=:
echo.
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" exit
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-8-3 at 06:06 ]
This batch script took me two days, so I marked it as original.
I also posted this batch script on Batch Processing Home. If there is any similarity with other posts, it's purely coincidental.
Welcome everyone to point out mistakes, thank you.
Post 41
Added background music "Spring River Flowers and Moonlight", a sound like flowing water on a mountain, it's so cool to play Go while listening, including the playback code and music file is only 96K.
Mouse operation version
Post 50
Latest at post 60 2009.8.1
@echo off&setlocal enabledelayedexpansion
set li0=┌───────────────────┐
set li1=│┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐│1
for /l %%a in (2,1,18) do (set li%%a=│├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤│%%a)
set li19=│└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘│19
set li20=└───────────────────┘
set li21= A B C D E F G H I J K L M N O P Q R S
for %%a in (%li21%) do (set/a .+=1,%%a=.&set z!.!=%%a)
set z0= &set z20= &set "z21= "
set li5=!li5! Five Chess Pieces Human-Computer Battle
set li7=!li7! Batch Processing
set li9=!li9! Computer Level Medium
set li12=!li12! Written by netbenton
set li14=!li14! Chessboard design refers to batman
title Batch Processing Go
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :eof
if /i "!var!" equ "W" (set zhi=●) else (set zhi=○)
echo.
:loop
if %zhi% equ ● goto :men
set .=&set put1=
for %%a in (!idea!) do (
for %%b in (he sh) do (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
for %%b in (pi ni) do (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
if defined put1 set put=%%a&goto :get
)
echo. It's a draw
pause
goto :restart
:men
for /l %%a in (0,1,21) do (echo !z%%a!!li%%a!)
set /p user=:
echo.
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" exit
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-8-3 at 06:06 ]
此帖被 +77 点积分 点击查看详情 评分人:【 zh159 】 | 分数: +20 | 时间:2009-5-5 21:04 | 评分人:【 konkoo 】 | 分数: +2 | 时间:2009-5-6 04:33 | 评分人:【 jmz573515 】 | 分数: +15 | 时间:2009-5-6 08:53 | 评分人:【 everest79 】 | 分数: +15 | 时间:2009-5-7 04:48 | 评分人:【 wxcute 】 | 分数: +4 | 时间:2009-5-10 01:40 | 评分人:【 THENEWLIFE 】 | 分数: +2 | 时间:2009-6-2 22:51 | 评分人:【 523066680 】 | 分数: +15 | 时间:2009-6-3 05:39 | 评分人:【 clamber 】 | 分数: +2 | 时间:2010-1-19 21:52 | 评分人:【 sl543001 】 | 分数: +2 | 时间:2010-1-19 23:47 |
|
|

精简
=> 个人 网志  |
|
2009-5-5 12:41 |
|
|
sexfio
社区乞丐
积分 -27
发帖 45
注册 2006-5-16
状态 离线
|
 『第 2 楼』:
使用 LLM 解释/回答一下
太精彩了,要能写出vbs的就好了,因为批处理我看不大懂
提个建议,棋盘搞大点,棋子用红 黄色比较好,文字搞小点,还有列数数字和线没对齐
还有电脑第一步棋走的离谱,我下中间,他跑边上下了一个<img src="images/smilies/face-smile-big.png" align="absmiddle" border="0">
Last edited by sexfio on 2009-5-5 at 12:49 ]
That's wonderful. It would be great if there was a VBS version, because I don't understand batch processing very well.
Put forward a suggestion: Make the chessboard larger, use red and yellow for the chess pieces, make the text smaller, and there's a misalignment between the column numbers and the lines.
Also, the computer's first move was absurd. I played in the center, and it went to the side and placed one piece there. :D
[[i] Last edited by sexfio on 2009-5-5 at 12:49 [/i]]
|
|
2009-5-5 12:47 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
要做成红黄的话,得用到三方,将就一点吧!
如果是为了显示好看一点的话,正准备改进,如果还要增加行列的话,就不必了,19X19下完一盘(和棋)也要不少时间了。
五子棋吗,并非要走到一起的,只要能五个一串,就算赢了。才一个子,电脑没有必要马上就堵的。
看过了一些五子棋的资料,发现原来是我对五子棋子解得太少了,
这人批处理的棋术真的是太低了。
Last edited by netbenton on 2009-5-10 at 08:38 ]
To make it red and yellow, three parties need to be used. Let's make do with it!
If it's for a better display, I'm preparing to improve it. If we need to add more rows and columns, there's no need. It takes quite a while to finish a game (a draw) with 19x19.
For Gobang, it's not necessary for the pieces to be together. As long as five are in a row, it's a win. With just one piece, the computer doesn't need to block immediately.
After reading some Gobang materials, I found that I solved too few Gobang pieces.
This batch processing chess skill is really too low.
Last edited by netbenton on 2009-5-10 at 08:38 ]
|

精简
=> 个人 网志  |
|
2009-5-5 12:55 |
|
|
provem
初级用户
 
积分 92
发帖 82
注册 2007-11-13
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
建议使用第三方工具 cmos 支持鼠标
It is suggested to use a third - party tool to support the mouse in CMOS.
|
|
2009-5-5 22:05 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
|
2009-5-6 08:54 |
|
|
wishpopo
新手上路

积分 18
发帖 20
注册 2008-10-28
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
很不错 ,没想到 可以这样设计电脑的智商 学习了
Not bad. I didn't expect that the intelligence of the computer could be designed like this. Learned it.
|
|
2009-5-6 10:02 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
    『第 7 楼』:
使用 LLM 解释/回答一下
应2楼的一点意见,已经把棋盘搞大一点了
同时增加了悔棋功能,增加了音效,
把系统提示放到了更合理的地方,
并增加了一点电脑方的棋艺,
增加了电脑方最后一步特别显示
5.10 修改:固定为黑子先手,第一手固定下在天元 JJ10 位置
5.17 修改:增强了电脑方的IQ
5.21 修改:完善了电脑方IQ,并在有多个等效位置下时,随机取位,可玩性提高了,也因为随机,所以玩家不一定能下赢电脑,电脑也不会必胜。
6.2 小修改。
@echo off&setlocal enabledelayedexpansion
mode con: lines=43 cols=110
set li39= A B C D E F G H I J K L M N O P Q R S
set li0= ┌─────────────────────────────────────┐
set li1=A│┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐│A
set var=1
for %%a in (!li39:~5^,-1!) do (set/a var+=2&set li!var!=%%a│├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤│%%a)
for /l %%a in (2,2,36) do (set li%%a= ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││)
set li37=S│└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘│S
set li38= └─────────────────────────────────────┘
set str=a b c d e f g h i j k l m n o p q r s
for %%a in (%str%) do (set/a .+=1,%%a=.&set z!.!=%%a)
set li5=!li5! 五 棋 子 人 机 对 战
set li7=!li7! 批 处 理
set li10=!li10! 电 脑 水 平 中 等
set li31=!li31! 由 netbenton 编写完成
set li33=!li33! 棋盘设计参照了 batman
title 批处理五子棋
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :quit
if /i "!var!" equ "D" (set onez=○&set towz=●&set hou=☆) else (set onez=●&set towz=○&set hou=★)
set a!onez!=电脑&set a!towz!=玩家
)
(
set ttr=!idea:@=%onez%!&set ttr=!ttr:$=%towz%!
set idea=
for %%a in (!ttr!) do (
for /f "tokens=1,2 delims=." %%b in ("%%a") do (set %%b=%%c&set idea=!idea! %%b)
)
set ttr=
set li27=!li27! !onez! !a%onez%!
set li25=!li25! !towz! !a%towz%!
set/a pos=10,poh=10&goto :getok
)
:loop
(if %zhi% equ %onez% goto :men
set .=
setlocal enabledelayedexpansion
for %%a in (!idea!) do (
set str=%%a
if "!str:~,2!" neq "vs" (
for %%b in (he sh) do (
set all=!%%b1!!%%b2!!%%b3!!%%b4!!%%b5!!%%b6!!%%b7!!%%b8!!%%b9!!%%b10!!%%b11!!%%b12!!%%b13!!%%b14!!%%b15!!%%b16!!%%b17!!%%b18!!%%b19!
if "!all:%%a=!" neq "!all!" (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c.%%a.!iqam!
)
) )
for %%b in (pi ni) do (
set all=!%%b5!!%%b6!!%%b7!!%%b8!!%%b9!!%%b10!!%%b11!!%%b12!!%%b13!!%%b14!!%%b15!!%%b16!!%%b17!!%%b18!!%%b19!!%%b20!!%%b21!!%%b22!!%%b23!!%%b24!!%%b25!!%%b26!!%%b27!!%%b28!!%%b29!!%%b30!!%%b31!!%%b32!!%%b33!
if "!all:%%a=!" neq "!all!" (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c.%%a.!iqam!
)
) )
) else (
set/a "iqam=(iqam+1)/8"
if %%a equ vs8 if defined . goto :get
if %%a equ vs9 if defined . goto :get
)
))
if defined . (goto :get)
echo. 已经和棋了
pause
endlocal&goto :restart
:men
(
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%hou%!%%b:~%%c!)
set li38=!li38!
cls
for /l %%a in (0,1,39) do (echo !li%%a!)
for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%zhi%!%%b:~%%c!)
set li38=%li38%
set /p user=!say:say=%error%! :
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" goto :quit
if "!user!" equ "back" call :悔&goto :men
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-6-2 at 09:52 ]
In response to a comment from user 2, the chessboard has been enlarged.
At the same time, a move - undo function has been added, sound effects have been added, the system prompt has been placed in a more reasonable place, and a little bit of chess - playing skill for the computer side has been increased, and a special display for the computer side's last move has been added.
May 10 modification: Fixed that black pieces go first, and the first move is fixed to be placed at the Tianyuan position JJ10.
May 17 modification: Enhanced the computer's IQ.
May 21 modification: Perfected the computer's IQ, and when there are multiple equivalent positions, it selects positions randomly. The playability has been improved, and also because of the randomness, so players don't necessarily win against the computer, and the computer doesn't necessarily win.
June 2 minor modification.
@echo off&setlocal enabledelayedexpansion
mode con: lines=43 cols=110
set li39= A B C D E F G H I J K L M N O P Q R S
set li0= ┌─────────────────────────────────────┐
set li1=A│┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐│A
set var=1
for %%a in (!li39:~5^,-1!) do (set/a var+=2&set li!var!=%%a│├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤│%%a)
for /l %%a in (2,2,36) do (set li%%a= ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││)
set li37=S│└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘│S
set li38= └─────────────────────────────────────┘
set str=a b c d e f g h i j k l m n o p q r s
for %%a in (%str%) do (set/a .+=1,%%a=.&set z!.!=%%a)
set li5=!li5! 五 棋 子 人 机 对 战
set li7=!li7! 批 处 理
set li10=!li10! 电 脑 水 平 中 等
set li31=!li31! 由 netbenton 编写完成
set li33=!li33! 棋盘设计参照了 batman
title 批处理五子棋
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :quit
if /i "!var!" equ "D" (set onez=○&set towz=●&set hou=☆) else (set onez=●&set towz=○&set hou=★)
set a!onez!=电脑&set a!towz!=玩家
)
(
set ttr=!idea:@=%onez%!&set ttr=!ttr:$=%towz%!
set idea=
for %%a in (!ttr!) do (
for /f "tokens=1,2 delims=." %%b in ("%%a") do (set %%b=%%c&set idea=!idea! %%b)
)
set ttr=
set li27=!li27! !onez! !a%onez%!
set li25=!li25! !towz! !a%towz%!
set/a pos=10,poh=10&goto :getok
)
:loop
(if %zhi% equ %onez% goto :men
set .=
setlocal enabledelayedexpansion
for %%a in (!idea!) do (
set str=%%a
if "!str:~,2!" neq "vs" (
for %%b in (he sh) do (
set all=!%%b1!!%%b2!!%%b3!!%%b4!!%%b5!!%%b6!!%%b7!!%%b8!!%%b9!!%%b10!!%%b11!!%%b12!!%%b13!!%%b14!!%%b15!!%%b16!!%%b17!!%%b18!!%%b19!
if "!all:%%a=!" neq "!all!" (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c.%%a.!iqam!
)
) )
for %%b in (pi ni) do (
set all=!%%b5!!%%b6!!%%b7!!%%b8!!%%b9!!%%b10!!%%b11!!%%b12!!%%b13!!%%b14!!%%b15!!%%b16!!%%b17!!%%b18!!%%b19!!%%b20!!%%b21!!%%b22!!%%b23!!%%b24!!%%b25!!%%b26!!%%b27!!%%b28!!%%b29!!%%b30!!%%b31!!%%b32!!%%b33!
if "!all:%%a=!" neq "!all!" (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c.%%a.!iqam!
)
) )
) else (
set/a "iqam=(iqam+1)/8"
if %%a equ vs8 if defined . goto :get
if %%a equ vs9 if defined . goto :get
)
))
if defined . (goto :get)
echo. 已经和棋了
pause
endlocal&goto :restart
:men
(
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%hou%!%%b:~%%c!)
set li38=!li38!
cls
for /l %%a in (0,1,39) do (echo !li%%a!)
for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%zhi%!%%b:~%%c!)
set li38=%li38%
set /p user=!say:say=%error%! :
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" goto :quit
if "!user!" equ "back" call :悔&goto :men
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-6-2 at 09:52 ]
此帖被 +67 点积分 点击查看详情 评分人:【 yishanju 】 | 分数: +15 | 时间:2009-5-6 16:59 | 评分人:【 moniuming 】 | 分数: +15 | 时间:2009-5-8 04:49 | 评分人:【 s11ss 】 | 分数: +15 | 时间:2009-5-8 05:57 | 评分人:【 zh159 】 | 分数: +20 | 时间:2009-5-8 12:20 | 评分人:【 516526966 】 | 分数: +2 | 时间:2009-5-18 03:01 |
|
|

精简
=> 个人 网志  |
|
2009-5-6 10:23 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
真的真的很漂亮,震撼了
Really, really beautiful, it's stunning
|

有问题请发论坛或者自行搜索,再短消息问我的统统是SB |
|
2009-5-6 16:59 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
建议把这算法转为VBS或JS,可以用在HTA里面,支持鼠标点击,界面也会更漂亮
It is suggested to convert this algorithm to VBS or JS, which can be used in HTA, support mouse clicks, and the interface will be more beautiful
|

 |
|
2009-5-7 13:53 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
re 9楼
我对vbs 没有深入了解,哪位有兴趣的就写一下。
其实做五子棋游戏并不难,用其它语言,早就有相当漂亮的五子棋了,只是在纯批下做时要一点技巧。可是有一点,无论做得如何好,是比不上真正的图形界面的。
re 4楼
也想过用三方来支持鼠标操作,但这个游戏只有几K,如果为了鼠标操作而用到一个几百K的三方,我认为不划算。如果可以用vbs,js,或其它系统自带的脚本语言来做的话,那还差不多。
用键盘有用键盘的好,可以在玩的过程中,无意识的在练习盲打。
re 9th floor
I don't have an in-depth understanding of VBS. Anyone who is interested can write it.
In fact, making a Gobang game is not difficult. With other languages, there are already quite beautiful Gobang games. It's just that some skills are needed when doing it in pure batch. But there is one point, no matter how good it is made, it can't compare with the real graphical interface.
re 4th floor
I also thought about using third parties to support mouse operation, but this game is only a few KB. If I use a third party of hundreds of KB for mouse operation, I don't think it's cost-effective. If it can be done with VBS, JS, or other system-built-in scripting languages, then it's almost okay.
Using the keyboard has the advantages of using the keyboard. You can unconsciously practice blind typing while playing.
|

精简
=> 个人 网志  |
|
2009-5-8 02:13 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
有空讲解下,我都看不懂
There is nothing to translate here as the input is in Chinese but the content is just "有空讲解下,我都看不懂" which translates to "There is time to explain, I can't understand it all". But since the task is to just return the translated text as is, and in this case the English translation is "There is time to explain, I can't understand it all" but let's just present it directly:
There is time to explain, I can't understand it all
|

49206C6F766520796F752067757973 54656C3A3133383238343036373837 |
|
2009-5-8 12:00 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
有空讲解下算法,看看如何转为VBS
Got some free time to explain an algorithm and see how to convert it to VBS?
|

 |
|
2009-5-8 12:20 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
    『第 13 楼』:
使用 LLM 解释/回答一下
::算法是利用了批处理的变量名可变,
::在定义变量和使用时,变量名也是数据的一部分,不知vbs可不可以这样
::已经在主要的地方加了注释了。
@echo off&setlocal enabledelayedexpansion
mode con: lines=43 cols=110
set li39= A B C D E F G H I J K L M N O P Q R S
set li0= ┌─────────────────────────────────────┐
set li1=A│┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐│A
set var=1
for %%a in (!li39:~5^,-1!) do (set/a var+=2&set li!var!=%%a│├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤│%%a)
for /l %%a in (2,2,36) do (set li%%a= ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││)
set li37=S│└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘│S
set li38= └─────────────────────────────────────┘`
rem 前面定义棋盘布局数组li0~li39,相当于显示缓存
set str=a b c d e f g h i j k l m n o p q r s
for %%a in (%str%) do (set/a .+=1,%%a=.&set z!.!=%%a)
rem 定义字母与数值互换对等变量如:a=1 z1=a
rem 此处定义后面有多个地方用到
set li5=!li5! 五 棋 子 人 机 对 战
set li7=!li7! 批 处 理
set li10=!li10! 电 脑 水 平 中 等
set li31=!li31! 由 netbenton 编写完成
set li33=!li33! 棋盘设计参照了 batman
title 批处理五子棋
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :eof
if /i "!var!" equ "W" (set zhi=●) else (set zhi=○)
echo.
rem 完全由%zhi%这个变量来制轮到哪一方下子
:loop
(if %zhi% equ ● goto :men
set .=
for %%a in (!idea!) do (
for %%b in (he sh) do (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
for %%b in (pi ni) do (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
if defined . set put=%%a&goto :get
))
rem rem 根据前面定义的idea规则,搜索所有横竖撇倷串,取到最前的匹配后跳出,
rem rem 完全没有匹配的,说明已经和棋了
echo. 已经和棋了
pause
endlocal&goto :restart
:men
(
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!★!%%b:~%%c!)
set li38=!li38:`=!
cls
for /l %%a in (0,1,39) do (echo !li%%a!)
rem rem 把缓存显示到屏幕
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%zhi%!%%b:~%%c!)
set li38=%li38%
set /p user=!say:say=%error%! :
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" exit
if "!user!" equ "back" call :悔&goto :men
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-5-8 at 12:32 ]
::The algorithm takes advantage of the variable names being changeable in batch processing. When defining and using variables, the variable name is also part of the data. I wonder if VBS can do this in the same way.
::Comments have been added in the main places.
@echo off&setlocal enabledelayedexpansion
mode con: lines=43 cols=110
set li39= A B C D E F G H I J K L M N O P Q R S
set li0= ┌─────────────────────────────────────┐
set li1=A│┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐│A
set var=1
for %%a in (!li39:~5^,-1!) do (set/a var+=2&set li!var!=%%a│├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤│%%a)
for /l %%a in (2,2,36) do (set li%%a= ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││)
set li37=S│└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘│S
set li38= └─────────────────────────────────────┘`
rem The chessboard layout array li0~li39 is defined earlier, equivalent to the display buffer
set str=a b c d e f g h i j k l m n o p q r s
for %%a in (%str%) do (set/a .+=1,%%a=.&set z!.!=%%a)
rem Define the equivalent variables for letter and number conversion, such as a=1, z1=a
rem This definition is used in multiple places later
set li5=!li5! 五 棋 子 人 机 对 战
set li7=!li7! 批 处 理
set li10=!li10! 电 脑 水 平 中 等
set li31=!li31! 由 netbenton 编写完成
set li33=!li33! 棋盘设计参照了 batman
title 批处理五子棋
set str=###################
set .=0
for /l %%a in (1,1,19) do (
set he%%a=!str!&set sh%%a=!str!
for /l %%b in (1,1,19) do set
:
if /i "!var!" equ "Q" goto :eof
if /i "!var!" equ "W" (set zhi=●) else (set zhi=○)
echo.
rem Completely controlled by the %zhi% variable to determine which side is to play
:loop
(if %zhi% equ ● goto :men
set .=
for %%a in (!idea!) do (
for %%b in (he sh) do (
for /l %%c in (1,1,19) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
for %%b in (pi ni) do (
for /l %%c in (5,1,33) do (
if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c
) )
if defined . set put=%%a&goto :get
))
rem rem According to the defined idea rules, search all horizontal, vertical, diagonal strings, and jump out after getting the first match
rem rem If there is no match at all, it means it's a draw
echo. 已经和棋了
pause
endlocal&goto :restart
:men
(
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!★!%%b:~%%c!)
set li38=!li38:`=!
cls
for /l %%a in (0,1,39) do (echo !li%%a!)
rem rem Display the buffer on the screen
set/a .=lips-1&for /f "tokens=1-3" %%b in ("li!liph! !lips! !.!") do (set %%b=!%%b:~0,%%d!%zhi%!%%b:~%%c!)
set li38=%li38%
set /p user=!say:say=%error%! :
if "!user!" equ "reboot" endlocal&goto :restart
if "!user!" equ "exit" exit
if "!user!" equ "back" call :悔&goto :men
set/a pos=!user:~0,1!,poh=!user:~1,2!,var=pos-1 2>nul
if not defined
Last edited by netbenton on 2009-5-8 at 12:32 ]
|

精简
=> 个人 网志  |
|
2009-5-8 14:26 |
|
|
sady2009
初级用户
 
积分 58
发帖 60
注册 2009-2-18
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
太复杂了。死了几万个脑细胞,还没看懂:D
It's too complicated. I've used up tens of thousands of brain cells and still don't understand it. :D
|
|
2009-5-8 22:32 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
   『第 15 楼』:
使用 LLM 解释/回答一下
还没空搞清算法,先弄个HTA的界面出来先
<html>
<title>五子棋界面 - zh159</title>
<hrad>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="五子棋界面 - zh159"
BORDER="thin"
BORDERSTYLE=""
VERSION="1.0"
SCROLL="no"
ICON="C:\WINDOWS\System32\wuauclt.exe"
INNERBORDER="no"
CONTEXTMENU="no"
CAPTION="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>
</hrad>
<script language="javascript"></script>
<script language="VBScript"></script>
<style>
.GUIwh {width:24;height:24;cursor:hand;}
</style>
<body background="bg.gif" scroll="no" style="background: SteelBlue ;color:#ffffff;">
<table align="center" width="630" border="1" cellspacing="0" cellpadding="10" borderColor="#ffffff" style="font: 13px 宋体;border-collapse:collapse;">
<tr align="center">
<td width="450" height="450">
<table border="0" cellspacing="0" cellpadding="0" borderColor="#ffffff" style="font: 21px 宋体;border:2px solid #ffffff;">
<script language="VBScript">
str = "ABCDEFGHIJKLMNOPQRS"
For i = 1 To Len(str)
with document
.write "<tr align='center'>"
For n = 1 To Len(str)
stri = MID(str,i,1)
strn = MID(str,n,1)
tdstr = "<td id='GUI_" & strn & stri & "' class='GUIwh'><span onclick='Test(this)' onMouseOver='innerText=""●"";style.color=""blue""' onMouseOut='innerText=""┼"";style.color=""""'>┼</span></td>"
s = "┼"
If (stri = "A" and strn = "A") Then .write Replace(tdstr,s,"┌")
If stri = "A" Then If not (strn = "A" or strn = "S") Then .write Replace(tdstr,s,"┬")
If (stri = "A" and strn = "S") Then .write Replace(tdstr,s,"┐")
If not (stri = "A" or stri = "S") Then If strn = "A" Then .write Replace(tdstr,s,"├")
If not (stri = "A" or stri = "S" or strn = "A" or strn = "S") Then .write tdstr
If not (stri = "A" or stri = "S") Then If strn = "S" Then .write Replace(tdstr,s,"┤")
If (stri = "S" and strn = "A") Then .write Replace(tdstr,s,"└")
If stri = "S" Then If not (strn = "A" or strn = "S") Then .write Replace(tdstr,s,"┴")
If (stri = "S" and strn = "S") Then .write Replace(tdstr,s,"┘")
Next
.write "</tr>"
end with
Next
</script>
</table>
</td>
<td>
<span id="PC"><button>电脑先下</button><br><br>直接点击为玩家先下</span>
</td>
</tr>
</table>
</body>
<script language="VBScript">
width = 660
height = 550
window.resizeTo width, height
ileft=(window.screen.width-width)/2
itop=(window.screen.height-height)/2
window.moveTo ileft,itop
Sub Test(this)
this.parentNode.style.cursor = "default"
this.parentNode.innerHtml = "●"
PC.style.display = "none"
End Sub
Sub Title
Document.title = "五子棋 - zh159 - " & FormatDateTime(Now, 1) & " " & WeekdayName(WeekDay(now)) & " " & FormatDateTime(Now, 3)
End Sub
Title:setInterval "Title()",500
</script>
</html>
Haven't had time to figure out the algorithm yet, let's first create an HTA interface.
<html>
<title>Go Interface - zh159</title>
<hrad>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="Go Interface - zh159"
BORDER="thin"
BORDERSTYLE=""
VERSION="1.0"
SCROLL="no"
ICON="C:\WINDOWS\System32\wuauclt.exe"
INNERBORDER="no"
CONTEXTMENU="no"
CAPTION="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>
</hrad>
<script language="javascript"></script>
<script language="VBScript"></script>
<style>
.GUIwh {width:24;height:24;cursor:hand;}
</style>
<body background="bg.gif" scroll="no" style="background: SteelBlue ;color:#ffffff;">
<table align="center" width="630" border="1" cellspacing="0" cellpadding="10" borderColor="#ffffff" style="font: 13px 宋体;border-collapse:collapse;">
<tr align="center">
<td width="450" height="450">
<table border="0" cellspacing="0" cellpadding="0" borderColor="#ffffff" style="font: 21px 宋体;border:2px solid #ffffff;">
<script language="VBScript">
str = "ABCDEFGHIJKLMNOPQRS"
For i = 1 To Len(str)
with document
.write "<tr align='center'>"
For n = 1 To Len(str)
stri = MID(str,i,1)
strn = MID(str,n,1)
tdstr = "<td id='GUI_" & strn & stri & "' class='GUIwh'><span onclick='Test(this)' onMouseOver='innerText=""●"";style.color=""blue""' onMouseOut='innerText=""┼"";style.color=""""'>┼</span></td>"
s = "┼"
If (stri = "A" and strn = "A") Then .write Replace(tdstr,s,"┌")
If stri = "A" Then If not (strn = "A" or strn = "S") Then .write Replace(tdstr,s,"┬")
If (stri = "A" and strn = "S") Then .write Replace(tdstr,s,"┐")
If not (stri = "A" or stri = "S") Then If strn = "A" Then .write Replace(tdstr,s,"├")
If not (stri = "A" or stri = "S" or strn = "A" or strn = "S") Then .write tdstr
If not (stri = "A" or stri = "S") Then If strn = "S" Then .write Replace(tdstr,s,"┤")
If (stri = "S" and strn = "A") Then .write Replace(tdstr,s,"└")
If stri = "S" Then If not (strn = "A" or strn = "S") Then .write Replace(tdstr,s,"┴")
If (stri = "S" and strn = "S") Then .write Replace(tdstr,s,"┘")
Next
.write "</tr>"
end with
Next
</script>
</table>
</td>
<td>
<span id="PC"><button>Computer goes first</button><br><br>Click directly for player to go first</span>
</td>
</tr>
</table>
</body>
<script language="VBScript">
width = 660
height = 550
window.resizeTo width, height
ileft=(window.screen.width-width)/2
itop=(window.screen.height-height)/2
window.moveTo ileft,itop
Sub Test(this)
this.parentNode.style.cursor = "default"
this.parentNode.innerHtml = "●"
PC.style.display = "none"
End Sub
Sub Title
Document.title = "Go - zh159 - " & FormatDateTime(Now, 1) & " " & WeekdayName(WeekDay(now)) & " " & FormatDateTime(Now, 3)
End Sub
Title:setInterval "Title()",500
</script>
</html>
|

 |
|
2009-5-9 13:27 |
|
|