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-08-12 10:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Push Box Batch Processing Game View 12,784 Replies 63
Floor 31 Posted 2009-09-10 12:37 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
1. Increase to support the use of super large maps, referring to more than one screen.
2. Add a verification function of the map by the compression conversion program, and prompt when characters other than the map appear.
3. Develop a map editing program hdt.bat. Use this program to quickly edit full-width character maps for maze walking, box pushing, etc.

**Please see the attachment enhanced version on the first floor**

[ Last edited by netbenton on 2009-9-16 at 09:47 ]
精简
=> 个人网志
Floor 32 Posted 2009-09-16 11:51 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Add 12 easier levels to the Sokoban game. Just add the following code to the level data after the batch Sokoban program. It is recommended to insert it into the third line of the level data.

:囧g4a7 g3a2b2abfa g3ab3ab2a g3acbcbcba g3abca2b2a ga3bcbaba2 gad5b2a ga9 
:囧g3a6 ga3b4a a2dbca2ba2 ad2cbcb2fa ad2bcbcba2 a5b3a g4a5
:囧a6 abfb2a abcaba abcb2a abcba2 a3ba4 gab2ab2a gad3b2a gab5a ga7
:囧a9a3 ab9ba aba7bfa2 abab9a abab2cb3ab2a abc2ba5b2a a3b2agabd3a g2a4gab4a g7a6
:囧ga9 gab2a2b3a gab3cb3a gacba3bca gabad3aba a2bad3aba2 abcb2cb2cba ab5ab2fa a9a2
:囧g2a5 g2ab3a a3cdca5 ab3dbcb3a aba2ca2bfba ab3dba5 a3bdba g2ab3a g2a5
:囧ga4g2a5 a2b2ag2ab3a abcba4cb2a ab2cd4bcba a2b4abfba2 ga9a
:囧a9a ad2b6a ad2cb2ab2a ab2aca2ba2 abcb5a a5baba g2abcbfba g2ab5a g2a7
:囧a6ga5 ab4a3b3a abc2b5afa abcbad3b3a ab3a8 a5
:囧ga5 gab3a a2bcbag2a4 ab4a4b2a abcb6cda ab3a5cda a5g3abfa g8a4
:囧g7a5 g7adb2a g7adaba a8daba abfbcbcb2cba abababab2a3 ab8a a9a
:囧a5 ab3a4 abababda ab4cba3 a3bacdb2a ab3afb3a ababa6 ab3a a5
精简
=> 个人网志
Floor 33 Posted 2009-09-17 00:13 ·  中国 福建 厦门 电信
初级用户
Credits 36
Posts 22
Joined 2009-09-12 00:31
16-year member
UID 151867
Gender Male
From 厦门
Status Offline
Floor 34 Posted 2009-09-19 12:40 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Very good, proficient in assembly, learned...
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 35 Posted 2009-09-30 00:24 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
The original has been duplicated, forget it, just correct some typos...

Explanation of Batch Push-Square Source Code:

1. Use of Compact Format for Data Definition
First, put the variable definition set into a variable: (Note that the delimiter is unique, here using the ";" sign)
set a=a=i75;b=i79;str=abc
So the value of variable a is: a=i75;b=i79;str=abc
Use variable value replacement during preprocessing:
set %a:;=&set %
Equivalent to the following statements being executed:
set a=i75&set b=i79&set str=abc
Or:
set a=i75
set b=i79
set str=abc
If there are many variables to define, comprehensively considering from the perspective of occupied space and readability, this method has obvious advantages.


2. Implementation Algorithm of Push-Square Program
1). Read the level data into the array: lev(n)
Change the value of n, which is to change the level, here n is %lev%
2). Restore the current level map data and store it in the two-dimensional array: r(n).(m)
(1) Collect the variable names r(n).(m) with the value "☆" into variable ke, and store the number of "☆" into variable ji, and convert them to "★" at the same time; Note: ke saves the variable name, not the variable value.
%ke% expansion later is the real-time value of all two-dimensional variables with the source value "☆"; as long as %ke% is equal to !ji! indicates that the level is passed
(2) Store the two-dimensional variable names as an array: r(n) by row, Note: it is the variable name
%r(n)% expansion later is the real-time value of all two-dimensional arrays in row n

