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
PrestoPimp
Apprentice


Joined: 18 Sep 2001
Posts: 175
Location: USA

PostPosted: Mon Mar 03, 2003 5:47 pm   

Comparing Card Values
 
Hi, I'm working on a bot and I need to compare a 1-card value between two players. Does anyone know the simplest way I could achieve this without going through all the things like
#IF (@p1card=Ace)&(@p2card=King) {p1win} {
#IF (@p1card=King)&(@p2card=Queen) {p1win} {
etc.
I have it like this right now but unfortunately it still doesnt pick up that if player 2's card is higher than player 1's, it is supposed to do an alias for player2 winning, but does player1's winning alias.
Help Please
Thanks.

-Prestopimp

Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 867
Location: USA

PostPosted: Mon Mar 03, 2003 6:59 pm   
 
So you know that player 1 has a card named "Ace" and player 2 has a card named "King" (or similar)?

Two lists, one with cards, and one with points:

Ace|Two|Three|Four...
1|2|3|4...

Two variables, one for each player:
Player1Points
Player2Points

Look up the number of points each player has based on the two lists (Card is a Two->second position in the other list->2 points)

An #IF statement based on the Points variables to see who wins (maybe more than one, if you have to check for a tie.)

-Tarn
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Mar 03, 2003 7:12 pm   
 
Change the card values to numbers (2 to 14?), then just do a comparison.
#ADDK CardValues {Two=2|Three=3|Four=4|Five=5|Six=6|Seven=7|Eight=8}
#ADDK CardValues {Nine=9|Ten=10|Jack=11|Queen=12|King=13|Ace=14}
#IF (%db( @CardValues, @p1card) > %db( @CardValues, @p2card)) {p1win} {#IF (%db( @CardValues, @p1card) < %db( @CardValues, @p2card)) {p2win} {tie}}

LightBulb
Advanced Member
Reply with quote
PrestoPimp
Apprentice


Joined: 18 Sep 2001
Posts: 175
Location: USA

PostPosted: Mon Mar 03, 2003 9:23 pm   
 
If I did it that way, How could I pull a random text card value out of the database as player1 and player2's cards?
thanks.

-Prestopimp

Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Mon Mar 03, 2003 10:03 pm   
 
Tarn's example case 1 - where you need to know the value of the card for adding say to 21:
#VARIABLE CardNames "Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Jack|Queen|King|Ace"
#VARIABLE CardValue "2|3|4|5|6|7|8|9|10|11|12|13|14"
#VARIABLE Card_Pick %item(@CardValue,%random(1,%numitems(@CardValue)))
say You draw %item(@CardNames,%ismember(@Card_Pick,@CardValue)) which is worth @Card_Pick

Tarn's example case 2 - where you just draw 1 card and want to know if its higher or lower/equal (dealer wins)

#VARIABLE CardNames "Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Jack|Queen|King|Ace"
#VARIABLE CardPick1 %item(@CardNames,%random(1,%numitems(@CardNames)))
#VARIABLE CardPick2 %item(@CardNames,%random(1,%numitems(@CardNames)))
say Your @CardPick1 %if(%pos(@CardPick1,@CardNames)>%pos(@CardPick2,@CardNames),"beats","loses against") Dealers @CardPick2

The about concepts should work.

Thinking about how you can grab a random key from Lightbulb's example.
All I can come up with grabbing a random key is something like

#VARIABLE p1card %word(%item(%expanddb(@CardValues,"|",""),%random(1,%numkeys(@CardValues))),1,"=")
#VARiABLE p2card %word(%item(%expanddb(@CardValues,"|",""),%random(1,%numkeys(@CardValues))),1,"=")
#IF (%db( @CardValues, @p1card) > %db( @CardValues, @p2card)) {p1win} {#IF (%db( @CardValues, @p1card) < %db( @CardValues, @p2card)) {p2win} {tie}}

Ton Diening
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Mar 04, 2003 5:49 am   
 
I'm rather surprised that you're trying to figure out how to compare cards before you've solved the problem of drawing them. Anyway, I'd just make a list
#VAR CardNames {Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Jack|Queen|King|Ace}

And then pick an item at random.
#VAR p1Card {%item( @CardNames, %random( 1, 13))}

No need to complicate things by trying to use a variable which was designed for a different purpose.

LightBulb
Advanced Member
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 867
Location: USA

PostPosted: Tue Mar 04, 2003 7:11 pm   
 
