Post: [Batch]Random Letter placement
05-30-2013, 03:13 AM #1
~SpongeBob
[move]Winning.[/move]
(adsbygoogle = window.adsbygoogle || []).push({}); I have been messing around with batch, and had the idea for a word guessing game. Being bored i decided to do it. I have gotten the game almost done, it still needs work, but i have a game breaking problem, and that is that i cant constantly have a random placement for the letter i need, i also need a way to make the letters not repeat at all
Some Examples:
My random letter picker.
    
set /a num=%random% %%10 +1
setLocal EnableDelayedExpansion
set str=ABCDEFGHIJKLMNOPQRSTUVWXYZ
set /a P1=!random!%%26
set /a P2=!random!%%26
set /a P3=!random!%%26
set /a P4=!random!%%26
set /a P5=!random!%%26
set /a P6=!random!%%26
set /a P7=!random!%%26
set /a P8=!random!%%26
set /a P9=!random!%%26
set /a P10=!random!%%26
set /a P11=!random!%%26
set /a P12=!random!%%26
set /a P13=!random!%%26
set /a P14=!random!%%26
set /a P15=!random!%%26
set /a P16=!random!%%26
set /a P17=!random!%%26
set /a P18=!random!%%26
set /a P19=!random!%%26
set /a P20=!random!%%26
set /a P21=!random!%%26
set /a P22=!random!%%26
set /a P23=!random!%%26
set /a P24=!random!%%26
set /a P25=!random!%%26
set /a P26=!random!%%26
set /a P27=!random!%%26
set /a P28=!random!%%26
set /a P29=!random!%%26
set /a P30=!random!%%26

An example word that uses all random letters, i need the first letter letters to contain a P, and the second letter to contain an A, ect.
    
