|
Post by oldnoob on Aug 26, 2010 19:39:11 GMT -5
I use a random number generator to choose the cards in a poker game and it works perfectly what I don't know how to do is, once a card is used how do I keep the RND function from choosing the same "card"again during the current hand? Thanks OldNoob.
|
|
|
Post by assdgasfgadfgsdfg on Aug 26, 2010 21:21:40 GMT -5
I'm working on poker one too After the random values are chosen, I store them into an array so ou can use values until the hand finish. Hope I've been useful ! I'm a noob too
|
|
|
Post by chris857 on Aug 26, 2010 22:10:57 GMT -5
Here's a specific example. Basically you fill an array with the numbers 0 to 12 and then randomly swap pairs of numbers. Even more simply put, I make all the cards and then shuffle them. Note: This example uses the Toolbox for the swap command.
dim CardArray(12) 'dim array, note that it has elements 0-12, aka 13 elements dim i dim a,b
resizetext(40*1.5,25*1.5)
printr "unshuffled" for i = 0 to 12 CardArray(i) = i 'fill array with cards so that there are no repeats printr CardArray(i) 'print out card array before shuffling next
for i = 0 to 12 a = rnd()%13 'get two random numbers from 0 to 12 b = rnd()%13 swap(CardArray(a),CardArray(b)) 'swap the ath card with the bth card next
printr printr "shuffled" for i = 0 to 12 printr CardArray(i) 'print out card array after shuffling next
|
|
|
Post by DJLinux on Aug 26, 2010 22:11:00 GMT -5
dim CardStack(51) dim i,a,b,c
for i=0 to 51 CardStack(i)=i next
' make the whole cardstack random for i=1 to 1000 a=rnd() % 52 : b=rnd() % 52 c=CardStack(a) CardStack(a)=CardStack(b) CardStack(b)=c next
dim nCardsOnStack=52 function GetNextCardFromStack() if nCardsOnstack<1 then printr "error card stack empty!" end end if nCardsOnstack=nCardsOnstack-1 return CardStack(nCardsOnStack) end function
print "player 1 get's " for i=1 to 5 print GetNextCardFromStack() + " " next printr print "player 2 get's " for i=1 to 5 print GetNextCardFromStack() + " " next printr
|
|
|
Post by oldnoob on Aug 28, 2010 3:48:15 GMT -5
Man that works like a charm, I'll work on tweaking it into my program this week, of course the next trick will be to hold some cards and draw into the card slots discarded, but...baby steps, I will try to figure it out first and if I can't understand it I'll come back here whimperin' and - a - cryin sniveling for more help, but I'm going to try NOT to. Thanks DJLinux, I'm just doing this for fun and I think you guys are all great to help us noobs. OldNoob.
|
|