3). Variable ebuf is used as a display buffer, all content to be displayed is stored in ebuf, and all is displayed at once with echo !ebuf! to achieve fast screen refresh.

Because after expansion of for variable %%a, the! number variables in the value will be expanded again, so:
for /l %%a in (1,1,!r!) do for %%b in ("!r%%a!") do set ebuf=!ebuf! %%~b!cr!
The above sequentially stores the expanded values of the variable name array r(n) from row 1 to!r! into the display buffer ebuf, and adds the newline character!cr!

4). First define the operations for up, down, left and right:
"c1=n-;c2=m-;c3=n+;c4=m+"
In this way, the following code can be used:
set/a sm=m,sn=n,!c%in%!=1,bm=m,bn=n,!c%in%!=1
Respectively obtain the source point: sm.sn, step one: bm.bn, step two: m.n, the values of the three coordinates after pressing up/down/left/right

for /f "tokens=1,2" %%a in ("!r%bn%.%bm%! !r%bn%.%bm%!!r%n%.%m%!") do (
Take out the values of the three coordinates and spread them out as: (step one => %%a) (step one + step two =>%%b) For example: %%a=▓ %%b=▓∷

***Various movable combination types have been variables before***
***The undefined ones are considered as non-movable combinations***

for %%c in ("!%%a!!%%b!") do (
%%a %%b is re-expanded and grouped to %%c, connected with the previous example:!▓! => empty,!▓∷! =>▓-∷
Then: ▓-∷ => %%c

for /f "tokens=1,2 delims=-" %%1 in (%%c) do (
Spread out as: %%1=▓, %%2=∷
Next is the if judgment, and according to various situations, the values of the three points and a "big" standing! source! point are readjusted

Note: There is one point, if the value of %%c is empty, such as %%b=▓■, then this for will be idle, that is, even the following if statement will not be executed, making the following set/a m=sm,n=sn be executed, restoring m,n, that is, cannot move


3. Compression and Restoration of Level Data
1). Compression, because full-width is double-byte, using single character conversion can be reduced by half, if ▓=a, zf=▓, then: set zf=!%af%! can be converted back
If there is not only one, and there are consecutive ones, then a number is added after the letter to indicate the number of times, such as: a4, if it exceeds 9 times, then another group is started, such as: a11, then split into a9a2

2). Restoration, reference: the advantage of starting with 囧,

for /f "tokens=2* delims=囧" %%a in (%~nx0) do (set lev!n!=%%a&set/a n+=1)
In this way, when reading, the reading of other non-data lines can be subtracted, and the speed is accelerated
Similarly, convert the characters back, and then use for /l counting to repeat to convert all
if "!tn:%%2=!" neq "!tn!" (set k=%%2) else (set k=1)
for /l %%k in (1,1,!k!) do (
The above!k! is the number of consecutive characters


4. Get rid of choice.exe and no flickering when refreshing the screen
That is to use debug.exe instead, but this is usually built into the system, so third-party...
debug <%~nx0>nul
Call itself as pipeline input, the first line is wrong, only two lines are really useful
e 100 cd 16 86 c4 b4 02 cd 10 b4 4C CD 21 Write code
g Execute
Here, key reading is performed, the current cursor position is set to the first line, first column, and the key data is used as the return code to: %errorlevel%
Definition: "a=i83=10;i1=7;i72=1;i80=3;i75=2;i77=4;i73=8;i81=9;i57=5;i79=6"
Execute: set in=!i%errorlevel%!
You can get the corresponding key according to the definition, if it is not defined, it is empty

Usually when writing a batch processing to return to the first line to display, only cls is used, and then display, obviously the speed is also very fast, but still feel a little flickering.
Directly reset the cursor to the first line, first column, without clearing the screen, and when displaying again, it is on the original basis, so the feeling of flickering is less
If you want to see the assembly source code, it is very simple, remove >nul after debug <%~nx0>nul, and then add a line u between the e line and the g line


5. Player record saving and reading
Here, the record is stored in the first line of the batch processing,

1). Reading
set/p yg=< %~nx0 >nul
Take the first line to variable yg
set yg=!yg:~13,52!
set lev=%yg:@=&rem %
Because the current level record and the passed level record are separated by @, in this way, only the part before @ is given to lev, and the part after @ is commented out by rem
set yg= !yg:* =!
Take the passed data, and keep that there must be spaces before and after
In this way, the data of the current level and the passed levels has been read into the variable


[ Last edited by netbenton on 2009-10-5 at 15:46 ]
精简
=> 个人网志
Floor 36 Posted 2009-10-01 17:17 ·  中国 北京 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
Expert! Great post and expert insights, I've learned a lot! There are many useful things in the script that can be studied. For example, the choice command has always been a big headache, but the LZ has managed to handle it! Who can summarize these useful things? I'm still studying the LZ's code!
Floor 37 Posted 2009-10-01 20:59 ·  中国 海南 电信
初级用户
Credits 24
Posts 24
Joined 2009-09-21 07:50
16-year member
UID 152383
Gender Male
Status Offline
Niu Niu's, there's no way to describe it
Floor 38 Posted 2009-10-02 22:07 ·  中国 江西 吉安 遂川县 电信
新手上路
Credits 1
Posts 1
Joined 2009-08-17 03:33
16-year member
UID 150496
Gender Male
Status Offline
The second level is a dead end and cannot be passed. The third level is just numerous and easy to pass. Generally, it is written quite well, and I admire it.
Floor 39 Posted 2009-10-03 20:29 ·  中国 广东 东莞 电信
新手上路
Credits 3
Posts 3
Joined 2009-09-30 15:25
16-year member
UID 152470
Gender Male
Status Offline
Oh my goodness, this level is way too high...................
Floor 40 Posted 2009-10-05 12:27 ·  中国 广东 东莞 电信
初级用户
Credits 86
Posts 45
Joined 2007-07-27 08:05
19-year member
UID 94111
Gender Male
Status Offline
Oh my god, batch processing can also be used to program such a complex game! The thread starter is awesome, I support you!
Floor 41 Posted 2009-10-10 07:27 ·  中国 广东 肇庆 四会市 电信
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by xdjxondaojune at 2009-10-2 22:07:
The second level is a dead end, can't pass, the third level is just numerous, easy to pass. Generally well written, admired


The second level can't be a dead end, brother, think more about it, I reached the third level in less than a minute.
Floor 42 Posted 2009-10-10 08:29 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
What the 41st floor said is right.

Hey, how could that classmate casually say that was a dead end...
Floor 43 Posted 2009-10-12 18:38 ·  中国 湖南 郴州 电信
初级用户
Credits 36
Posts 15
Joined 2008-05-07 18:47
18-year member
UID 118028
Gender Male
Status Offline
Floor 44 Posted 2009-10-23 22:22 ·  中国 云南 玉溪 电信
新手上路
Credits 14
Posts 13
Joined 2009-07-06 12:21
17-year member
UID 148847
Gender Female
Status Offline
awesome, cool, fun
天行健 君子以自强不息
Floor 45 Posted 2009-10-28 20:31 ·  中国 山东 移动
中级用户
★★
Credits 208
Posts 97
Joined 2006-12-28 22:08
19-year member
UID 74845
Gender Male
Status Offline
That Tetris is quite awesome, and this one is even more awesome, it's the work of so-called masters
Forum Jump: