Skip to main content
added 462 characters in body
Source Link
T3RR0R
  • 141
  • 4

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
 CLS
 Set /A Matches=0,R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
rem Prompt Echo([E]xitFor Selection of Guesses N%%i [ 1 2 3 ]
  <Nul Set /P "=[E]xit or Pick Number %%i [0-9]: "
rem Capture Input of guess %%i into For Metavariable %%G
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
rem append input to current line, output newline.
   <Nul Set /P "=[%%G]"& Echo(
rem Exit Batch on Input of 'E'
   If "%%G" == "E" (Endlocal & Exit /B)
 rem Assign SetInput "N%%i=%%G"
to Guess N%%i <Nul'E'
 Set /P "=[%%G]Set "N%%i=%%G" "
rem Compare )
Input )
to Echo(NumbersRolled Number Rolled:
of Echo(same [!R1!][!R2!][!R3!]
%%i Setindex; "Matches=0"
Assign ForM%%i /LDisplay %%iValue; inIncrement (1Matches 1count 3)DoIf (EQU
   If !R%%i!"%%G" EQU== "!N%%iR%%i!" (
    Set "M%%i=!R%%i!""M%%i=%%G"
    Set /A Matches+=1
  ) )Else Set "M%%i=-"
 ))
 Set /A Score+=Echo( Matches * 100 ) * Matches +Rolled: 0[!R1!][!R2!][!R3!]
 Echo(Numbers Matched: [!M1!][!M2!][!M3!]
rem Calculate Score * Matches. 1M=100 2M=400 3M=900 ; Add to total Score ; Display
 For /F "Delims=" %%G in ('Set /A "Matches * 100 * Matches + 0" 2^> nul')Do (
  Set /A "Score+=%%G + 0"
  Echo(Points Earned this Round: %%G Score: !Score!
 )
Pause
Goto :Gameloop

'rolled' numbers get assigned to R#
'Selected' numbers ~ to N#
M# Array is used to Display Matched characters.

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
CLS
Set /A R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
  Echo([E]xit or Pick Number %%i [0-9]: 
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
   If "%%G" == "E" (Endlocal & Exit /B)
   Set "N%%i=%%G"
   <Nul Set /P "=[%%G]  "
  )
 )
 Echo(Numbers  Rolled:
 Echo( [!R1!][!R2!][!R3!]
 Set "Matches=0"
 For /L %%i in (1 1 3)Do (
  If !R%%i! EQU !N%%i! (
   Set "M%%i=!R%%i!"
   Set /A Matches+=1
  ) Else Set "M%%i=-"
 )
 Set /A Score+=( Matches * 100 ) * Matches + 0
Echo(Numbers Matched: [!M1!][!M2!][!M3!]
Echo(Score !Score!
Pause
Goto :Gameloop

'rolled' numbers get assigned to R#
'Selected' numbers ~ to N#
M# Array is used to Display Matched characters.

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
 CLS
 Set /A Matches=0,R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 For /L %%i in (1 1 3)Do (
rem Prompt For Selection of Guesses N%%i [ 1 2 3 ]
  <Nul Set /P "=[E]xit or Pick Number %%i [0-9]: "
rem Capture Input of guess %%i into For Metavariable %%G
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
rem append input to current line, output newline.
   <Nul Set /P "=[%%G]"& Echo(
rem Exit Batch on Input of 'E'
   If "%%G" == "E" (Endlocal & Exit /B)
rem Assign Input to Guess N%%i 'E'
   Set "N%%i=%%G" 
rem Compare Input to Rolled Number of same %%i index; Assign M%%i Display Value; Increment Matches count If EQU
   If "%%G" == "!R%%i!" (
    Set "M%%i=%%G"
    Set /A Matches+=1
   )Else Set "M%%i=-"
 ))
 Echo( Rolled: [!R1!][!R2!][!R3!]
 Echo(Matched: [!M1!][!M2!][!M3!]
rem Calculate Score * Matches. 1M=100 2M=400 3M=900 ; Add to total Score ; Display
 For /F "Delims=" %%G in ('Set /A "Matches * 100 * Matches + 0" 2^> nul')Do (
  Set /A "Score+=%%G + 0"
  Echo(Points Earned this Round: %%G Score: !Score!
 )
Pause
Goto :Gameloop

'rolled' numbers get assigned to R#
'Selected' numbers ~ to N#
M# Array is used to Display Matched characters.

added 4 characters in body
Source Link
T3RR0R
  • 141
  • 4

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
CLS
Set /A R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
  Echo([E]xit or Pick Number %%i [0-9]: 
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
   If "%%G" == "E" (Endlocal & Exit /B)
   Set "N%%i=%%G"
   <Nul Set /P "=[%%G]  "
  )
 )
 Echo(Numbers  Rolled:
 Echo( [!R1!][!R2!][!R3!]
 Set "Matches=0"
 For /L %%i in (1 1 3)Do (
  If !R%%i! EQU !N%%i! (
   Set "M%%i=!R%%i!"
   Set /A Matches+=1
  ) Else Set "M%%i=-"
 )
 Set /A Score+=( Matches * 100 ) * Matches + 0
Echo(Numbers Matched: [!M1!][!M2!][!M3!]
Echo(Score !Score!
Pause
Goto :Gameloop

'rolled' numbers get assigned to R# 
'Selected' numbers ~ to N# 
M# Array is used to Display Matched characters.

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
CLS
Set /A R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
  Echo([E]xit or Pick Number %%i [0-9]: 
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
   If "%%G" == "E" (Endlocal & Exit /B)
   Set "N%%i=%%G"
   <Nul Set /P "=[%%G]  "
  )
 )
 Echo(Numbers  Rolled:
 Echo( [!R1!][!R2!][!R3!]
 Set "Matches=0"
 For /L %%i in (1 1 3)Do (
  If !R%%i! EQU !N%%i! (
   Set "M%%i=!R%%i!"
   Set /A Matches+=1
  ) Else Set "M%%i=-"
 )
 Set /A Score+=( Matches * 100 ) * Matches + 0
Echo(Numbers Matched: [!M1!][!M2!][!M3!]
Echo(Score !Score!
Pause
Goto :Gameloop

'rolled' numbers get assigned to R# 'Selected' numbers ~ to N# M# Array is used to Display Matched characters.

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
CLS
Set /A R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
  Echo([E]xit or Pick Number %%i [0-9]: 
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
   If "%%G" == "E" (Endlocal & Exit /B)
   Set "N%%i=%%G"
   <Nul Set /P "=[%%G]  "
  )
 )
 Echo(Numbers  Rolled:
 Echo( [!R1!][!R2!][!R3!]
 Set "Matches=0"
 For /L %%i in (1 1 3)Do (
  If !R%%i! EQU !N%%i! (
   Set "M%%i=!R%%i!"
   Set /A Matches+=1
  ) Else Set "M%%i=-"
 )
 Set /A Score+=( Matches * 100 ) * Matches + 0
Echo(Numbers Matched: [!M1!][!M2!][!M3!]
Echo(Score !Score!
Pause
Goto :Gameloop

'rolled' numbers get assigned to R# 
'Selected' numbers ~ to N# 
M# Array is used to Display Matched characters.

Source Link
T3RR0R
  • 141
  • 4

The core logic of Number generation and comparison can be greatly simplified by using For /L and For /F loops in conjunction with indexed arrays:

@Echo Off
Setlocal EnableDelayedExpansion
:Gameloop
CLS
Set /A R1=!Random! %%9+1,R2=!Random! %%9+1,R3=!Random! %%9+1
 Echo(  
 For /L %%i in (1 1 3)Do (
  Echo([E]xit or Pick Number %%i [0-9]: 
  For /F "Delims=" %%G in ('Choice /N /C:0123456789E')Do (
   If "%%G" == "E" (Endlocal & Exit /B)
   Set "N%%i=%%G"
   <Nul Set /P "=[%%G]  "
  )
 )
 Echo(Numbers  Rolled:
 Echo( [!R1!][!R2!][!R3!]
 Set "Matches=0"
 For /L %%i in (1 1 3)Do (
  If !R%%i! EQU !N%%i! (
   Set "M%%i=!R%%i!"
   Set /A Matches+=1
  ) Else Set "M%%i=-"
 )
 Set /A Score+=( Matches * 100 ) * Matches + 0
Echo(Numbers Matched: [!M1!][!M2!][!M3!]
Echo(Score !Score!
Pause
Goto :Gameloop

'rolled' numbers get assigned to R# 'Selected' numbers ~ to N# M# Array is used to Display Matched characters.