Wokring out battle messages and lol

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Wokring out battle messages and lol

#1 Post by Jedininja » 14 Jan 2022 04:28

So i have been trying to work out how to implement battle messages in a text based game and i came up with this!

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
::SETLOCAL ENABLEDELAYEDEXPANSION
:Load
set hp=100
set k=0
set x=0
set y=0
set g=Gestapo
set ukg=      You killed a %g%!
echo =================Gestapo=================
Echo.
echo  The Gestapo are trying to exterminate
echo  your babies. The wonderful little rays
echo  of sunshine are hinding in a bookshelf
echo  to avert the potential crisis.
echo.
echo =================Gestapo=================
Pause>nul
cls
echo =================Gestapo=================
echo.
echo  But, you are a valent care giver, kind
echo  and equal and trained to kill all in an
echo  instaint. Poor Gestapos...
echo.
echo =================Gestapo=================
Pause>nul
cls

:Start
set apl=error
set asl=error
set hsi=error
:Action Prefix List
set /a aplroll=%random%/1560
if /i %aplroll%==0 set apl=hit
if /i %aplroll%==1 set apl=hit
if /i %aplroll%==2 set apl=punch
if /i %aplroll%==3 set apl=headbunt
if /i %aplroll%==4 set apl=stab
if /i %aplroll%==5 set apl=insault
if /i %aplroll%==6 set apl=bite
if /i %aplroll%==7 set apl=dropkick
if /i %aplroll%==8 set apl=kick
if /i %aplroll%==9 set apl=shoot
if /i %aplroll%==10 set apl=knife
if /i %aplroll%==11 set apl=bash
if /i %aplroll%==12 set apl=shank
if /i %aplroll%==13 set apl=poison
if /i %aplroll%==14 set apl=shock
if /i %aplroll%==15 set apl=electrocute
if /i %aplroll%==16 set apl=burn
if /i %aplroll%==17 set apl=gas
if /i %aplroll%==18 set apl=claw
if /i %aplroll%==19 set apl=scratch
if /i %aplroll%==20 set apl=impail
if /i %aplroll%==21 set apl=hang
if /i %aplroll%==22 set apl=throw
:Action Suffix List
set /a aslroll=%random%/2520
If /i %aslroll%==0 set asl=finds jesus
If /i %aslroll%==1 set asl=burns
If /i %aslroll%==2 set asl=bleeds
If /i %aslroll%==3 set asl=drowns
If /i %aslroll%==4 set asl=convilses
If /i %aslroll%==5 set asl=pukes
If /i %aslroll%==6 set asl=staggers
If /i %aslroll%==7 set asl=stumbles
If /i %aslroll%==8 set asl=faints
If /i %aslroll%==9 set asl=explodes
If /i %aslroll%==10 set asl=melts
If /i %aslroll%==11 set asl=disintegrates
If /i %aslroll%==12 set asl=immolates
If /i %aslroll%==13 set asl=sufficates
:HeSheIt
set /a hsiroll=%random%/10922
If /i %hsiroll%==0 set hsi=he
If /i %hsiroll%==1 set hsi=she
If /i %hsiroll%==2 set hsi=it

set /a x=(%random%/7367)+1+(%k%/2)


CLS
echo =================Gestapo=================
echo.
echo.
echo       You %apl% the %g% and
echo       %hsi% %asl% for %x% Damage!
echo.
set /a hp=%hp%-%x%
If /i %hp% lss 1 set /a k=%k%+1 & echo %ukg%
If /i %hp% lss 1 set /a hp=100+(%k%*2)
echo.
echo =========================================
echo   Gustopo hp:%hp%   Damage:%x%   Kills:%k%
echo =================Gestapo=================
pause>nul
GOTO :start
It uses word lists based on a division of %random%, for example %random%/10922 results in an out put of 0, 1 or 2. (though i am half sure it should be 1,2,3)
But it comes up with some pretty funny messages with the words lists.

i Would like to know how to call these message from another file to set the word list variables if anyone can direct me int the right direction?
i have loosely experimented with calling batch label's, but i can not get it to work from another file.

