Your code have a couple problems. In first place, the second for command is not appropriately nested because it apply just to the first if command. This way, in the second and third if commands the %%S replaceable parameter is not defined. The way you write your code makes difficult to isolate this types of errors, so my first recommendation is to always use justification in nested commands and to place the closing parentheses in a way that clearly mark the end of each for or if construct. Below there is an example of such format.
In second place, a trace of your code results in these actions:
%%R = 1
%%S = !a%%R! = !a1! = a numeric value between 0 and 12
if !b1!==4 echo P1 has a !%%S! 4 of a kind
In the last line %%S has a numeric value, so !%%S! tries to replace the value of a variable whose name is a number! I think you forgot an array here, so I inserted card as the name of the array that store the card names as you show above:
@echo off
setlocal EnableDelayedExpansion
rem Define names of cards
set i=0
for %%a in (A 2 3 4 5 6 7 8 9 10 J Q K) do (
set card!i!=%%a
set /A i+=1
)
rem The values a1 through a9 are equal to some number that is modulus 13 (0-12)
for /L %%i in (1,1,9) do set /A a%%i=!random! %% 13
rem b1 through b4 ... signify the number of repeated cards there are to identify pairs and such.
set "b1=2" // two cards of b1 type
set "b2=0" // no cards of b2 type
set "b3=4" // four cards of b3 type
set "b4=1" // one card of b4 type
rem I am trying to call A from 0 from a3 or the 7 from 8 from a1 with this code:
for %%R in (1 3) do for %%S in (!a%%R!) do (
if !b%%R!==4 echo P1 has a !card%%S! 4 of a kind
if !b%%R!==3 echo P1 has a !card%%S! 3 of a kind
if !b%%R!==2 echo P1 has a !card%%S! pair
)
for %%T in (2 4) do for %%U in (!a%%T!) do (
if !b%%T!==4 echo CP has a !card%%U! 4 of a kind
if !b%%T!==3 echo CP has a !card%%U! 3 of a kind
if !b%%T!==2 echo CP has a !card%%U! pair
)
Output example:
C:\> test
P1 has a A pair
P1 has a Q 4 of a kind
You may also do a further simplification this way:
for %%R in (1 3) do for %%S in (!a%%R!) do (
if !b%%R! gtr 1 echo P1 has a !card%%S! !b%%R! of a kind
)
for %%T in (2 4) do for %%U in (!a%%T!) do (
if !b%%T! gtr 1 echo CP has a !card%%U! !b%%T! of a kind
)
In the last simplification, you may also define an array of "names of multiples" like "2=pair", "3=3 of a kind", etc. if you want to show a more precise result.