Chance in batch game?

January 31, 2011 at 03:25:58
Specs: Windows 7
How do you make a 50% chance that you can use in a batch game?
I am new to batch files, so please explain everything clearly.
If am doing something wrong, please tell me.
Please do not post replies like: "Do this, stupid." because I am new to batch files.

@echo off
:command
echo ===============
echo 1.Rock
echo 2.Paper
echo 3.Scissors
echo ===============

I give the user the chance to choose between: "Rock", "Paper", or "Scissors".
How do I make the batch file choose between the 3 randomly.
And after I add the chance, how do I set the win or lose?
,Thanks in advance
eXe


See More: Chance in batch game?

Report •

#1
January 31, 2011 at 03:36:07
set /a hand=%random% %% 3

if %hand%==0 echo rock
if %hand%==1 echo paper
if %hand%==2 echo Scissors


Report •

#2
January 31, 2011 at 03:43:32
Thanks again, Judago. Just one more thing, can you explain it? If not, it's okay. Thanks again.
-eXe

Report •

#3
January 31, 2011 at 04:32:04
See an explaunation of modulo wuth set /?


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
January 31, 2011 at 15:16:11
Yep:

If Command Extensions are enabled, then there are several dynamic
environment variables that can be expanded but which don't show up in
the list of variables displayed by SET.  These variable values are
computed dynamically each time the value of the variable is expanded.
If the user explicitly defines a variable with one of these names, then
that definition will override the dynamic one described below:

..........

%RANDOM% - expands to a random decimal number between 0 and 32767.


Modulo is a type of division where the result is only the remainder(the rest is discarded). The result can only be 0 to [divisor - 1].


Report •

#5
January 31, 2011 at 21:39:23
What do you do after:
set /a hand=%random% %% 3

if %hand%==0 echo rock
if %hand%==1 echo paper
if %hand%==2 echo Scissors


Report •

#6
January 31, 2011 at 21:43:58
What do you do after:
set /a hand=%random% %% 3

if %hand%==0 echo rock
if %hand%==1 echo paper
if %hand%==2 echo Scissors
It just closes.


Report •

#7
January 31, 2011 at 21:50:30
What do I do after writing that?

Report •

#8
January 31, 2011 at 22:50:30
it was just an example, %hand% will contain a number between 0 and 2(inclusive) based on a random number, so any can come up.

Add a:

pause

to the end of the example to see the result.

In the end you will have to add it to your game yourself.


Report •

#9
February 1, 2011 at 00:04:24
How do I set the win/lose condition?

Report •

#10
February 1, 2011 at 00:28:11
Just one more thing to help me complete my first batch game, how do I set the win / lose condition?

Report •

#11
February 1, 2011 at 00:34:41
@echo off

setlocal
set won=0
set lost=0
set tie=0


:input
echo.
title Rock, Paper Scissors (%won%won/%lost%lost/%tie%ties)

set input=
set choice=
set /p input=(R)ock, (P)aper or (S)cissors ? 
if not defined input goto input
if /i "%input:"=%"=="r" set choice=0
if /i "%input:"=%"=="rock" set choice=0
if /i "%input:"=%"=="p" set choice=1
if /i "%input:"=%"=="paper" set choice=1
if /i "%input:"=%"=="s" set choice=2
if /i "%input:"=%"=="Scissors" set choice=2
if not defined choice goto input

if %choice%==0 echo You chose     : Rock
if %choice%==1 echo You chose     : Paper
if %choice%==2 echo You Chose     : Scissors

set /a hand=%random% %% 3

if %hand%==0 echo Computer chose: Rock
if %hand%==1 echo Computer chose: Paper
if %hand%==2 echo Computer Chose: Scissors

if %hand%==%choice% (
    echo Tied result!
    set /a tie+=1
    goto input
)
if %hand%==0 (
   if %choice%==1 (
        Set victory=true
    ) else (
        set victory=false
    )
)
if %hand%==1 (
   if %choice%==2 (
        Set victory=true
    ) else (
        Set victory=false
    )
)
if %hand%==2 (
   if %choice%==0 (
        Set victory=true
    ) else (
        Set victory=false
    )
)
if "%victory%"=="true" (
    echo You won!
    set /a won+=1
) else (
    echo Computer won!
    set /a lost+=1
)
goto input


Report •

#12
February 1, 2011 at 00:58:13
Even better:

@echo off