this is the script to make the range of %random% divided if anyone is interested, it takes about an hour to run on my pos computer.

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
Pause
:Divisor
set d=0
:value of %random%
set r=32767
:Start
set /a x=%x%
if /i %d% equ %r% exit /b
set /a d=%d%+1
set /a x=%r%/%d%
echo %r% / %d% = %x% >> c:\temp\"random divided".txt
goto :start
My end goal is to be able to import player characters, mobs, weapons/armor/items from another file (for a different game) all of which will have customized battle messages when used attack/defend/block. i like this method but with 4 mobs 5 armors 2 weapons and items the "engine" file would be bulky and slow so figuring out how to call a batch header from another file is where i am left at. thanks for reading!

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Wokring out battle messages and lol

#2 Post by penpen » 15 Jan 2022 05:54

Jedininja wrote:
14 Jan 2022 04:28
It uses word lists based on a division of %random%, for example %random%/10922 results in an out put of 0, 1 or 2. (though i am half sure it should be 1,2,3)
If i rremember right, then random is a non negative and non zero 16-bit signed int, so the result of "%random%/10922" should be either 0, 1, 2 or 3:
- 0 if %random% is in [1, 10921]
- 1 if %random% is in [10922, 21843]
- 2 if %random% is in [21844, 32765]
- 3 if %random% is in [32766, 32767]


Jedininja wrote:
14 Jan 2022 04:28
i Would like to know how to call these message from another file to set the word list variables if anyone can direct me int the right direction?
i have loosely experimented with calling batch label's, but i can not get it to work from another file.
I'm not sure if you are searching for something like that:
viewtopic.php?f=3&t=7171

You might consider presenting, what you've tried so far, so we might be able to find out why you didn't succeed.

Jedininja wrote:
14 Jan 2022 04:28
this is the script to make the range of %random% divided if anyone is interested, it takes about an hour to run on my pos computer.
(...)
Technically you only need to perform your loop until your divisor reached the value ⌊ sqrt(32767)⌋:
"32767 / 181 = 181"

All following lines are kind of mirrored or 'filler' lines:

Code: Select all

...
32767 / 168 = 195 <- line A
32767 / 169 = 193 <- line B
...
"32767 / 181 = 181"
...
32767 / 193 = 169 <- mirrored B
32767 / 194 = 168 <- filler (same result as mirrored A)
32767 / 195 = 168 <- mirrored A
...
Note: All lines with divisors bigger than sqrt(32767), that were no result of the above computations are 'filler' lines.


penpen

T3RRY
Posts: 243
Joined: 06 May 2020 10:14

Re: Wokring out battle messages and lol

#3 Post by T3RRY » 15 Jan 2022 09:15

What i'd recommend before getting carried away with ill concieved approcahes to accomplish your end goals is to spend some time researching
and understanding the different ways of utilizing data structures in batch files.

Lists, arrays, lookup tables and even methods of implementing OOP principles in batch have all been developed over the years and countless
examples of each have been demonstrated abd explained. Have a search around.
If there's something specific your trying to implement, but cant get to work / understand. Ask for advice on what needs changing / how the approach works

An extremely rudimentary sentence generator that demonstrates some ways of handling data.

Code: Select all

@Echo off & Cls