Don't forget to remove the cards from the deck when you draw them- not only is it unfair to leave them, but you'll have irate customers when impossible hands show up.

Dealer gives himself 5 aces in a poker hand and out come the Derringers

-Tarn
Reply with quote
PrestoPimp
Apprentice


Joined: 18 Sep 2001
Posts: 175
Location: USA

PostPosted: Thu Sep 18, 2003 1:58 am   
 
After quitting and comming back and upgrading and blah blah.. I decided to pursue this venture from march further.

If there are 4 suits of each card. then How would I go about Pulling the random card, matching it with a value 1-14 and not 1-52, right now i have something like

#VARIABLE dealer_num %item( @CardValue, %random( 1, %numitems( @CardValue)))
#VAR dcardvalue %delitem( @dealer_num, @CardValue)
#VARIABLE player_num %item( @CardValue, %random( 1, %numitems( @CardValue)))
#VAR pcardvalue %delitem( @player_num, @CardValue)
#VAR dealercardname %item( @cardlist, %ismember( @dealer_num, @CardValue))


Problem is.. sometimes It wont pick a value for dealer or player number.. or it somehow picks the same card for both players even though the number is supposedly removed after each pick.

the variables for cardlist and cardvalue are:

#VAR cardlist {Ace of Spades|Ace of Hearts|Ace of Diamonds|Ace of Clubs|King of Spades|King of Hearts|King of Diamonds|King of Clubs|Queen of Spades|Queen of Hearts|Queen of Diamonds|Queen of Clubs|Jack of Spades|Jack of Hearts|Jack of Diamonds|Jack of Clubs|Ten of Spades|Ten of Hearts|Ten of Diamonds|Ten of Clubs|Nine of Spades|Nine of Hearts|Nine of Diamonds|Nine of Clubs|Eight of Spades|Eight of Hearts|Eight of Diamonds|Eight of Clubs|Seven of Spades|Seven of Hearts|Seven of Diamonds|Seven of Clubs|Six of Spades|Six of Hearts|Six of Diamonds|Six of Clubs|Five of Spades|Five of Hearts|Five of Diamonds|Five of Clubs|Four of Spades|Four of Hearts|Four of Diamonds|Four of Clubs|Three of Spades|Three of Hearts|Three of Diamonds|Three of Clubs|Two of Spades|Two of Hearts|Two of Diamonds|Two of Clubs}



#VAR CardValue {14|14|14|14|13|13|13|13|12|12|12|12|11|11|11|11|10|10|10|10|9|9|9|9|8|8|8|8|7|7|7|7|6|6|6|6|5|5|5|5|4|4|4|4|3|3|3|3|2|2|2|2|}


Please lend a hand if ya know what the problem is and how to rectify the situation. [:p]
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Sep 18, 2003 4:05 am   
 
Okay, so @cardlist is the entire deck with the highest cards first and you want to draw one card for each player and see who has the highest? zMUD uses integer division so this just requires a little math. The Aces are items 1 to 4, and dividing by 4 gives 0, 0, 0, 1. In order to get the same answer for all four of them, add 3 then divide by 4. This gives sums of 4 to 7, and dividing by 4 gives 1, 1, 1, 1. Similarly, after adding 3 and dividing by 4, all the Kings will give a result of 2, the Queens 3, etc.

#VAR TempDeck {@cardlist}
#VAR Dcard {%item( @TempDeck, %random( 1, %numitems( @TempDeck)))}
#DELI TempDeck {@Dcard}
#VAR Pcard {%item( @TempDeck, %random( 1, %numitems( @TempDeck)))}
#DELI TempDeck {@Pcard}
#IF ((%ismember( @Dcard, @cardlist) + 3)/4 > (%ismember( @Pcard, @cardlist) + 3)/4) {say Dealer draws @Dcard, Player draws @Pcard, Player wins}
#IF ((%ismember( @Dcard, @cardlist) + 3)/4 < (%ismember( @Pcard, @cardlist) + 3)/4) {say Dealer draws @Dcard, Player draws @Pcard, Dealer wins}
#IF ((%ismember( @Dcard, @cardlist) + 3)/4 = (%ismember( @Pcard, @cardlist) + 3)/4) {say Dealer draws @Dcard, Player draws @Pcard, we have a tie}
Reply with quote
PrestoPimp
Apprentice


Joined: 18 Sep 2001
Posts: 175
Location: USA

PostPosted: Thu Sep 18, 2003 5:20 am   
 
U'r the man Lightbulb.
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