setlocal
set won=0
set lost=0
set tie=0


:input
echo.
title Rock, Paper Scissors (%won%won/%lost%lost/%tie%ties)

set input=
set choice=
set /p input=(R)ock, (P)aper or (S)cissors ? 
if not defined input goto input
if /i "%input:"=%"=="r" set choice=0
if /i "%input:"=%"=="rock" set choice=0
if /i "%input:"=%"=="p" set choice=1
if /i "%input:"=%"=="paper" set choice=1
if /i "%input:"=%"=="s" set choice=2
if /i "%input:"=%"=="Scissors" set choice=2
if not defined choice goto input

if %choice%==0 echo You chose     : Rock
if %choice%==1 echo You chose     : Paper
if %choice%==2 echo You Chose     : Scissors

set /a hand=%random% %% 3

if %hand%==0 echo Computer chose: Rock
if %hand%==1 echo Computer chose: Paper
if %hand%==2 echo Computer Chose: Scissors

if %hand%==%choice% (
    echo Tied result!
    set /a tie+=1
    goto input
)
set victory=false

if %hand%==0 if %choice%==1 Set victory=true
if %hand%==1 if %choice%==2 Set victory=true
if %hand%==2 if %choice%==0 Set victory=true

if /i "%victory%"=="true" (
    echo You won!
    set /a won+=1
) else (
    echo Computer won!
    set /a lost+=1
)
goto input


Report •

#13
June 22, 2011 at 16:46:58
here is a batch game codes I now!
here it is:

:menu
@echo off
title Guess That Number!
echo type 1 to play
echo type 2 to exit
echo type 3 to play multiplayer
set /p C=
if "%C%"=="1" goto play
if "%C%"=="2" goto exit
if "%C%"=="3" goto multiplayer
if "%C%"=="%C%" goto invalid

:play
echo guess my favorite number 1 through 100!
set /p G=
if "%G%"=="none" goto win
if "%G%"=="%G%" goto lose
Exit

:multiplayer
echo do you want to see multiplayer instructions?
set /p MC=
if "%MC%"=="yes" goto M-instructions
if "%MC%"=="no" goto M-play

:M-instructions
echo the point of multiplayer in this game is to guess the correct number before the other player does! good luck!
pause
goto M-play

:M-play
set /p P1=type player 1's name here:
set /p P2=type player 2's name here:
echo %P1%
echo vs
echo %P2%
pause
echo to start multiplayer you need an extra player to choose the winning number!
pause
set /p N=type the winning number here:
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
echo loading...
pause
echo %P1%'s turn
echo guess my favorite number 1 through 100!
set /p MG=
if "%MG%"=="%N%" goto M-win
if "%MG%"=="%MG%" goto M-lose

:M-win
echo %MG% IS CORRECT!
echo %P1% WINS!
pause
Exit

:M-lose
echo I'm sorry, the answer %MG% is wrong. you lose!
echo %P1% LOSES!
pause
goto P2-M-play

:P2-M-play
echo %P2%'s turn
echo guess my favorite number 1 through 100!
set /p MGP2=
if "%MGP2%"=="%N%" goto P2-M-win
if "%MGP2%"=="%MGP2%" goto P2-M-lose

:p2-M-win
echo %MGP2% IS CORRECT!
echo %P2% WINS!
pause
Exit

:P2-M-lose
echo I'm sorry, the answer %G% is wrong. you lose!
echo TIE!
pause
echo and the wwinning number is...
pause
echo %N%!
pause
Exit


:win
echo %G% IS CORRECT!
pause
Exit

:lose
echo I'm sorry, the answer %G% is wrong. you lose!
pause
echo do you want to try again?
set /p Y=
if "%Y%"=="yes" goto play
if "%Y%"=="no" goto exit
if "%Y%"=="%Y%" goto invalid2

:exit
Exit

:invalid
echo I'm sorry but the command %C% is an invalid command.
pause
goto menu

:invalid2
echo I'm sorry but the command %Y% is an invalid command.
pause
goto lose

P.S. this is a guess the number game.
P.S.S. you can say this batch game is yours because I don't have a website to post it on so that's why I posted it. PEACE!


Report •

#14
June 22, 2011 at 16:48:56
Ask me for how to use batch and vbs (visual basic script).
I'm a computer GENIUS

Report •

#15
June 22, 2011 at 23:41:52
it's useful, I will conder it

Report •

Ask Question