-4

I have this algorithm which is used for a deck with 52 cards, let's say i=10:

int suit = i / 13;
int cardValue = i % 13;
  • suit is from 0 to 3 for Hearts, Diamonds, Spades, Clubs
  • cardValue is from 0 to 12 for Ace, 2, 3, ... ,Jack, King, Queen

How do I deduce from known suit and cardValue to get back i?

4

2 回答 2

5

我不完全确定你在问什么,但如果只是从拥有suitand中获得“i” cardValue,这会做:

int i = suit * 13 + cardValue;
于 2013-05-11T17:25:35.097 回答
0

这段代码中的变量 i 永远不会改变。如果它从 10 开始,它将保持为 10。您只是临时更改分配的值。

于 2013-05-11T17:26:48.337 回答