Skip to main content
2 of 3
added 4 characters in body
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.

T3RR0R
  • 141
  • 4