2017-02-23 39 views
-2

我正在編寫一個簡單的撲克遊戲,需要幫助檢查手中的直線,其中:第二組代碼是我的卡片是如何生成的(第二張卡片,翻牌等等還有另一個代碼塊)檢查變量是否比批量中的前一個大一個?

%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

什麼是'%card%','%fcard%'?這不是你如何設置變量值。卡變量的值是否包含一些命令? – npocmaka

+1

你需要向我們展示真實的代碼。不是僞代碼。 – Squashman

+1

哪些卡需要按順序?變量有什麼值? – Magoo

回答

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 
+0

感謝aacini這是非常有幫助的,但是我需要知道如何做到這一點與變量已經定義不是用戶輸入。我確信它的代碼很簡單 – JohnBatch

+0

更改是的,我同意你的看法。所需的更改非常簡單,您可以自行確保...我可以要求您註冊並選擇此答案嗎? – Aacini

+0

謝謝!那麼upvote呢? – Aacini

相關問題