|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Thu Nov 29, 2007 4:36 am
Embedded Alias Problem |
Ok, I've got a really nice Blackjack script, but I'm having problems with one of my aliases returning improper results.
First off, it is called from within another alias, and BOTH yes, BOTH write to the same variables. So, is the first alias not letting go
of them when it finishes writing to them? Both aliases work 100% correct from the command line. So I'm really guessing
its an access issue.
The point of the script is to turn your player into an automated Blackjack Dealer. Every single piece works correct 100%
if called manually from the command line. However with the one embedded alias, it breaks. Or at least this was true,
I've been working on the calctotal alias, and it is now a little messed up. So I know there are some problems with it IF
the person has an ace. I know how to fix that.
What it is doing, is that when it is called from the deal alias, calctotal ALWAYS returns 13. Always. It also says that
the cards it is using are AHearts and 2Hearts, regardless of what the real cards are. Which says to me that it cannot
read from the variable, and just snags the first 2 cards from the deck var.
Here is the deal alias:
Code: |
#CLASS Blackjack
#loop @numplayers {#var player%{i} ""}
#loop @numplayers {
#var player%{i}.c1 %item( @Deck, 1)
#VAR player%{i}.nc 1
emote deals the %item( @CardNames, %item( @Deck, 1)) to %item( @players, %i).
#DELNITEM Deck 1
#wait 1000
}
#var dealer.c1 %item( @Deck, 1)
#var dealer.nc 1
#DELNITEM Deck 1
emote deals a card face down to himself.
#wait 1000
#loop @numplayers {
#var player%{i}.c2 %item( @Deck, 1)
#VAR player%{i}.nc 2
emote deals the %item( @CardNames, %item( @Deck, 1)) to %item( @players, %i).
#DELNITEM Deck 1
#wait 1000
}
#var dealer.c2 %item( @Deck, 1)
#var dealer.nc 2
emote deals the %item( @CardNames, %item( @Deck, 1)) to himself.
#DELNITEM Deck 1
#wait 1000
#loop @numplayers {
#ECHO Calling Cal For Player ~#: %i
calctotal %i
#wait 1000
calctotal %i
#wait 1000
gt %item( @players, %i) hand: %item( @CardNames, @player%{i}.c1) and %item( @CardNames, @player%{i}.c2) for a total of @player%{i}.total
#wait 1000
#IF (@player%{i}.total = 21) {
#wait 1000
gt Congratulations %item( @players, %i)! You have a Blackjack!
}
}
calctotal 0
gt Dealer has the %item( @CardNames, @dealer.c2) showing
#IF (@dealer.total = 21) {
emote flips his down card and reveals the %item( @CardNames, @dealer.c1)
gt Dealer has Blackjack! Sorry, if you have a Blackjack you push, otherwise you lose.
dbj
}
#CLASS 0
|
And here is calctotal:
Code: |
#IF (%1 > 0) {
#var player%{1}.numaces 0
#var player%{1}.ac ""
#var player%{1}.total 0
#loop @player%{1}.nc {
#IF (%ismember( @player%{1}.c%{i}, @aces) > 0) {
#ADD player%{1}.numaces 1
#ADDITEM player%{1}.ac %i
}
}
#IF (@player%{1}.numaces = 0) {#LOOP @player%{1}.nc {#add player%{1}.total %item( @CardValues, @player%{1}.c%{i})}} {
#loop @player%{1}.nc {#IF (%ismember( %i, @player%{1}.ac) > 0) {#ADD player%{1}.total 11} {#ADD player%{1}.total %item( @CardValues, @player%{1}.c%{i})}}
#while (@player%{1}.numaces > 0 AND @player%{1}.total > 21) {
#ADD player%{1}.total -10
#ADD player%{1}.numaces -1
}
}
#ECHO Player Returning: @player%{1}.total
} {
#var dealer.numaces 0
#var dealer.ac ""
#var dealer.total 0
#loop @dealer.nc {
#IF (%ismember( dealer.c%{i}, @aces) > 0) {
#ADD dealer.numaces 1
#ADDITEM dealer.ac %i
}
}
#IF (@dealer.numaces = 0) {#LOOP @dealer.nc {#add dealer.total %item( @CardValues, @dealer.c%{i})}} {
#loop @dealer.nc {#IF (%ismember( %i, @dealer.ac) > 0) {#ADD dealer.total 11} {#ADD dealer.total %item( @CardValues, @dealer.c%{i})}}
#while (@dealer.numaces > 0 AND @dealer.total > 21) {
#ADD dealer.total -10
#ADD dealer.numaces -1
}
}
#ECHO Dealer Returning: @dealer.total
}
|
And here is the WHOLE THING! (NOTE: This IS a WIP, so it is complete. You have to manually edit the players var, the numplayers var, and the active var, amongst other things.) To reproduce my issue, import this, do an offline session. shuffle, wait for all 3 shuffles, deal, and watch. Then, to prove calctotal works (it doesn't properly all the time at the moment - fix if you'd like, I'll do my fix myself) run calctotal 1 (to recalc for player 1) on the command line and see what gets returned.
Code: |
#CLASS {Blackjack}
#ALIAS shuffle {Deck = "";emote is shuffling the cards...;#while (%numitems( @Deck) < 17) {#ADDITEM Deck %random( 1, 52)};#wait 1000;emote is shuffling the cards again...;#while (%numitems( @Deck) < 34) {#ADDITEM Deck %random( 1, 52)};#wait 1000;emote is shuffling the cards the final time...;#while (%numitems( @Deck) < 52) {#ADDITEM Deck %random( 1, 52)}}
#ALIAS hit {#IF (%item( @players, %1) = @active) {#loop @numplayers {#IF (%i = %1) {#add player%{i}.nc 1;#loop @player%{i}.nc {#IF (%j = @player%{i}.nc) {#var player%{i}.c%{j} %item( @Deck, 1)}};emote deals the %item( @CardNames, %item( @Deck, 1)) to %item( @players, %1).;#DELNITEM Deck 1;calctotal %i;#wait 1000;say %item( @players, %1), you now have @player%{i}.total~.;#IF (@player%{i}.total > 21) {say And I'm sorry, but you've busted.;active = %item( @players, %1 + 1);say @active it is now you turn, would you like to hit or stand?}}}} {say %item( @players, %1) please wait your turn.}}
#ALIAS reveal {}
#ALIAS compare {#wait 1000;gt Dealer stands with: @dealer.total;#loop @numplayers {gt %item( @players, %i) stayed at: @player%{i}.total;#IF (@player%{i}.total > @dealer.total) {gt You win!;pwin %i} {#IF (@stay = @dealer) {gt %item( @players, %i) receives a push;push %i} {gt Sorry, you did not beat the house!;dwin %i}}}}
#ALIAS pwin {#add pwin 1;#math player%{1}.win {@player%{1}.bet * @multiplier.normal};gt Congratulations, you have won @player%{1}.win gold coins!;#FILE 1 blackjack;#write 1 {%item( @players, %1) won @player%{1}.win off a @player%{1}.bet bet.};#close 1;#wait 1000;withdraw @player%{1}..win;give @player%{1}.win coins %item( @players, %1)}
#ALIAS charlie {#math players%{1}.win {@players%{1}.bet * @multiplier.charlie};gt Congratulations, you have won @players%{1}.win gold coins!;#FILE 1 blackjack;#write 1 {Player won @players%{1}.win off a @players%{1}.bet bet. CHARLIE};#close 1;#wait 1000;withdraw @players%{1}.win;give @players%{1}.win coins %item( @players, %1)}
#ALIAS dwin {#add dwin 1;#FILE 1 blackjack;#write 1 {Dealer won off a @player%{1}.bet bet.};#close 1}
#ALIAS accept {#loop @numplayers {#var player%{i}.bet = 0};gt %item( @betmsg, %random( 1, %numitems( @betmsg)))}
#ALIAS push {#add push 1;#FILE 1 blackjack;#write 1 {PUSH.};#close 1;#wait 1000;withdraw @player%{1}.bet;give @player%{1}.bet coins %item( @players, %1)}
#ALIAS deal {#CLASS Blackjack;#loop @numplayers {#var player%{i} ""};#loop @numplayers {#var player%{i}.c1 %item( @Deck, 1);#VAR player%{i}.nc 1;emote deals the %item( @CardNames, %item( @Deck, 1)) to %item( @players, %i).;#DELNITEM Deck 1;#wait 1000};#var dealer.c1 %item( @Deck, 1);#var dealer.nc 1;#DELNITEM Deck 1;emote deals a card face down to himself.;#wait 1000;#loop @numplayers {#var player%{i}.c2 %item( @Deck, 1);#VAR player%{i}.nc 2;emote deals the %item( @CardNames, %item( @Deck, 1)) to %item( @players, %i).;#DELNITEM Deck 1;#wait 1000};#var dealer.c2 %item( @Deck, 1);#var dealer.nc 2;emote deals the %item( @CardNames, %item( @Deck, 1)) to himself.;#DELNITEM Deck 1;#wait 1000;#loop @numplayers {#ECHO Calling Cal For Player ~#: %i;calctotal %i;#wait 1000;calctotal %i;#wait 1000;gt %item( @players, %i) hand: %item( @CardNames, @player%{i}.c1) and %item( @CardNames, @player%{i}.c2) for a total of @player%{i}.total;#wait 1000;#IF (@player%{i}.total = 21) {#wait 1000;gt Congratulations %item( @players, %i)! You have a Blackjack!}};calctotal 0;gt Dealer has the %item( @CardNames, @dealer.c2) showing;#IF (@dealer.total = 21) {emote flips his down card and reveals the %item( @CardNames, @dealer.c1);gt Dealer has Blackjack! Sorry, if you have a Blackjack you push, otherwise you lose.;dbj};#CLASS 0}
#ALIAS dbj {#loop @numplayers {#IF (@player%{i}.total = 21) {gt Ok %item( @players, %i), you push.;give @player%{i}.bet coin %item( @players, %i)} {gt Sorry %item( @players, %i) %item( lostmsg, %random( 1, 5));deposit @player%{i}.bet}};#wait 1000}
#ALIAS nextactive {#IF (%numitems( @players) < %1) {#var active (%item( @players, %1 +1);say @active~,it is now your turn.} {active = "Dealer";ddhs}}
#ALIAS ddhs {}
#ALIAS calctotal {#IF (%1 > 0) {#var player%{1}.numaces 0;#var player%{1}.ac "";#var player%{1}.total 0;#loop @player%{1}.nc {#IF (%ismember( @player%{1}.c%{i}, @aces) > 0) {#ADD player%{1}.numaces 1;#ADDITEM player%{1}.ac %i}};#IF (@player%{1}.numaces = 0) {#LOOP @player%{1}.nc {#add player%{1}.total %item( @CardValues, @player%{1}.c%{i})}} {#loop @player%{1}.nc {#IF (%ismember( %i, @player%{1}.ac) > 0) {#ADD player%{1}.total 11} {#ADD player%{1}.total %item( @CardValues, @player%{1}.c%{i})}};#while (@player%{1}.numaces > 0 AND @player%{1}.total > 21) {#ADD player%{1}.total -10;#ADD player%{1}.numaces -1}};#ECHO Player Returning: @player%{1}.total} {#var dealer.numaces 0;#var dealer.ac "";#var dealer.total 0;#loop @dealer.nc {#IF (%ismember( dealer.c%{i}, @aces) > 0) {#ADD dealer.numaces 1;#ADDITEM dealer.ac %i}};#IF (@dealer.numaces = 0) {#LOOP @dealer.nc {#add dealer.total %item( @CardValues, @dealer.c%{i})}} {#loop @dealer.nc {#IF (%ismember( %i, @dealer.ac) > 0) {#ADD dealer.total 11} {#ADD dealer.total %item( @CardValues, @dealer.c%{i})}};#while (@dealer.numaces > 0 AND @dealer.total > 21) {#ADD dealer.total -10;#ADD dealer.numaces -1}};#ECHO Dealer Returning: @dealer.total}}
#VAR push {0}
#VAR dwin {0}
#VAR pwin {0}
#VAR players {Fax}
#VAR betmsg {Now Accepting Bets!|Bids Are Now Being Accepted!|You may now place your bid!|Please place a bid!|Bid Now!|Feel Free to Bet!|Betting Time!|Go Ahead!!|Bet whenever!|You are now able to bet!|Continue to Bet!|Betting is now Allowed!|Bettin' Time!|Bet Away!|Bets' will now be accepted!|Go @player, Bet away!!|Go whenever!|Now Accepting Bids!|Biddin' Time!|Now Ready to Bet!}
#VAR CardNames {AH|2H|3H|4H|5H|6H|7H|8H|9H|10H|JH|QH|KH|AS|2S|3S|4S|5S|6S|7S|8S|9S|10S|JS|QS|KS|AD|2D|3D|4D|5D|6D|7D|8D|9D|10D|JD|QD|KD|AC|2C|3C|4C|5C|6C|7C|8C|9C|10C|JC|QC|KC}
#VAR CardValues {(1|11)|2|3|4|5|6|7|8|9|10|10|10|10|(1|11)|2|3|4|5|6|7|8|9|10|10|10|10|(1|11)|2|3|4|5|6|7|8|9|10|10|10|10|(1|11)|2|3|4|5|6|7|8|9|10|10|10|10}
#VAR Deck {5|4|25|21|16|38|52|31|18|17|46|27|15|32|12|10|51|29|33|37|42|20|49|30|6|44|28|8|11|40|9|13|48|14|43|35|24|1|47|26|3|34|7|19|2|22|41|23}
#VAR numplayers {1}
#VAR player1 {c139nc2c245numaces0actotal16}
#VAR player2 {c135nc2c249numaces1ac1total13}
#VAR player3 {c16nc2c215numaces1ac1total13}
#VAR dealer {c150nc2c236total20numaces0ac}
#VAR loops {}
#VAR multiplier {normal1blackjack2charlie2.5}
#VAR lostmsg {you've lost your bet!|your bet belongs to the house!|you've lost... too bad.|your bet is mine!|the bet was lost to the house.}
#VAR active {Dealer}
#VAR pn {1}
#VAR ncp {9}
#VAR cn {9}
#VAR aces {1|14|27|40}
#TRIGGER {(%w) tells the group, 'help'} {#wait 1000;gt Ok, %1, this game is Blackjack;#wait 1000;gt I'll briefly explain the rules associated with this particular version, if you're unfamiliar with blackjack as a game in general, read up on the internet before playing.;#wait 1000;gt The player must give a bet to me, Casino, and then the cards will be shuffled, and dealt.;#wait 1000;gt The player will be dealt 2 cards, face up, and the dealer will reveal 1 of his cards, the other stays face down until the player is done playing.;#wait 1000;gt The player will either 'hit' which means ask for another card to be added to their total, or 'stay' where their current highest total without going over 21 will be saved.;#wait 1000;gt When the player has completed by staying or going over 21, the dealer will reveal his hidden card;#wait 1000;gt The deal is forced to 'hit' if his total is under 17, and is forced to stay if his total is 17 or higher.;#wait 1000;gt CURRENTLY YOU CANNOT SPLIT, this function will be added later, once Blackjack is confirmed to be bug-free.;#wait 1000;gt The allowed bets are from 5,000 to 5,000,000. This means any bet from 5,000 to 5,000,000 may be used.;#wait 1000;gt Winning Payouts: If you win: 1.5x bet, if you win with a TRUE blackjack, (ie. Ace - Jack) :2.0x bet, and if you get a 5 card charlie: 2.5x bet (5 card charlie is having 5 cards that add up to less than 21)}
#TRIGGER {(%w) tells the group, 'odds'} {math @dwin/@pwin}
#TRIGGER {Result was: %1} {gt The current wins are: Dealer: @dwin || Players: @pwin || Ties: @push With a house to player ratio of: %1}
#TRIGGER {(%w) says, 'hit'} {#var pn %ismember( %1, @players);#wait 1000;hit %number( @pn)}
#TRIGGER {(%w) says, 'stand'} {#IF (%1 = @active) {#loop @numplayers {#IF (%i = %ismember( %1, @players)) {say thank you %1~, you have stood with @player%{i}.total;nextactive}}} {say please wait your turn %1}}
#CLASS 0
|
|
|
Last edited by ralgith on Thu Nov 29, 2007 3:51 pm; edited 1 time in total |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Nov 29, 2007 5:29 am |
Forgive me, because I just woke up in the middle of the night, but where are the two aliases trying to write to files? I don't see any #FILE or related commands in there.
Also, this syntax: @player%{i}.c2 is horrific. I'm shocked and appalled that zMUD accepts that. CMUD wouldn't take none of that jibba jabba. It should look more like this: @{player%i.c2} or even @{%concat("player",%i,".c2")}. |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Thu Nov 29, 2007 3:49 pm |
Sorry, that should be write to the same variable.
And yes, I'll change the syntax to a concat. That is much nicer :)
Though the %{i} is right out of the help files lol!
Editing original post to say variable instead of file (I posted this very late last night after much frustration. |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Thu Nov 29, 2007 6:37 pm |
Ok, I've changed it to use the concatenation and it still doesn't work when called from within the deal alias.
It always returns 13, because it thinks the cards EVERY player has on hand are the Ace and 2 of hearts.
Why can it not properly read from the .c1 and .c2 sections of the player's variable when called from within
the deal alias (which writes to those records)? |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
|
|
|
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
|
|