2017-02-23 6 views
-2

私は単純なポーカーゲームをバッチで書いています。手の中でストレートをチェックするのに役立つ必要があります。次のコードセットは、自分のカードがどのように生成されるかです(2番目のカード、 )変数が以前のバッチより1つ大きいかどうかを確認しますか?

%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 

Iは、行の任意の直線(5枚のカードを確認できるようにする必要があるなど9,10、J、Q、K)

+0

'%card%'、 '%fcard%'とは何ですか?これは、あなたが変数値を設定する方法ではありません。いくつかのコマンドを保持しているカード変数の値はありますか? – npocmaka

+1

REAL CODEを表示する必要があります。疑似コードではありません。 – 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

これは非常に役に立ちますが、私はすでにユーザー入力では定義されていない変数でこれを行う方法を知る必要があります。私はコードに非常に単純な変更を確信しています – JohnBatch

+0

はい、私はあなたに同意します。必要な変更は非常に簡単で、あなた自身でそれを確実に行うことができます...この回答をupvoteして選択してもらえますか? – Aacini

+0

ありがとう! upvoteはどうですか? – Aacini

関連する問題