Rem Define list to be indexed into array
 Set "Pronuouns=all,another,any,anybody,anyone,anything,as,aught,both,each,each other,either,enough,everybody,everyone,everything,few,he,her,hers,herself,him,himself,his,I,idem,it,its,itself,many,me,mine,most,my,myself,naught,neither,no one,nobody,none,nothing,nought,one,one another,other,others,ought,our,ours,ourself,ourselves,several,she,some,somebody,someone,something,somewhat,such,suchlike,that,thee,their,theirs,theirself,theirselves,them,themself,themselves,there,these,they,thine,this,those,thou,thy,thyself,us,we,what,whatever,whatnot,whatsoever,whence,where,whereby,wherefrom,wherein,whereinto,whereof,whereon,wherever,wheresoever,whereto,whereunto,wherewith,wherewithal,whether,which,whichever,whichsoever,who,whoever,whom,whomever,whomso,whomsoever,whose,whosever,whosesoever,whoso,whosoever,ye,yon,yonder,you,your,yours,yourself,yourselves"
 Set "ActionVerb=,Act,Answer,Approve,Arrange,Break,Build,Buy,Coach,Color,Cough,Create,Complete,Cry,Dance,Describe,Draw,Drink,Eat,Edit,Enter,Exit,Imitate,Invent,Jump,Laugh,Lie,Listen,Paint,Plan,Play,Read,Replace,Run,Scream,See,Shop,Shout,Sing,Skip,Sleep,Sneeze,Solve,Study,Teach,Touch,Turn,Walk,Win,Write,Whistle,Yank,Zip,"
 Set "LinkingVerb=,Am,Appear,Are,Be,Become,Been,Being,Feel,Grow,Is,Look,Remain,Seem,Smell,Sound,Stay,Taste,Turn,Was,Were"

Setlocal EnableDelayedExpansion

Rem Define indexable Array
 Set AVi=0&Set "null=%ActionVerb:,="& Set/A "AVi+=1" & Set "AV[!AVi!]=%"
 Set LVi=0&Set "null=%LinkingVerb:,="& Set/A "LVi+=1" & Set "LV[!LVi!]=%"
 Set PNi=0&Set "null=%Pronuouns:,="& Set/A "PNi+=1" & Set "PN[!PNi!]=%"

REM randomly index from arrays alternating array group between each iteration.

 Set /A "RandLen=!Random! %% 5 + 5"
 2> nul (
  Set "w[i]=1"
  For /l %%z in (1 1 !RandLen!)Do (
   If !w[i]! EQU 1 For /f "delims=" %%i in ('Set /A "v=!Random! %%AVi + 1"')Do <nul Set /p "=!AV[%%i]! "
   If !w[i]! EQU 2 For /f "delims=" %%i in ('Set /A "v=!Random! %%LVi + 1"')Do <nul Set /p "=!LV[%%i]! "
   If !w[i]! EQU 3 (
    For /f "delims=" %%i in ('Set /A "v=!Random! %%PNi + 1"')Do <nul Set /p "=!PN[%%i]! "
    Set "w[i]=0"
   )
   Set /A "w[i]+=1"
  )
 )
With some more thought, it would be reasonably easy to generate semi coherent sentences by giving thought to which words to define to the word type arrays, and randomly indexing into each word type array with a bias based on whatever the last word type was. Likewise, you can define different lists of wordtypes for different in-game situations to provide a higher likelihood of contextual output. Suggested reference to assist with determining what to use in the word type list:
http://www.butte.edu/departments/cas/ti ... 0sentence.

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: Wokring out battle messages and lol

#4 Post by Jedininja » 16 Jan 2022 20:15

penpen wrote:
15 Jan 2022 05:54
If i rremember right, then random is a non negative and non zero 16-bit signed int, so the result of "%random%/10922" should be either 0, 1, 2 or 3:
- 0 if %random% is in [1, 10921]
- 1 if %random% is in [10922, 21843]
- 2 if %random% is in [21844, 32765]
- 3 if %random% is in [32766, 32767]
it sure does! and i'v updated accordingly!

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
::SETLOCAL ENABLEDELAYEDEXPANSION
:Load
set hp=100
set k=0
set x=0
set g=Gestapo
set ukg=      You killed a %g%!
set g1=-----------------Gestapo-----------------
set g2=-----------------------------------------
echo %g1%
Echo.
echo  The Gestapo are trying to exterminate
echo  your babies. The wonderful little rays
echo  of sunshine are hinding in a bookshelf
echo  to avert the potential crisis.
echo.
echo %g1%
Pause>nul
cls
echo %g1%
echo.
echo  But, you are a valent care giver, kind
echo  and equal and trained to kill all in an
echo  instaint. Poor Gestapos...
echo.
echo %g1%
Pause>nul
cls

