我正在批量编写一个简单的扑克游戏,需要帮助检查手中的直道:第二组代码是我的卡是如何生成的(第二张卡还有另一个块,翻牌等等())
%card% = player's first card
%card2% = player's second card
%fcard% %fcard2% and %fcard3% = the three flop cards
%tcard% = the turn card
%rcard% = the river card
set /a card=%random% %% 13 + 1
set /a suit=%random% %% 4 + 1
if %card%==13 set card=Ace
if %card%==12 set card=King
if %card%==11 set card=Queen
if %card%==10 set card=Jack
if %card%==9 set card=Ten
if %card%==8 set card=Nine
if %card%==7 set card=Eight
if %card%==6 set card=Seven
if %card%==5 set card=Six
if %card%==4 set card=Five
if %card%==3 set card=Four
if %card%==2 set card=Three
if %card%==1 set card=Two
if %suit%==1 set suit=Spades
if %suit%==2 set suit=Clubs
if %suit%==3 set suit=Hearts
if %suit%==4 set suit=Diamonds
我需要能够检查任何直线(连续5张牌,如9,10,J,Q,K)
答案 0 :(得分:0)
@echo off
setlocal EnableDelayedExpansion
set "cardSet=_A23456789TJQKA"
set "i=0"
for %%a in (Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King Ace) do (
set /A i+=1
set "name[!i!]=%%a"
)
:nextSet
echo/
set /P "set=Enter a set of 5 cards separated by spaces: "
if errorlevel 1 goto :EOF
set "i=0"
for %%a in (%set%) do (
set /A i+=1
set "card[!i!]=%%a"
)
:Sort the cards
set "change="
for /L %%i in (1,1,4) do (
set /A j=%%i+1
for %%j in (!j!) do (
if !card[%%i]! gtr !card[%%j]! set /A change=card[%%i],card[%%i]=card[%%j],card[%%j]=change
)
)
if defined change goto :Sort the cards
rem Re-assemble the set in order with letters
set "set1="
for /L %%i in (1,1,5) do (
for %%j in (!card[%%i]!) do set "set1=!set1!!cardSet:~%%j,1!"
)
rem Special case: Ace is greater than King
set "set2=%set1%"
if "%set2:~0,1%" equ "A" set "set2=%set2:~1%A"
rem Test for straights
set "straight="
for /L %%i in (1,1,10) do if not defined straight (
if "%set1%" equ "!cardSet:~%%i,5!" set /A "straight=%%i+4"
if "%set2%" equ "!cardSet:~%%i,5!" set /A "straight=%%i+4"
)
if defined straight (
echo Yes, ending at !name[%straight%]!
) else (
echo No
)
goto nextSet
输出示例:
Enter a set of 5 cards separated by spaces: 8 2 7 10 13
No
Enter a set of 5 cards separated by spaces: 8 5 7 4 6
Yes, ending at Eight
Enter a set of 5 cards separated by spaces: 9 12 11 13 10
Yes, ending at King
Enter a set of 5 cards separated by spaces: 11 10 1 13 12
Yes, ending at Ace
Enter a set of 5 cards separated by spaces: 3 2 5 4 1
Yes, ending at Five