Karl_a_r said:
I cant figure out how to simulate the playing conditions
of the simple cardgame: war (don't ask me why, just to see
if i can, which I can't) I can't figure out how to get a
list generated that is 52 data points, using 13 numbers,
and never more than 4... would especially like it if I
could get two variables to show 26 random numbers each,
that also follow the above guidelines. I can get close,
have used every dang data analysis tool so far. Also
seems to be one thing.. like 5 of one number, or ALWAYS
COME OUT SEQUENTIALLY. Can someone shed some lite on this
please?
Define the following names.
CardNums referring to
=ROW(INDIRECT("1:52"))
Values referring to
="AKQJT98765432"
Suits referring to
="SHDC"
Cards referring to
=MID(Values,1+MOD(CardNums-1,13),1)&" "
&MID(Suits,1+INT((CardNums-1)/13),1)
Now formulas.
B1:
=INDEX(Cards,INT(1+COUNTA(Cards)*RAND()))
C1 [array formula]:
=INDEX(Cards,LARGE(IF(COUNTIF($B1:B2,Cards)=0,CardNums),
1+INT((COUNTA(Cards)-COUNTA($B1:B2))*RAND())))
B2 [array formula]:
=INDEX(Cards,LARGE(IF(COUNTIF(B1,Cards)=0,CardNums),
1+INT((COUNTA(Cards)-1)*RAND())))
C2 [array formula]:
=INDEX(Cards,LARGE(IF(COUNTIF(C1,Cards)+COUNTIF($B1:B2,Cards)=0,
CardNums),1+INT((COUNTA(Cards)-COUNTA($B1:B2)-1)*RAND())))
Fill C1:C2 into D1:AA2. This gives 2 shuffled hands of 26 cards each.
Now to play the game. More formulas. There's no good alternative to using
ancillary formulas to determine which card in which hand is the winner. I'm
assuming suit means nothing, so there can be ties, when there are ties, the
next 2 cards from each hand are played 'down' and the next card from each
hand is played face up. If that's also a tie, repeat this process. If either
hand lacks enough cards to play ties, that counts as a loss. [These are the
rules I used as a kid.]
A1 [array formula]:
=1+3*(MATCH(TRUE,CODE(T(OFFSET(B1,0,3*(ROW(INDIRECT("1:9"))-1),
1,1)))<>CODE(T(OFFSET(B2,0,3*(ROW(INDIRECT("1:9"))-1),1,1))),
0)-1)
A2:
=1+(FIND(LEFT(INDEX(B1:AZ1,A1),1),Values)>
FIND(LEFT(INDEX(B2:AZ2,A1),1),Values))
Hands after first trick. In real play, the players winning the trick isn't
careful about how s/he adds cards from the trick to his/her hand. All the
cards from the trick must all be placed on the bottom of the pile, but there
are no rules about how they should be ordered. That's too much work for me
at the moment, so I'm requiring that the losing player's cards, in order,
are added to the bottom of the winning player's pile first, then the winning
player's cards, in order.
B4:
=IF(COLUMN()-2<SUMPRODUCT(--($B1:$AZ1<>""))-$A1,
OFFSET(B1,0,$A1,1,1),IF($A2=1,
IF(COLUMN()-2<SUMPRODUCT(--($B1:$AZ1<>"")),INDEX($B2:$AZ2,
COLUMN()-1-SUMPRODUCT(--($B1:$AZ1<>""))+$A1),
IF(COLUMN()-2<SUMPRODUCT(--($B1:$AZ1<>""))+$A1,
INDEX($B1:$AZ1,COLUMN()-1-SUMPRODUCT(--($B1:$AZ1<>""))),
"")),""))
B5:
=IF(COLUMN()-2<SUMPRODUCT(--($B2:$AZ2<>""))-$A1,
OFFSET(B2,0,$A1,1,1),IF($A2=2,
IF(COLUMN()-2<SUMPRODUCT(--($B2:$AZ2<>"")),INDEX($B1:$AZ1,
COLUMN()-1-SUMPRODUCT(--($B2:$AZ2<>""))+$A1),
IF(COLUMN()-2<SUMPRODUCT(--($B2:$AZ2<>""))+$A1,
INDEX($B2:$AZ2,COLUMN()-1-SUMPRODUCT(--($B2:$AZ2<>""))),
"")),""))
Fill B4:B5 into C4:BA5. Copy A1:A2 and paste into A4:A5. For hands after
every subsequent trick, copy A4:BA5 and paste into a range 2 rows below the
second hand after the previous trick, so A7:BA8 for hands after the second
trick.
If you'd prefer not having to enter all this, download my test file (in Zip
archive).
ftp://members.aol.com/hrlngrv/war.zip