:Start
set apl=error
set asl=error
set hsi=error
set trd=error
:Action Prefix List
set /a aplroll=%random%/1560
if /i %aplroll%==0 set apl=irradiate
if /i %aplroll%==1 set apl=hit
if /i %aplroll%==2 set apl=punch
if /i %aplroll%==3 set apl=headbunt
if /i %aplroll%==4 set apl=stab
if /i %aplroll%==5 set apl=insault
if /i %aplroll%==6 set apl=bite
if /i %aplroll%==7 set apl=dropkick
if /i %aplroll%==8 set apl=kick
if /i %aplroll%==9 set apl=shoot
if /i %aplroll%==10 set apl=knife
if /i %aplroll%==11 set apl=bash
if /i %aplroll%==12 set apl=shank
if /i %aplroll%==13 set apl=poison
if /i %aplroll%==14 set apl=shock
if /i %aplroll%==15 set apl=electrocute
if /i %aplroll%==16 set apl=burn
if /i %aplroll%==17 set apl=gas
if /i %aplroll%==18 set apl=claw
if /i %aplroll%==19 set apl=scratch
if /i %aplroll%==20 set apl=impail
if /i %aplroll%==21 set apl=hang
if /i %aplroll%==22 set apl=throw

:Action Suffix List
set /a aslroll=%random%/5461
If /i %aslroll%==0 set asl=bleeds
If /i %aslroll%==1 set asl=convulses
If /i %aslroll%==2 set asl=pukes
If /i %aslroll%==3 set asl=staggers
If /i %aslroll%==4 set asl=stumbles
If /i %aslroll%==5 set asl=faints
If /i %aslroll%==6 set asl=slips

:HeSheIt
set /a hsiroll=%random%/10922
If /i %hsiroll%==0 set hsi=he
If /i %hsiroll%==1 set hsi=she
If /i %hsiroll%==2 set hsi=it

:trd
set /a hsiroll=%random%/8191
If /i %hsiroll%==1 set trd=taking
If /i %hsiroll%==0 set trd=receiving
If /i %hsiroll%==2 set trd=doing
If /i %hsiroll%==3 set trd=for

set /a x=(%random%/7367)+1+(%k%/2)

CLS
echo %g1%
echo.
echo.
echo       You %apl% the %g% and
echo       %hsi% %asl% %trd% %x% Damage!
echo.
set /a hp=%hp%-%x%
If /i %hp% lss 1 set /a k=%k%+1 & echo %ukg%
If /i %hp% lss 1 set /a hp=100+(%k%*2)
echo.
echo %g2%
echo   Gestapo hp:%hp%    Damage:%x%     Kills:%k%
echo %g1%
pause>nul
GOTO :start
for arguments sake one could change Gestapo to Dragon if needed.
penpen wrote:
15 Jan 2022 05:54
All following lines are kind of mirrored or 'filler' lines:

Code: Select all

...
32767 / 168 = 195 <- line A
32767 / 169 = 193 <- line B
...
"32767 / 181 = 181"
...
32767 / 193 = 169 <- mirrored B
32767 / 194 = 168 <- filler (same result as mirrored A)
32767 / 195 = 168 <- mirrored A
...
Was very much the problem i was having, the further the divisor gets from the denominator the bigger the range of "truthy-ness" gets. which i figured may be solved by using the center variable in the range.

For example to get the result 1 there are 779 possible divisors that fit into 32767 once, which is a range of 779 spanning from 16386 to 17165 --
(17165 - 16386) = (779 / 2) = 389.5
Which means that 389.5th variable (in the random divided script) will give the true'ist divisor for the output of 1 which can be found by subtracting
389 from 17165 (17165 - 389 = 16,776).
beyond 17165 the output of random divided is 0 and the script gets the divided by zero error.
T3RRY wrote:
15 Jan 2022 09:15
An extremely rudimentary sentence generator that demonstrates some ways of handling data.
That script is awesome, i put a lot of effort into selecting words that would "work" well together and still be small and simple. i fixed it in the script in this post which was basically removing suffix words until it made sense in a sentence... most of the time! i very much based it around the conjunctions being static variables. "You, The, And, Damage". it would probably make a terrible paragraph but works for a single sentence with some variation.

Post Reply