Title Word-Guessing-Game
Echo Word Selected.
Echo Your Word is 5 Letters long, and it has somthing to do with Clothing.
PING 1.1.1.1 -n 1 -w 4500 >NUL
Cls
Echo The First Letter Could be [!str:~%P1%,1!, !str:~%P2%,1!, !str:~%P3%,1!, !str:~%P4%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Second Letter Could be [!str:~%P5%,1!, !str:~%P6%,1!, !str:~%P7%,1!, !str:~%P8%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Thrid Letter Could be [!str:~%P9%,1!, !str:~%P12%,1!, !str:~%P11%,1!, !str:~%P12%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fourth Letter Could be [[!str:~%P13%,1!, !str:~%P14%,1!, !str:~%P15%,1!, !str:~%P16%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fifth Letter Could be [!str:~%P17%,1!, !str:~%P18%,1!, !str:~%P19%,1!, !str:~%P20%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo What is your Guess?
set /p guess1=
if %guess1% == Pants goto winner
if %guess1% == pants goto winner
if NOT %guess1% == pants goto Loser

I don't want to just replace one of the !str's with a letter, because then it will never change, and you can just learn what it is. I also have some letters repeat. If you could help me out with any of these problems, that would be AMAZING. I cant just leave the project until its done ^^

Here is the entire program if you need it.
    
@echo off
set /a num=%random% %%10 +1
setLocal EnableDelayedExpansion
set str=ABCDEFGHIJKLMNOPQRSTUVWXYZ
set /a P1=!random!%%26
set /a P2=!random!%%26
set /a P3=!random!%%26
set /a P4=!random!%%26
set /a P5=!random!%%26
set /a P6=!random!%%26
set /a P7=!random!%%26
set /a P8=!random!%%26
set /a P9=!random!%%26
set /a P10=!random!%%26
set /a P11=!random!%%26
set /a P12=!random!%%26
set /a P13=!random!%%26
set /a P14=!random!%%26
set /a P15=!random!%%26
set /a P16=!random!%%26
set /a P17=!random!%%26
set /a P18=!random!%%26
set /a P19=!random!%%26
set /a P20=!random!%%26
set /a P21=!random!%%26
set /a P22=!random!%%26
set /a P23=!random!%%26
set /a P24=!random!%%26
set /a P25=!random!%%26
set /a P26=!random!%%26
set /a P27=!random!%%26
set /a P28=!random!%%26
set /a P29=!random!%%26
set /a P30=!random!%%26

Title Word-Guessing-Game
:beginging
cls
color 9
echo ------------------
echo [ Word Guessing Game ]
echo ------------------
PING 1.1.1.1 -n 1 -w 500 >NUL
cls
color 0A
echo ------------------
echo [ Word Guessing Game ]
echo ------------------
PING 1.1.1.1 -n 1 -w 500 >NUL
cls
color 0C
echo ------------------
echo [ Word Guessing Game ]
echo ------------------
PING 1.1.1.1 -n 1 -w 500 >NUL
cls
color 0D
echo ------------------
echo [ Word Guessing Game ]
echo ------------------
PING 1.1.1.1 -n 1 -w 500 >NUL
cls
color 0E
echo ------------------
echo [ Word Guessing Game ]
echo ------------------
PING 1.1.1.1 -n 1 -w 500 >NUL
:starting1
cls
echo Please select your dificulty.
echo (1) Easy
echo (2) Medium
echo (3) Hard
echo (4) Imposible
set /p dif=(1-4)
if %dif%==1 goto startE
if %dif%==2 goto startM
if %dif%==3 goto startH
if %dif%==4 goto startI
if NOT %dif%==1 goto starting1
:startE
cls
color 0F
Echo Welcome, You have selected Easy, Are you Ready to play?
set /p input=(Y/N)
if %input%==Y goto clear
if %input%==Yes goto clear
if %input%==yes goto clear
if %input%==y goto clear
if %input%==n goto bye
if %input%==no goto bye
if %input%==N goto bye
if %input%==No goto bye
if NOT %input%==Y goto start
:startM
cls
color 0F
Echo Welcome, You have selected Medium, Are you Ready to play?
set /p input=(Y/N)
if %input%==Y goto clearM
if %input%==Yes goto clearM
if %input%==yes goto clearM
if %input%==y goto clearM
if %input%==n goto bye
if %input%==no goto bye
if %input%==N goto bye
if %input%==No goto bye
if NOT %input%==Y goto start
:startH
cls
color 0F
Echo Welcome, You have selected Hard, Are you Ready to play?
set /p input=(Y/N)
if %input%==Y goto clearH
if %input%==Yes goto clearH
if %input%==yes goto clearH
if %input%==y goto clearH
if %input%==n goto bye
if %input%==no goto bye
if %input%==N goto bye
if %input%==No goto bye
if NOT %input%==Y goto start
:startI
cls
color 0F
Echo Welcome, You have selected Imposible, Are you Ready to play?
set /p input=(Y/N)
if %input%==Y goto clearI
if %input%==Yes goto clearI
if %input%==yes goto clearI
if %input%==y goto clearI
if %input%==n goto bye
if %input%==no goto bye
if %input%==N goto bye
if %input%==No goto bye
if NOT %input%==Y goto start
:clear
cls
goto selector
:clearM
cls
goto selectorM
:clearH
cls
goto selectorH
:clearI
cls
goto selectorI
:selector
title Selecting Word, This may take a second.
echo Selecting.
set /a num=%random% %%10 +1
if %random% == 1 goto hi1
if %random% == 2 goto hi2
if %random% == 3 goto hi3
if %random% == 4 goto hi1
if %random% == 5 goto hi2
if %random% == 6 goto hi3
if %random% == 7 goto hi1
if %random% == 8 goto hi2
if %random% == 9 goto hi3
if %random% == 10 goto hi1
if NOT %random% == 1 goto selector1
:selector1
title Selecting Word, This may take a second..
echo Selecting..
set /a num=%random% %%10 +1
if %random% == 1 goto hi1
if %random% == 2 goto hi2
if %random% == 3 goto hi3
if %random% == 4 goto hi1
if %random% == 5 goto hi2
if %random% == 6 goto hi3
if %random% == 7 goto hi1
if %random% == 8 goto hi2
if %random% == 9 goto hi3
if %random% == 10 goto hi1
if NOT %random% == 1 goto selector2
:selector2
title Selecting Word, This may take a second...
echo Selecting...
set /a num=%random% %%10 +1
if %random% == 1 goto hi1
if %random% == 2 goto hi2
if %random% == 3 goto hi3
if %random% == 4 goto hi1
if %random% == 5 goto hi2
if %random% == 6 goto hi3
if %random% == 7 goto hi1
if %random% == 8 goto hi2
if %random% == 9 goto hi3
if %random% == 10 goto hi1
if NOT %random% == 1 goto selector
:selectorM
title Selecting Word, This may take a second...
set var1= %random%
if %random% == 1 goto hiM
if %random% == 2 goto hi2M
if %random% == 3 goto hi3M
if %random% == 4 goto hiM
if %random% == 5 goto hi2M
if %random% == 6 goto hi3M
if %random% == 7 goto hiM
if %random% == 8 goto hi2M
if %random% == 9 goto hi3M
if %random% == 10 goto hi1M
if %random% == 11 goto hi2M
if %random% == 12 goto hi3M
if %random% == 13 goto hiM
if %random% == 14 goto hi2M
if %random% == 15 goto hi3M
if %random% == 16 goto hiM
if %random% == 17 goto hi2M
if %random% == 18 goto hi3M
if %random% == 19 goto hiM
if %random% == 20 goto hi2M
if %random% == 21 goto hi3M
if %random% == 22 goto hiM
if %random% == 23 goto hi2M
if %random% == 24 goto hi3M
if %random% == 25 goto hiM
if %random% == 26 goto hi2M
if %random% == 27 goto hi3M
if %random% == 28 goto hiM
if %random% == 29 goto hi2M
if %random% == 30 goto hi3M
if %random% == 31 goto hiM
if %random% == 32 goto hi2M
if %random% == 33 goto hi3M
if %random% == 34 goto hiM
if %random% == 35 goto hi2M
if %random% == 36 goto hi3M
if %random% == 37 goto hiM
if %random% == 38 goto hi2M
if %random% == 39 goto hi3M
if %random% == 40 goto hiM
if %random% == 41 goto hi2M
if %random% == 42 goto hi3M
if %random% == 43 goto hiM
if %random% == 44 goto hi2M
if %random% == 45 goto hi3M
if %random% == 46 goto hiM
if %random% == 47 goto hi2M
if %random% == 48 goto hi3M
if %random% == 49 goto hiM
if %random% == 50 goto hi2M
if %random% == 51 goto hi3M
if %random% == 52 goto hiM
if %random% == 53 goto hi2M
if %random% == 54 goto hi3M
if %random% == 55 goto hiM
if %random% == 56 goto hi2M
if %random% == 57 goto hi3M
if %random% == 58 goto hiM
if %random% == 59 goto hi2M
if %random% == 60 goto hi3M
if NOT %random% == 1 goto selectorM
:selectorH
title Selecting Word, This may take a second...
set /a num=%random% %%60 +1
if %random% == 1 goto hi1
if %random% == 2 goto hi2
if %random% == 3 goto hi3
if %random% == 4 goto hi1
if %random% == 5 goto hi2
if %random% == 6 goto hi3
if %random% == 7 goto hi1
if %random% == 8 goto hi2
if %random% == 9 goto hi3
if %random% == 10 goto hi1
if %random% == 11 goto hi2
if %random% == 12 goto hi3
if %random% == 13 goto hi1
if %random% == 14 goto hi2
if %random% == 15 goto hi3
if %random% == 16 goto hi1
if %random% == 17 goto hi2
if %random% == 18 goto hi3
if %random% == 19 goto hi1
if %random% == 20 goto hi2
if %random% == 21 goto hi3
if %random% == 22 goto hi1
if %random% == 23 goto hi2
if %random% == 24 goto hi3
if %random% == 25 goto hi1
if %random% == 26 goto hi2
if %random% == 27 goto hi3
if %random% == 28 goto hi1
if %random% == 29 goto hi2
if %random% == 30 goto hi3
if %random% == 31 goto hi1
if %random% == 32 goto hi2
if %random% == 33 goto hi3
if %random% == 34 goto hi1
if %random% == 35 goto hi2
if %random% == 36 goto hi3
if %random% == 37 goto hi1
if %random% == 38 goto hi2
if %random% == 39 goto hi3
if %random% == 40 goto hi1
if %random% == 41 goto hi2
if %random% == 42 goto hi3
if %random% == 43 goto hi1
if %random% == 44 goto hi2
if %random% == 45 goto hi3
if %random% == 46 goto hi1
if %random% == 47 goto hi2
if %random% == 48 goto hi3
if %random% == 49 goto hi1
if %random% == 50 goto hi2
if %random% == 51 goto hi3
if %random% == 52 goto hi1
if %random% == 53 goto hi2
if %random% == 54 goto hi3
if %random% == 55 goto hi1
if %random% == 56 goto hi2
if %random% == 57 goto hi3
if %random% == 58 goto hi1
if %random% == 59 goto hi2
if %random% == 60 goto hi3
if NOT %random% == 1 goto selectorH
:selectorI
title Selecting Word, This may take a second...
set /a num=%random% %%60 +1
if %random% == 1 goto hi1
if %random% == 2 goto hi2
if %random% == 3 goto hi3
if %random% == 4 goto hi1
if %random% == 5 goto hi2
if %random% == 6 goto hi3
if %random% == 7 goto hi1
if %random% == 8 goto hi2
if %random% == 9 goto hi3
if %random% == 10 goto hi1
if %random% == 11 goto hi2
if %random% == 12 goto hi3
if %random% == 13 goto hi1
if %random% == 14 goto hi2
if %random% == 15 goto hi3
if %random% == 16 goto hi1
if %random% == 17 goto hi2
if %random% == 18 goto hi3
if %random% == 19 goto hi1
if %random% == 20 goto hi2
if %random% == 21 goto hi3
if %random% == 22 goto hi1
if %random% == 23 goto hi2
if %random% == 24 goto hi3
if %random% == 25 goto hi1
if %random% == 26 goto hi2
if %random% == 27 goto hi3
if %random% == 28 goto hi1
if %random% == 29 goto hi2
if %random% == 30 goto hi3
if %random% == 31 goto hi1
if %random% == 32 goto hi2
if %random% == 33 goto hi3
if %random% == 34 goto hi1
if %random% == 35 goto hi2
if %random% == 36 goto hi3
if %random% == 37 goto hi1
if %random% == 38 goto hi2
if %random% == 39 goto hi3
if %random% == 40 goto hi1
if %random% == 41 goto hi2
if %random% == 42 goto hi3
if %random% == 43 goto hi1
if %random% == 44 goto hi2
if %random% == 45 goto hi3
if %random% == 46 goto hi1
if %random% == 47 goto hi2
if %random% == 48 goto hi3
if %random% == 49 goto hi1
if %random% == 50 goto hi2
if %random% == 51 goto hi3
if %random% == 52 goto hi1
if %random% == 53 goto hi2
if %random% == 54 goto hi3
if %random% == 55 goto hi1
if %random% == 56 goto hi2
if %random% == 57 goto hi3
if %random% == 58 goto hi1
if %random% == 59 goto hi2
if %random% == 60 goto hi3
if NOT %random% == 1 goto selectorI
:hi1
Title Word-Guessing-Game
Echo Word Selected.
Echo Your Word is 6 Letters long, and it has somthing to do with Wrighting.
PING 1.1.1.1 -n 1 -w 4500 >NUL
Cls
Echo The First Letter Could be [!str:~%P1%,1!, P, !str:~%P3%,1!, !str:~%P4%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Second Letter Could be [!str:~%P5%,1!, !str:~%P6%,1!, !str:~%P7%,1!, E]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Thrid Letter Could be [N, !str:~%P12%,1!, !str:~%P11%,1!, !str:~%P12%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fourth Letter Could be [!str:~%P13%,1!, !str:~%P14%,1!, C, !str:~%P16%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fifth Letter Could be [!str:~%P17%,1!, I, !str:~%P19%,1!, !str:~%P20%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Sixth Letter Could be [!str:~%P24%,1!, !str:~%P23%,1!, !str:~%P22%,1!, L]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo What is your Guess?
set /p guess1=
if %guess1% == Pencil goto winner
if %guess1% == pencil goto winner
if NOT %guess1% == Pencil goto Loser
Pause
:hi2
Title Word-Guessing-Game
Echo Word Selected.
Echo Your Word is 7 Letters long, and it has somthing to do with Eyesight.
PING 1.1.1.1 -n 1 -w 4500 >NUL
Cls
Echo The First Letter Could be [!str:~%P1%,1!, !str:~%P2%,1!, !str:~%P3%,1!, !str:~%P4%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Second Letter Could be [!str:~%P5%,1!, !str:~%P6%,1!, !str:~%P7%,1!, !str:~%P8%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Thrid Letter Could be [!str:~%P9%,1!, !str:~%P12%,1!, !str:~%P11%,1!, !str:~%P12%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fourth Letter Could be [!str:~%P13%,1!, !str:~%P14%,1!, !str:~%P15%,1!, !str:~%P16%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fifth Letter Could be [!str:~%P17%,1!, !str:~%P18%,1!, !str:~%P19%,1!, !str:~%P20%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Sixth Letter Could be [!str:~%P24%,1!, !str:~%P23%,1!, !str:~%P22%,1!, !str:~%P21%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Seventh Letter Could be [!str:~%P28%,1!, !str:~%P27%,1!, !str:~%P26%,1!, !str:~%P25%,1!]
Echo What is your Guess?
set /p guess1=
if %guess1% == Glasses goto winner
if %guess1% == glasses goto winner
if NOT %guess1% == glasses goto Loser
:hi3
Title Word-Guessing-Game
Echo Word Selected.
Echo Your Word is 5 Letters long, and it has somthing to do with Clothing.
PING 1.1.1.1 -n 1 -w 4500 >NUL
Cls
Echo The First Letter Could be [!str:~%P1%,1!, !str:~%P2%,1!, !str:~%P3%,1!, !str:~%P4%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Second Letter Could be [!str:~%P5%,1!, !str:~%P6%,1!, !str:~%P7%,1!, !str:~%P8%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Thrid Letter Could be [!str:~%P9%,1!, !str:~%P12%,1!, !str:~%P11%,1!, !str:~%P12%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fourth Letter Could be [[!str:~%P13%,1!, !str:~%P14%,1!, !str:~%P15%,1!, !str:~%P16%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fifth Letter Could be [!str:~%P17%,1!, !str:~%P18%,1!, !str:~%P19%,1!, !str:~%P20%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo What is your Guess?
set /p guess1=
if %guess1% == Pants goto winner
if %guess1% == pants goto winner
if NOT %guess1% == pants goto Loser
:HiM
Title Word-Guessing-Game
Echo Word Selected.
Echo Your Word is 5 Letters long, and it has somthing to do with Clothing.
PING 1.1.1.1 -n 1 -w 4500 >NUL
Cls
Echo The First Letter Could be [!str:~%P1%,1!, !str:~%P2%,1!, !str:~%P3%,1!, !str:~%P4%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Second Letter Could be [!str:~%P5%,1!, !str:~%P6%,1!, !str:~%P7%,1!, !str:~%P8%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Thrid Letter Could be [!str:~%P9%,1!, !str:~%P12%,1!, !str:~%P11%,1!, !str:~%P12%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fourth Letter Could be [[!str:~%P13%,1!, !str:~%P14%,1!, !str:~%P15%,1!, !str:~%P16%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo The Fifth Letter Could be [!str:~%P17%,1!, !str:~%P18%,1!, !str:~%P19%,1!, !str:~%P20%,1!]
PING 1.1.1.1 -n 1 -w 2500 >NUL
Echo What is your Guess?
set /p guess1=
if %guess1% == Pants goto winner
if %guess1% == pants goto winner
if NOT %guess1% == pants goto Loser
:bye
Echo Ok then, Bye
Pause
Exit
:winner
cls
Echo Congratz, You Won!
Pause
goto starting1
:loser
cls
Echo :: ::
Echo :: ::
Echo :: ::
Echo :::: :: :: ::::
Echo :::: :: :: ::::
Echo.
Echo.
Echo.
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo :: ::
Echo ::::::::::::::
Echo.
Echo Better luck next time...
Echo.
Pause
goto starting1

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo