SNAKE.BAT 4.1 - An arcade style game using pure batch
Moderator: DosItHelp
Re: SNAKE.BAT 3.5 - An arcade style game using pure batch
Nice modification Dave - I love the growth rate. 6 FTW.
I have to say that on my pretty swift box there is no difference with CursorPos or not. No flicker either way.
I have to say that on my pretty swift box there is no difference with CursorPos or not. No flicker either way.
Re: SNAKE.BAT 3.6 - An arcade style game using pure batch
I've posted version 3.6 to the top of the thread. It is a trivial release. The only change is the game will now pause before exiting under the following conditions:
1) CursorPos.exe is not in the game folder, so the game potentially played with screen flicker.
2) The console will close upon game exit because the game was launched by double clicking the game or a shortcut.
The conditional pause is added so that players can view the message about CursorPos.exe before the console closes.
Dave Benham
1) CursorPos.exe is not in the game folder, so the game potentially played with screen flicker.
2) The console will close upon game exit because the game was launched by double clicking the game or a shortcut.
The conditional pause is added so that players can view the message about CursorPos.exe before the console closes.
Dave Benham
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
I've posted version 3.7 to the top of the thread.
The only change is to reduce the screen flicker when playing without CursorPos.exe by building the entire screen as a single variable with line feeds before using CLS and ECHOing the screen content. This was in response to einstein1969's post: Anti-Flicker in dos batch
Dave Benham
The only change is to reduce the screen flicker when playing without CursorPos.exe by building the entire screen as a single variable with line feeds before using CLS and ECHOing the screen content. This was in response to einstein1969's post: Anti-Flicker in dos batch
Dave Benham
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
dbenham wrote:I've posted version 3.7 to the top of the thread.
The only change is to reduce the screen flicker when playing without CursorPos.exe by building the entire screen as a single variable with line feeds before using CLS and ECHOing the screen content. This was in response to einstein1969's post: Anti-Flicker in dos batch
Dave Benham
Hi Dave,
I have probed the 3.7 version and is very beautyful!
In my example i use the command SET for display on screen
The SET command is more speedy of every other.
But for your scope is not necessary because the env should be emptied, and the code would be too complex.
But there is a problem... On my pc windows 7 the FIRST LINE flicker/blink. I have not probed on xp.
There is a trick for this
start print from the SECOND LINE but the first line must not be empty!
For the first line use a hidden character ALT+255 "ÿ" for example! or LF (I have not probed)
If you use timer coalesce this is not necessary.
Could you confirm this?
EDIT: I have probed and i have changed the line
Code: Select all
set screen=%\n%
width
Code: Select all
set screen=ÿ!LF!%\n%
and the line not blink...
einstein1969
Last edited by einstein1969 on 08 Aug 2014 06:46, edited 1 time in total.
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
I hope you don't take offense at this but I wanted to make a comment on a couple of your English terms.
instead of probed an English speaker may say I have examined or I have tested
The term timer coalesce is not an English expression that is in common use and I don't know what you mean by it.
This isn't meant to point out flaws, but just to say that some terms which you use fairly frequently have little meaning in English.
Your English is far far better than my Italian, or Spanish, or German, so I hope you take this constructively.
einstein1969 wrote:I have probed the 3.7 version and is very beautyful!
instead of probed an English speaker may say I have examined or I have tested
If you use timer coalesce this is not necessary.
The term timer coalesce is not an English expression that is in common use and I don't know what you mean by it.
This isn't meant to point out flaws, but just to say that some terms which you use fairly frequently have little meaning in English.
Your English is far far better than my Italian, or Spanish, or German, so I hope you take this constructively.
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
foxidrive wrote:I hope you don't take offense at this but I wanted to make a comment on a couple of your English terms.einstein1969 wrote:I have probed the 3.7 version and is very beautyful!
instead of probed an English speaker may say I have examined or I have testedIf you use timer coalesce this is not necessary.
The term timer coalesce is not an English expression that is in common use and I don't know what you mean by it.
This isn't meant to point out flaws, but just to say that some terms which you use fairly frequently have little meaning in English.
Your English is far far better than my Italian, or Spanish, or German, so I hope you take this constructively.
No offense. Indeed, thanks for the correction. I need correction
The "timer coalescing" is a concept.
From now on, I'll put it in quotation marks.
"timer coalescing" is usefull for anti-flicker in dos batch. On certain situation.
what is your mother tongue?
einstein1969
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
einstein1969 wrote:The "timer coalescing" is a concept.
From now on, I'll put it in quotation marks.
I see. thanks.
Can you describe how batch code can enter and exit idle states, and which affects screen flicker?
Has this been discussed here before? I may have missed it.
what is your mother tongue?
I speak English and only know a few words in other languages - I have enough trouble remembering how to spell in English.
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
foxidrive wrote:Can you describe how batch code can enter and exit idle states, and which affects screen flicker?
Has this been discussed here before? I may have missed it.
Well, it is rather an intuition which, however, is supported by visible results. I've done thousands of tests working with the variable TIME.
I've noticed that sometimes the variable takes values between them far apart.
I then calculated the average distance of these values and I saw that converged to a particular value that depends on the hardware.
I noticed that when it happens the timer coalescing, concurrently, the TIME variable changes.
Then I noticed that the redraw of the screen follows the same logic. So everything happens at the same time.
And it 's possible with reasonable accuracy then know when it happens the redraw of the screen.
einstein1969
Re: SNAKE.BAT 3.7 - An arcade style game using pure batch
einstein1969 wrote:But there is a problem... On my pc windows 7 the FIRST LINE flicker/blink. I have not probed on xp.
I think the specific flicker behavior varies from machine to machine. On my Win 7 64 bit machine, I don't get any flicker with speeds 1-3, and speeds 4-6 get minor flicker distributed throughout the entire screen. But the flicker is much less noticeable on v3.7 vs. v3.6.
Skipping the 1st line as you suggest does not improve the flicker for speeds 4-6 on my machine. I don't think there is any simple pure batch solution. Perhaps your "timer coalesce" technique could be made to work, but I don't really understand what it does, or how to apply it to SNAKE.
Dave Benham
Re: SNAKE.BAT 3.8 - An arcade style game using pure batch
Relatively minor changes for version 3.8 (available at the beginning of this thread).
1) I modified the Abort Replay function to purge the input stream via FINDSTR, thus making it nearly instantaneous. This is especially effective because FINDSTR does not reset the file pointer to the beginning of the file (originally described by jeb at viewtopic.php?f=3&t=2128&p=9720#p9720). I preserved the slower :purge routine for use when prompting for user input.
2) I eliminated the CLS at the end of :initialize and replaced it with CursorPos and ECHO to conditionally clear instructions. This eliminates irritating screen flicker when a new game or replay starts.
3) I defined variables for the file handles so the code is better self documenting.
Dave Benham
1) I modified the Abort Replay function to purge the input stream via FINDSTR, thus making it nearly instantaneous. This is especially effective because FINDSTR does not reset the file pointer to the beginning of the file (originally described by jeb at viewtopic.php?f=3&t=2128&p=9720#p9720). I preserved the slower :purge routine for use when prompting for user input.
2) I eliminated the CLS at the end of :initialize and replaced it with CursorPos and ECHO to conditionally clear instructions. This eliminates irritating screen flicker when a new game or replay starts.
3) I defined variables for the file handles so the code is better self documenting.
Dave Benham
Re: SNAKE.BAT 3.8 - An arcade style game using pure batch
Dave developing my password_input.cmd I found a strange thing that ocurrs with copy /Z.
Copy /Z cannot copy files with read only attributes if you run inside other cmd.exe instance, for example from for /f
for example:
Also this script:
with normal attributes display:
with read only attributes display:
Because it, if your script file have the read only attribute., it not set the CR variable properly and something strange things can happen, like not exist from graphics menu pressing Enter.
For fix it, i replaced this line:
with this:
with that I can run snake.cmd with read only attributes.
Also, optional, for avoid problems, with path filenames with special characters I replace this line:
with:
Copy /Z cannot copy files with read only attributes if you run inside other cmd.exe instance, for example from for /f
for example:
C:\dev>echo foo>new.txt
C:\dev>attrib +r new.txt
C:\dev>copy /Z c:\dev\new.txt nul
100% copied 1 file(s) copied.
C:\dev>cmd /c copy /Z c:\dev\new.txt nul
The parameter is incorrect.
0 file(s) copied.
C:\dev>
Also this script:
Code: Select all
@echo off
for /f %%A in ('copy /Z "%~dpf0" nul') do set "CR=%%A"
set CR
pause
with normal attributes display:
Code: Select all
CR=
Press any key to continue . . .
with read only attributes display:
Code: Select all
The parameter is incorrect.
CR=0
Press any key to continue . . .
Because it, if your script file have the read only attribute., it not set the CR variable properly and something strange things can happen, like not exist from graphics menu pressing Enter.
For fix it, i replaced this line:
Code: Select all
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
with this:
Code: Select all
set "CR=" &For /F "skip=1" %%a in (
'"echo(|replace.exe ? . /u /w"'
) do if not defined CR set "CR=%%a"
with that I can run snake.cmd with read only attributes.
Also, optional, for avoid problems, with path filenames with special characters I replace this line:
Code: Select all
for /f "delims=" %%A in ('xcopy /w "%~f0" "%~f0" 2^>nul') do (
with:
Code: Select all
for /f "delims=" %%A in ('xcopy /d /w ? ? 2^>nul') do (
Re: SNAKE.BAT 4.0 - An arcade style game using pure batch
I've posted a new version 4.0 of SNAKE.BAT at the first post in this thread.
There are two new features:
1) I utilized the Windows 10 console VT100 escape sequence capabilities to eliminate all screen flicker using nothing but "pure batch"
This only works if you have Windows 10, and your console has the "Use Legacy Console" option turned off. The SNAKE VT100 mode can be enabled within the Graphic options menu.
Besides eliminating flicker, I also hide the cursor while the game is being played.
If you don't have Windows 10, then you can still eliminate screen flicker by using Aacini's CursorPos.exe, just as before.
2) I've added an option to specify the playing field size. Supported sizes are as follows:
The original size used by SNAKE was Medium 40 x 25.
The Large and Wide sizes both have nearly maximal area supported by the SNAKE architecture. The limit stems from the 8191 variable length limit.
Dave Benham
There are two new features:
1) I utilized the Windows 10 console VT100 escape sequence capabilities to eliminate all screen flicker using nothing but "pure batch"
This only works if you have Windows 10, and your console has the "Use Legacy Console" option turned off. The SNAKE VT100 mode can be enabled within the Graphic options menu.
Besides eliminating flicker, I also hide the cursor while the game is being played.
If you don't have Windows 10, then you can still eliminate screen flicker by using Aacini's CursorPos.exe, just as before.
2) I've added an option to specify the playing field size. Supported sizes are as follows:
Code: Select all
Tiny 15 x 10
Small 30 x 20
Medium 40 x 25
Large 47 x 32
Wide 82 x 19
Narrow 15 x 40
The original size used by SNAKE was Medium 40 x 25.
The Large and Wide sizes both have nearly maximal area supported by the SNAKE architecture. The limit stems from the 8191 variable length limit.
Dave Benham
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: SNAKE.BAT 4.0 - An arcade style game using pure batch
Hi Dave,
I noticed that the snake on the x-axis with the time delay normal creeps. In the y-axis, however, the snake is 25% faster if the default resolution of the command line is 8 pixels x 12 pixels.
In the wide size this is particularly noticeable.
In order to compensate for this, an adjusted delay per axis is calculated.
I do not like this calculation especially, since this does not round properly. But in the fastest speed it must be increased by one hundredths.
I have only found the possibility within this part %=== establish direction ===%
In the 4-key mode.
The setting of the delay for the axes must be done in the initialization
Is there a possibility to read the fonts resolution of the command line?
Phil
I noticed that the snake on the x-axis with the time delay normal creeps. In the y-axis, however, the snake is 25% faster if the default resolution of the command line is 8 pixels x 12 pixels.
In the wide size this is particularly noticeable.
In order to compensate for this, an adjusted delay per axis is calculated.
I do not like this calculation especially, since this does not round properly. But in the fastest speed it must be increased by one hundredths.
Code: Select all
:: delay#
::: Gives the movement on the Y axis 25 percent more delay time
::: because the default resolution of the command line is
::: 8 pixels x 12 pixels. Thus reducing the too fast movement
::: on the Y-axis to keep the axes moving synchronously.
set delay#=(%\n%
set /a "xDelay=delay"%\n%
set /a "yDelay=delay*45/30"%\n%
if !delay! gtr 10 set /a "yDelay=delay*4/3"%\n%
)
I have only found the possibility within this part %=== establish direction ===%
In the 4-key mode.
Code: Select all
if !axis! == X (set /a "delay=xDelay") else set /a delay=yDelay
The setting of the delay for the axes must be done in the initialization
Code: Select all
set "delay=!delay%key%!"
%delay#%
Is there a possibility to read the fonts resolution of the command line?
Phil
Re: SNAKE.BAT 4.0 - An arcade style game using pure batch
pieh-ejdsch wrote:Is there a possibility to read the fonts resolution of the command line?
Try to read it via reg query.
Code: Select all
@echo off &setlocal
reg query HKCU\Console\%%SystemRoot%%_system32_cmd.exe /v FaceName >nul 2>&1 && set "key1=HKCU\Console\^^%%SystemRoot^^%%_system32_cmd.exe" || set "key1=HKCU\Console"
reg query HKCU\Console\%%SystemRoot%%_system32_cmd.exe /v FontSize >nul 2>&1 && set "key2=HKCU\Console\^^%%SystemRoot^^%%_system32_cmd.exe" || set "key2=HKCU\Console"
for /f "tokens=2*" %%i in ('reg query %key1% /v FaceName') do set "facename=%%j"
for /f "tokens=3" %%i in ('reg query %key2% /v FontSize') do set /a "height=%%i>>16, width=%%i&0xFFFF"
if "%facename%"=="Terminal" (echo Raster Font %width%x%height%) else echo %facename% %height%
pause
Steffen
Re: SNAKE.BAT 4.0 - An arcade style game using pure batch
It looks like you are trying to define a macro, but there is no need - the two values are constant throughout one entire game play. So I would simply define the two values as part of game initialization.pieh-ejdsch wrote:I do not like this calculation especially, since this does not round properly. But in the fastest speed it must be increased by one hundredths.Code: Select all
:: delay#
::: Gives the movement on the Y axis 25 percent more delay time
::: because the default resolution of the command line is
::: 8 pixels x 12 pixels. Thus reducing the too fast movement
::: on the Y-axis to keep the axes moving synchronously.
set delay#=(%\n%
set /a "xDelay=delay"%\n%
set /a "yDelay=delay*45/30"%\n%
if !delay! gtr 10 set /a "yDelay=delay*4/3"%\n%
)
The axis changes every time a turn key is pressed in 2 key mode.pieh-ejdsch wrote:I have only found the possibility within this part %=== establish direction ===%
In the 4-key mode.Code: Select all
if !axis! == X (set /a "delay=xDelay") else set /a delay=yDelay
The game always starts out with xaxis movement, regardless of 2 key or 4 key mode.
Besides taking into account the pixel dimensions of each character, you also have to consider the aspect ratio of each pixel within the physical display.
I'm not sure I like the idea of different delays for x and y. But if I were to implement it, then I would do something like the following (I'm implementing a constant 25% delay increase for y to keep things simple, regardless of the aspect ratio)
Within the :initialize routine, I need just one additional line to define a few more constants after the delay has been selected by the user:
Code: Select all
set /a "delay.!left!=delay.!right!=delay, delay.!up!=delay.!down!=delay*5/4, delayDiff=delay.!up!-delay"
and in the main loop I would make changes to the two SET /A statements :
Code: Select all
%=== establish direction ===%
if not defined replay (echo(!key!.) >>"!gameLog!"
for %%K in (!key!) do if !moveKeys! equ 2 (
set /a "xDiff=xTurn%%K*!yDiff!, yDiff=yTurn%%K*!xDiff!, delay-=(delayDiff*=-1)"
) else if "!%%KAxis!" neq "!axis!" (
set /a "xDiff=xDiff%%K, yDiff=yDiff%%K, delay=delay.%%K"
set "axis=!%%KAxis!"
)
Dave Benham