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-20 23:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Gobang Man-machine Battle Batch Game View 13,551 Replies 73
Floor 31 Posted 2009-05-12 08:42 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
First, write something simple to set up the framework, and then gradually make it more complex. Hehe
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 32 Posted 2009-05-12 13:57 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Added a few lines of code, but it improved a lot in speed.

It seems that it is still possible to further improve the computer's chess playing ability,
and introduce the forbidden moves and other rules of Gobang,


@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 :eof

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 (set var=%%a&set !var:~,-1!=!var:~-1!&set idea=!idea! !var:~,-1!)
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 .=
for %%a in (!idea!) do (
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
)
) )
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
)
) )
if defined . set put=%%a&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" 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-14 at 00:31 ]
精简
=> 个人网志
Floor 33 Posted 2009-05-17 11:44 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Enhanced the intelligence of the computer side!
Updated on floor 7 already.
精简
=> 个人网志
Floor 34 Posted 2009-05-17 14:22 ·  中国 山西 忻州 联通
初级用户
★★
Credits 87
Posts 63
Joined 2008-08-23 11:28
17-year member
UID 123947
Gender Male
Status Offline
Floor 35 Posted 2009-05-18 03:02 ·  中国 山东 淄博 联通
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
17-year member
UID 123026
Gender Male
Status Offline
It's really incredible, very spectacular,, admire you, you're really a good person...

[ Last edited by 516526966 on 2009-5-18 at 08:03 ]
Attachments
2009-05-18_185017.png
Floor 36 Posted 2009-05-18 13:07 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I'm completely confused. Except for the interface, I'm a total novice to the Budget Law, and changing to VBS is basically out of the question...
Floor 37 Posted 2009-05-19 04:20 ·  中国 贵州 黔南布依族苗族自治州 电信
新手上路
Credits 1
Posts 1
Joined 2009-05-16 08:07
17-year member
UID 145240
Gender Male
Status Offline
Floor 38 Posted 2009-05-21 09:09 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
There has been another update, improving the computer's IQ, and randomly selecting positions when there are multiple equivalent points that can be played, increasing the playability. Therefore, this batch script is no longer just a work of art but also a real Gobang game. Welcome everyone to use it, and post the places where you think the computer plays "stupidly" so that it can be improved again.

Final update, please see floor 7
精简
=> 个人网志
Floor 39 Posted 2009-05-22 23:31 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The two algorithms I now want to figure out:
1. Lower computer algorithm of the computer
2. Algorithm for the result of five-in-a-row
Floor 40 Posted 2009-05-23 00:55 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
re 39L

Array definition:
1. Display buffer
2. Horizontal (string length is 19)
3. Vertical (string length is 19)
4. Diagonal (slash, string length is 5~19~5)
5. Diagonal (backslash, string length is 5~19~5)

Array 1 is initially an empty chessboard.
Arrays 2~5 are initially strings of all #.

When there is a move, according to the player's input or the actual coordinates obtained by the computer, replace the corresponding positions in the 5 arrays with the chess piece (method:!str:~,n!chess piece!str:~n+1!). Immediately after replacement, match whether the string!str! contains five in a row, and if so, the player wins.

How the computer takes the position:
Because each direction string is defined and updated separately, just match the various rule strings (that is, set IQ, such as #○○○#) with the data strings in each direction. If found, record it (in which array, which string). After all matching is completed, analyze the recorded results and convert them into actual coordinates.

(The number after the IQ rule string is the available point in the rule string. Calculate the position of the rule string in the direction string. According to this point, the available point in the direction string can be calculated. Then, according to which array it is in, the available point in the actual coordinates can be calculated.)

Then weight the coordinates according to the rule string (in the initial version, only the first matched available point is sought, and the weight calculation is not done). Finally, the computer takes the coordinate with the largest weight value to make a move. If there are equal weights, randomly take one.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
WANKOILZ +2 2009-07-29 03:01
精简
=> 个人网志
Floor 41 Posted 2009-05-25 11:39 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Gobang batch processing, with music playback and music files, only 96K
Listening to "Moonlit Night on the Spring River" while playing chess, enjoy it!!

[ Last edited by netbenton on 2009-6-3 at 23:22 ]
Attachments
五子棋(音乐版).rar (20.18 KiB, Downloads: 107)
精简
=> 个人网志
Floor 42 Posted 2009-06-02 12:01 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Minor update: Slightly enhanced the computer's chess-playing skill.
(Updated on floors 7 and 41)

Saw someone online post that when the player goes first, they can win the computer in nine moves, so this has been improved.
精简
=> 个人网志
Floor 43 Posted 2009-06-02 22:53 ·  中国 江西 吉安 电信
初级用户
★★
Credits 78
Posts 64
Joined 2008-08-29 11:09
17-year member
UID 124464
Gender Male
Status Offline
After seeing the masterpiece of the senior, my heart has been in turmoil for a long time. When will I be able to reach the level of the senior?
I will work hard from today! Work hard! Aim at the senior
Floor 44 Posted 2009-06-03 02:34 ·  中国 河北 唐山 联通
初级用户
Credits 29
Posts 17
Joined 2009-06-02 06:03
17-year member
UID 146516
Gender Male
Status Offline
The music doesn't stop. The batch script is closed but the music continues.
Floor 45 Posted 2009-06-03 02:36 ·  中国 河北 唐山 联通
初级用户
Credits 29
Posts 17
Joined 2009-06-02 06:03
17-year member
UID 146516
Gender Male
Status Offline
Oh, only when you type Q to exit in the game will the music stop.

If you directly click the close button, the game exits but the music continues to play.

I don't know if it's only like this for me.
Forum Jump: