如何检查批处理文件中的多个变量是否相等?

时间:2022-01-29 11:29:26

I am creating a simple batch card game and i need to be able to check for flushes (five cards of the same suit). I need to be able to check if

我正在创建一个简单的批量纸牌游戏,我需要能够检查冲洗(同一套装的五张牌)。我需要能够检查是否

%suit1% = %suit2% = %suit3% = %suit4% = %suit5%

and be able to execute a command if it is true. Yes I realize that in batch files i would use == instead of =

并且如果它是真的则能够执行命令。是的我意识到在批处理文件中我会使用==而不是=

A big thank you to everyone for answering so quickly. Does anyone have any suggestion for a code that would check for straights? (2,3,4,5,6) (10,J,Q,K,A)

非常感谢大家如此迅速地回答。有没有人对检查直道的代码有任何建议? (2,3,4,5,6)(10,J,Q,K,A)

3 个解决方案

#1


1  

to emulate AND you need consecutive IFs:

模拟AND你需要连续的IF:

 if %suit1% == %suit2% if %suit2% == %suit3% if %suit3% == %suit4% if %suit4% == %suit5% (
   echo do something
)

#2


3  

if %suit1%%suit1%%suit1%%suit1% == %suit2%%suit3%%suit4%%suit5% (
   echo do something
)

should do what you want.

应该做你想做的事。

#3


0  

For an arbitrary number of variables whose names begin with suit, you could do this:

对于名称以suit开头的任意数量的变量,您可以这样做:

set "FLAG="
for /F "tokens=1,* delims==" %%V in ('set suit') do (
    if not "%suit1%"=="%%W" set "FLAG=#"
)
if not defined FLAG echo All variables `suit_` contain equal values.

#1


1  

to emulate AND you need consecutive IFs:

模拟AND你需要连续的IF:

 if %suit1% == %suit2% if %suit2% == %suit3% if %suit3% == %suit4% if %suit4% == %suit5% (
   echo do something
)

#2


3  

if %suit1%%suit1%%suit1%%suit1% == %suit2%%suit3%%suit4%%suit5% (
   echo do something
)

should do what you want.

应该做你想做的事。

#3


0  

For an arbitrary number of variables whose names begin with suit, you could do this:

对于名称以suit开头的任意数量的变量,您可以这样做:

set "FLAG="
for /F "tokens=1,* delims==" %%V in ('set suit') do (
    if not "%suit1%"=="%%W" set "FLAG=#"
)
if not defined FLAG echo All variables `suit_` contain equal values.