Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Atreides096
Beginner


Joined: 26 Apr 2004
Posts: 15
Location: USA

PostPosted: Tue May 04, 2004 4:04 am   

Poker Script
 
I am attempting to write a script that will deal poker hands (Texas Hold'Em Style) using ZMud, but I am.. well pretty much totally stuck. It seems the obvious way is to assign 52 variables, one for each card, and then use %random.. but I am not sure how to keep it from re-dealing the same cards..Any suggestions?
Reply with quote
Kronus
Wanderer


Joined: 13 Jan 2002
Posts: 76
Location: USA

PostPosted: Tue May 04, 2004 6:03 am   
 
My programmer insticts are telling me to use arrays. But I've never used arrays in zMUD so i can't help you with that part of it. Heh, not a very helpful reply is it? Sorry...
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue May 04, 2004 6:12 am   
 
Yes, you could use 52 variables, one for each card, starting them all at 0 and setting them to 1 when the corresponding card gets dealt (or vice-versa).

A similar approach would involve a single record-variable with each cardname as a key and all the values starting at 0, then changing to 1 as the cards are dealt.

A 52-item list would probably be easier. You can have a master variable, then copy it to a temporary variable when you want a new deck and delete cards from the temporary deck as you use them.
#VAR MasterDeck {As|2s|3s|4s|5s|6s|7s|8s|9s|10s|Js|Qs|Ks}
#VAR Deck @MasterDeck
#AL nextcard {#VAR Index %random( %numitems( @Deck));#VAR Card %item( @Deck, @Index);#DELN Deck @Index;#SAY Card is @Card}

Another method would be to use just one list variable, with the full deck as a default value, and reset it when you want a new deck.
#VAR Deck {As|2s|3s|4s|5s|6s|7s|8s|9s|10s|Js|Qs|Ks} {As|2s|3s|4s|5s|6s|7s|8s|9s|10s|Js|Qs|Ks} {Poker}
#RESET Poker
WARNING #RESET by itself will reset all variables and classes to their startup state. If used with a classname, it will reset all variables and triggers in that class. To reset a single variable, make sure it's in a class by itself. WARNING

The advantage to the list approach is that the number of items remaining in the list is the number of cards remaining in the deck. There is no possibility of duplication if you delete each card (item) as you use it.
Reply with quote
Atreides096
Beginner


Joined: 26 Apr 2004
Posts: 15
Location: USA

PostPosted: Wed May 05, 2004 4:04 am   
 
First off, thanks a lot for your help.. Using the alias you provided, I've finished the script. After intense study, I even think I mostly understand it now :P

I am having one problem more problem, I'm hoping someone can help with. The variable insists on leaving a blank column at the bottom, and I am getting a blank card returned to me pretty much every hand. Because 30 of the 52 cards are dealt, and the variable has 52 entries + the blank line, about 60% of the hands get this blank card. I wrote a series of aliases (took 28 of them!) to workaround this problem, but it is still fairly major nuisance. Any suggestions?
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Wed May 05, 2004 5:00 am   
 
As a complete stab in the dark without zmud in front of me are you using the correct syntax for %random
Syntax: %random(i,j)
return a random integer >= I and <= J. If J is omitted, then I specifies the maximum value, and 0 is used as the minimum value.

lines like this
%random( %numitems( @Deck))
should probably be changed to
%random(1, %numitems( @Deck))
so that %random will not return 0/null/false/empty etc
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net