Video Poker Machine
This object was coded to simulate one of those video poker machines. Since I didn't have a real one on hand for reference, the payoffs may be off. Also, you can only draw up to three cards, even if you are holding an ace.
Commands:
@adescribe,
@create,
@describe,
@dolist,
@lock,
@name,
@pemit,
@set,
@switch,
@trigger,
@wait.
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Video Poker Machine
@@ Poker machine
@@
@@ This object was coded to simulate one of those video poker
@@ machines. Since I didn't have a real one on hand for reference,
@@ the payoffs may be off. Also, you can only draw up to three cards,
@@ even if you are holding an ace.
@@
@@ Be careful you don't miss any commas or parentheses!
@@
@@ @@ denote comment lines. Do not include those in the actual code.
@@
@@ If your MUSH supports the if() or ifelse() function, you should
@@ use those rather than switch() if possible, since switch() is not
@@ as efficient. The code will need to be modified slightly for that.
@@
@@ Note that the machine renames itself, so if you want to permanently
@@ change the name, you should edit the &XNAME attribute.
@@
@@ VCOST and AVPAY are attributes specific to Dark Metal MUSH.
@@ These attributes, and anything referring to these attributes,
@@ may need to be tweaked to get this to work on any specific MUSH.
@@ It does need to have an economy system set up, though.
@@ If the MUSH uses the hardcoded money system, use COST and APAY
@@ instead of VCOST and AVPAY. (See 'help @cost' and 'help @apay').
@@
@@ ========================================================
@create poker machine
@lock poker machine=me
@set poker machine=safe
@set poker machine=commands
@desc poker=A video poker machine. Flashing lights and promises of BIG MONEY! EXCITEMENT! try to tempt you to stick in your cash or credit cards.%r%rThe screen is currently showing:%r[u(func-showhand)]%rThe current bet is set to: [v(temp-bet)] (Max is [v(xmax-bet)]).
@adesc poker=@pemit %#=Type 'poker help' for instructions%rOOC note: the commands are not locked during the game. If you want%rto mess with someone else's game, it's possible, but that needs to be%rroleplayed out, otherwise it is considered OOC cheating.%r
&avpay poker=@trig me/func-startup=%#;
&cmd-help poker=$poker help:@pemit %#=[u(text-help)]
&cmd-payoffs poker=$poker payoffs:@pemit %#=[u(text-payoffs)]
&cmd-setbet poker=$poker bet *:@switch [hasattr(me,temp-user)]=1,{@pemit %#=Sorry, the poker machine is currently being used by [name(v(temp-user))].}, {&VCOST me=[min(v(xmax-bet),max(1,%0))];@pemit %#=Current bet set to: [v(VCOST)] (Maximum: [v(xmax-bet)]).;}
&cmd-view poker=$poker view:@pemit %#=You view your current hand:%r[repeat(=,79)]%r Card number:%b [iter(1 2 3 4 5,[ljust(##,7)])]%r[repeat(-,79)]%r[space(11)][iter(v(temp-hand),[rjust([extract(v(xcards),first(##,|),1)]<[extract(v(xsuites),rest(##,|),1)]>,7)])]%r[space(10)][iter(v(temp-discards),[rjust(switch(##,0,%b,<x>),7)])]%r[repeat(-,79)]%r 'x' marks a card you wish to discard (up to 3)%r'poker discard #', 'poker keep #', 'poker done'%r[repeat(=,79)]
&cmd-discard poker=$poker discard *:@switch [gte(words(iter(v(temp-discards),switch(##,1,1,))),3)]=1,{@pemit %#=You may not discard more than 3 cards.;},{@pemit %#=You choose to discard card %0.;&temp-discards me=[replace(v(temp-discards),%0,1)];}
&cmd-keep poker=$poker keep *:@pemit %#=You choose to keep card %0;&temp-discards me=[replace(v(temp-discards),%0,0)];
&cmd-done poker=$poker done:@switch [hasattr(me,temp-user)]=1,{@pemit %#=You draw your new cards.;@dolist 1 2 3 4 5={@switch [extract(v(temp-discards),##,1)]=1,{[setq(0,add(1,rand(words(v(temp-deck)))))];&temp-hand me=[replace(v(temp-hand),##,extract(v(temp-deck),%q0,1))];&temp-deck me=[ldelete(v(temp-deck),%q0)];},@@ null;};@wait 2={&temp-vhand poker=sort(iter(v(temp-hand),first(##,|)));&temp-shand poker=sort(iter(v(temp-hand),rest(##,|)));@trig me/func-payoffs=%#;}},{@pemit %#=The poker machine is not in play at the moment.}
&cmd-playercheck poker=$poker playercheck:@switch [u(func-checkplayer)]=1,{@pemit %#=[name(v(temp-user))] is still present!;},{&temp-user me=;&VCOST me=[v(xmax-bet)];@pemit %#=You reset the poker machine.;}
&cmd-test-payoffs poker=$ptest *:&temp-vhand poker=sort(iter(v(temp-hand),first(##,|)));&temp-shand poker=sort(iter(v(temp-hand),rest(##,|)));@pemit %#=Checking %0 on [v(temp-hand)]: [u(check-%0)];
&func-startup poker=&temp-user me=%0;&temp-deck poker=[u(xdeck0)];&temp-bet me=[v(VCOST)];&temp-discards poker=0 0 0 0 0;&temp-hand me=;@wait 1={&VCOST me=1000000;};@pemit %0=The cards are being dealt...;@dolist 1 2 3 4 5={[setq(0,add(1,rand(words(v(temp-deck)))))];&temp-hand me=[cat(v(temp-hand),extract(v(temp-deck),%q0,1))];&temp-deck me=[ldelete(v(temp-deck),%q0)];};@name me=[v(xname)] (Current player: [name(%0)]);@wait 2={@pemit %0=Your current hand:%r[u(func-showhand)]%rType 'poker view' to repeat this display, 'poker help' for help.%r'poker discard #', 'poker keep #', 'poker done'%r[repeat(=,79)];}
&func-payoffs poker=[setq(0,u(check-hand))];@pemit %0=You have [u(check-handname,%q0)]:%r[u(func-showhand)];+pay [name(v(temp-user))]=[mul(v(temp-bet),v(pays-%q0))];&VCOST me=[v(temp-bet)];@wait 2={&temp-user me=;&temp-discards me=;};@name me=[v(xname)];
&func-showhand poker=[repeat(=,79)]%r Card number:%b [iter(1 2 3 4 5,[ljust(##,7)])]%r[repeat(-,79)]%r[space(11)][iter(v(temp-hand),[rjust([extract(v(xcards),first(##,|),1)]<[extract(v(xsuites),rest(##,|),1)]>,7)])]%r[repeat(=,79)]
&func-checkplayer poker=switch(hasflag(v(temp-user),connected),0,0,switch(match(lcon(loc(me)),v(temp-user)),0,0,1))
&check-hand poker=switch(u(check-rflush),1,rflush,switch(u(check-sflush),1,sflush,switch(u(check-4kind),1,4kind,switch(u(check-fullhouse),1,fullhouse,switch(u(check-flush),1,flush,switch(u(check-straight),1,straight,switch(u(check-3kind),1,3kind,switch(u(check-2pair),1,2pair,switch(u(check-1pair),1,1pair,nothing)))))))))
&check-handname poker=switch(%0,rflush,a royal flush,sflush,a straight flush,4kind,four of a kind,fullhouse,a full house,flush,a flush,straight,a straight,3kind,three of a kind,2pair,two pairs,1pair,a high pair,nothing,nothing,ERROR: %0)
&check-rflush poker=and(u(check-flush),switch(v(temp-vhand),9 10 11 12 13,1,0))
&check-straight poker=switch(iter(v(temp-vhand),sub(##,first(v(temp-vhand)))),0 1 2 3 4,1,switch(v(temp-vhand),1 2 3 4 13,1,0))
&check-sflush poker=and(u(check-flush),u(check-straight))
&check-4kind poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),4,1)),0,1,switch(sub(extract(u(temp-vhand),2,1),extract(u(temp-vhand),5,1)),0,1,0))
&check-fullhouse poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),3,1)),0,switch(sub(extract(u(temp-vhand),4,1),extract(u(temp-vhand),5,1)),0,1,0),switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),2,1)),0,switch(sub(extract(u(temp-vhand),3,1),extract(u(temp-vhand),5,1)),0,1,0),0))
&check-flush poker=switch(u(temp-shand),1 1 1 1 1,1,2 2 2 2 2,1,3 3 3 3 3,1,4 4 4 4 4,1,0)
&check-straight poker=switch(iter(v(temp-vhand),sub(##,first(v(temp-vhand)))),0 1 2 3 4,1,switch(v(temp-vhand),1 2 3 4 13,1,0))
&check-3kind poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),3,1)),0,1,switch(sub(extract(u(temp-vhand),2,1),extract(u(temp-vhand),4,1)),0,1,switch(sub(extract(u(temp-vhand),3,1),extract(u(temp-vhand),5,1)),0,1,0)))
&check-2pair poker=switch(u(xispair,1,2),1,switch(u(xispair,3,4),1,1,switch(u(xispair,4,5),1,1,0)),switch(u(xispair,2,3),1,switch(u(xispair,4,5),1,1,0),0))
&check-1pair poker=switch(u(xishpair,1,2),1,1,switch(u(xishpair,2,3),1,1,switch(u(xishpair,3,4),1,1,switch(u(xishpair,4,5),1,1,0))))
&xname poker=Poker Machine
&xispair poker=switch(sub(extract(u(temp-vhand),%0,1),extract(u(temp-vhand),%1,1)),0,1,0)
&xishpair poker=switch(gte(extract(u(temp-vhand),%0,1),10),0,0,switch(sub(extract(u(temp-vhand),%0,1),extract(u(temp-vhand),%1,1)),0,1,0))
&xdeck0 poker=13|4 12|4 11|4 10|4 9|4 8|4 7|4 6|4 5|4 4|4 3|4 2|4 1|4 13|3 12|3 11|3 10|3 9|3 8|3 7|3 6|3 5|3 4|3 3|3 2|3 1|3 13|2 12|2 11|2 10|2 9|2 8|2 7|2 6|2 5|2 4|2 3|2 2|2 1|2 13|1 12|1 11|1 10|1 9|1 8|1 7|1 6|1 5|1 4|1 3|1 2|1 1|1
&xsuites poker=D C H S
&xcards poker=2 3 4 5 6 7 8 9 10 J Q K A
&xhands poker=rflush sflush 4kind fullhouse flush straight 3kind 2pair 1pair nothing
&xmax-bet poker=10
&text-help poker=[center(Poker commands: ,79,=)]%rpoker help --- this text%rpoker payoffs --- view the payoffs for various hands%rpoker bet <#> --- set bet amount to <#>%rpoker view --- view your hand%rpoker discard <#> --- Mark <#>'th card to be discarded.%rpoker keep <#> --- unmark a card if you change your mind.%rpoker done --- trade in cards (from 0 to 3, marked with 'poker discard #')%rpoker playercheck --- allow a new player to start a game if original player%r has disconnected or left the room.%r+pay [name(me)] --- start a game%r[repeat(-,79)]%rCoded by Tai@DM%r[repeat(=,79)]
&text-payoffs poker=[center(Poker machine payoff chart: ,79,=)]%rOn a bet of 1 unit, you win:%r%r[iter(v(xhands),[rjust(v(pays-##),8)] [u(check-handname,##)]%r)]%rNote: a pair must be Jacks or higher, and Aces count as either%rhigh or low in a straight.%r[repeat(=,79)]
&pays-rflush poker=500
&pays-sflush poker=50
&pays-4kind poker=25
&pays-fullhouse poker=8
&pays-flush poker=5
&pays-straight poker=4
&pays-3kind poker=3
&pays-2pair poker=2
&pays-1pair poker=1
&pays-nothing poker=0
@@ Temp attributes created on the poker game when it's played:
@@ &temp-user poker=the player's DB#
@@ &temp-bet poker=the current bet amount.
@@ &temp-deck poker=the cards still in the deck
@@ &temp-hand poker=the cards in the player's hand
@@ &temp-discards poker=0 1 0 0 0 --- a 1 marks a card to discard
@@ &temp-vhand poker=card values, sorted, low to high
@@ &temp-shand poker=card suites, sorted, low to high
@@
@@ This object was coded to simulate one of those video poker
@@ machines. Since I didn't have a real one on hand for reference,
@@ the payoffs may be off. Also, you can only draw up to three cards,
@@ even if you are holding an ace.
@@
@@ Be careful you don't miss any commas or parentheses!
@@
@@ @@ denote comment lines. Do not include those in the actual code.
@@
@@ If your MUSH supports the if() or ifelse() function, you should
@@ use those rather than switch() if possible, since switch() is not
@@ as efficient. The code will need to be modified slightly for that.
@@
@@ Note that the machine renames itself, so if you want to permanently
@@ change the name, you should edit the &XNAME attribute.
@@
@@ VCOST and AVPAY are attributes specific to Dark Metal MUSH.
@@ These attributes, and anything referring to these attributes,
@@ may need to be tweaked to get this to work on any specific MUSH.
@@ It does need to have an economy system set up, though.
@@ If the MUSH uses the hardcoded money system, use COST and APAY
@@ instead of VCOST and AVPAY. (See 'help @cost' and 'help @apay').
@@
@@ ========================================================
@create poker machine
@lock poker machine=me
@set poker machine=safe
@set poker machine=commands
@desc poker=A video poker machine. Flashing lights and promises of BIG MONEY! EXCITEMENT! try to tempt you to stick in your cash or credit cards.%r%rThe screen is currently showing:%r[u(func-showhand)]%rThe current bet is set to: [v(temp-bet)] (Max is [v(xmax-bet)]).
@adesc poker=@pemit %#=Type 'poker help' for instructions%rOOC note: the commands are not locked during the game. If you want%rto mess with someone else's game, it's possible, but that needs to be%rroleplayed out, otherwise it is considered OOC cheating.%r
&avpay poker=@trig me/func-startup=%#;
&cmd-help poker=$poker help:@pemit %#=[u(text-help)]
&cmd-payoffs poker=$poker payoffs:@pemit %#=[u(text-payoffs)]
&cmd-setbet poker=$poker bet *:@switch [hasattr(me,temp-user)]=1,{@pemit %#=Sorry, the poker machine is currently being used by [name(v(temp-user))].}, {&VCOST me=[min(v(xmax-bet),max(1,%0))];@pemit %#=Current bet set to: [v(VCOST)] (Maximum: [v(xmax-bet)]).;}
&cmd-view poker=$poker view:@pemit %#=You view your current hand:%r[repeat(=,79)]%r Card number:%b [iter(1 2 3 4 5,[ljust(##,7)])]%r[repeat(-,79)]%r[space(11)][iter(v(temp-hand),[rjust([extract(v(xcards),first(##,|),1)]<[extract(v(xsuites),rest(##,|),1)]>,7)])]%r[space(10)][iter(v(temp-discards),[rjust(switch(##,0,%b,<x>),7)])]%r[repeat(-,79)]%r 'x' marks a card you wish to discard (up to 3)%r'poker discard #', 'poker keep #', 'poker done'%r[repeat(=,79)]
&cmd-discard poker=$poker discard *:@switch [gte(words(iter(v(temp-discards),switch(##,1,1,))),3)]=1,{@pemit %#=You may not discard more than 3 cards.;},{@pemit %#=You choose to discard card %0.;&temp-discards me=[replace(v(temp-discards),%0,1)];}
&cmd-keep poker=$poker keep *:@pemit %#=You choose to keep card %0;&temp-discards me=[replace(v(temp-discards),%0,0)];
&cmd-done poker=$poker done:@switch [hasattr(me,temp-user)]=1,{@pemit %#=You draw your new cards.;@dolist 1 2 3 4 5={@switch [extract(v(temp-discards),##,1)]=1,{[setq(0,add(1,rand(words(v(temp-deck)))))];&temp-hand me=[replace(v(temp-hand),##,extract(v(temp-deck),%q0,1))];&temp-deck me=[ldelete(v(temp-deck),%q0)];},@@ null;};@wait 2={&temp-vhand poker=sort(iter(v(temp-hand),first(##,|)));&temp-shand poker=sort(iter(v(temp-hand),rest(##,|)));@trig me/func-payoffs=%#;}},{@pemit %#=The poker machine is not in play at the moment.}
&cmd-playercheck poker=$poker playercheck:@switch [u(func-checkplayer)]=1,{@pemit %#=[name(v(temp-user))] is still present!;},{&temp-user me=;&VCOST me=[v(xmax-bet)];@pemit %#=You reset the poker machine.;}
&cmd-test-payoffs poker=$ptest *:&temp-vhand poker=sort(iter(v(temp-hand),first(##,|)));&temp-shand poker=sort(iter(v(temp-hand),rest(##,|)));@pemit %#=Checking %0 on [v(temp-hand)]: [u(check-%0)];
&func-startup poker=&temp-user me=%0;&temp-deck poker=[u(xdeck0)];&temp-bet me=[v(VCOST)];&temp-discards poker=0 0 0 0 0;&temp-hand me=;@wait 1={&VCOST me=1000000;};@pemit %0=The cards are being dealt...;@dolist 1 2 3 4 5={[setq(0,add(1,rand(words(v(temp-deck)))))];&temp-hand me=[cat(v(temp-hand),extract(v(temp-deck),%q0,1))];&temp-deck me=[ldelete(v(temp-deck),%q0)];};@name me=[v(xname)] (Current player: [name(%0)]);@wait 2={@pemit %0=Your current hand:%r[u(func-showhand)]%rType 'poker view' to repeat this display, 'poker help' for help.%r'poker discard #', 'poker keep #', 'poker done'%r[repeat(=,79)];}
&func-payoffs poker=[setq(0,u(check-hand))];@pemit %0=You have [u(check-handname,%q0)]:%r[u(func-showhand)];+pay [name(v(temp-user))]=[mul(v(temp-bet),v(pays-%q0))];&VCOST me=[v(temp-bet)];@wait 2={&temp-user me=;&temp-discards me=;};@name me=[v(xname)];
&func-showhand poker=[repeat(=,79)]%r Card number:%b [iter(1 2 3 4 5,[ljust(##,7)])]%r[repeat(-,79)]%r[space(11)][iter(v(temp-hand),[rjust([extract(v(xcards),first(##,|),1)]<[extract(v(xsuites),rest(##,|),1)]>,7)])]%r[repeat(=,79)]
&func-checkplayer poker=switch(hasflag(v(temp-user),connected),0,0,switch(match(lcon(loc(me)),v(temp-user)),0,0,1))
&check-hand poker=switch(u(check-rflush),1,rflush,switch(u(check-sflush),1,sflush,switch(u(check-4kind),1,4kind,switch(u(check-fullhouse),1,fullhouse,switch(u(check-flush),1,flush,switch(u(check-straight),1,straight,switch(u(check-3kind),1,3kind,switch(u(check-2pair),1,2pair,switch(u(check-1pair),1,1pair,nothing)))))))))
&check-handname poker=switch(%0,rflush,a royal flush,sflush,a straight flush,4kind,four of a kind,fullhouse,a full house,flush,a flush,straight,a straight,3kind,three of a kind,2pair,two pairs,1pair,a high pair,nothing,nothing,ERROR: %0)
&check-rflush poker=and(u(check-flush),switch(v(temp-vhand),9 10 11 12 13,1,0))
&check-straight poker=switch(iter(v(temp-vhand),sub(##,first(v(temp-vhand)))),0 1 2 3 4,1,switch(v(temp-vhand),1 2 3 4 13,1,0))
&check-sflush poker=and(u(check-flush),u(check-straight))
&check-4kind poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),4,1)),0,1,switch(sub(extract(u(temp-vhand),2,1),extract(u(temp-vhand),5,1)),0,1,0))
&check-fullhouse poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),3,1)),0,switch(sub(extract(u(temp-vhand),4,1),extract(u(temp-vhand),5,1)),0,1,0),switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),2,1)),0,switch(sub(extract(u(temp-vhand),3,1),extract(u(temp-vhand),5,1)),0,1,0),0))
&check-flush poker=switch(u(temp-shand),1 1 1 1 1,1,2 2 2 2 2,1,3 3 3 3 3,1,4 4 4 4 4,1,0)
&check-straight poker=switch(iter(v(temp-vhand),sub(##,first(v(temp-vhand)))),0 1 2 3 4,1,switch(v(temp-vhand),1 2 3 4 13,1,0))
&check-3kind poker=switch(sub(extract(u(temp-vhand),1,1),extract(u(temp-vhand),3,1)),0,1,switch(sub(extract(u(temp-vhand),2,1),extract(u(temp-vhand),4,1)),0,1,switch(sub(extract(u(temp-vhand),3,1),extract(u(temp-vhand),5,1)),0,1,0)))
&check-2pair poker=switch(u(xispair,1,2),1,switch(u(xispair,3,4),1,1,switch(u(xispair,4,5),1,1,0)),switch(u(xispair,2,3),1,switch(u(xispair,4,5),1,1,0),0))
&check-1pair poker=switch(u(xishpair,1,2),1,1,switch(u(xishpair,2,3),1,1,switch(u(xishpair,3,4),1,1,switch(u(xishpair,4,5),1,1,0))))
&xname poker=Poker Machine
&xispair poker=switch(sub(extract(u(temp-vhand),%0,1),extract(u(temp-vhand),%1,1)),0,1,0)
&xishpair poker=switch(gte(extract(u(temp-vhand),%0,1),10),0,0,switch(sub(extract(u(temp-vhand),%0,1),extract(u(temp-vhand),%1,1)),0,1,0))
&xdeck0 poker=13|4 12|4 11|4 10|4 9|4 8|4 7|4 6|4 5|4 4|4 3|4 2|4 1|4 13|3 12|3 11|3 10|3 9|3 8|3 7|3 6|3 5|3 4|3 3|3 2|3 1|3 13|2 12|2 11|2 10|2 9|2 8|2 7|2 6|2 5|2 4|2 3|2 2|2 1|2 13|1 12|1 11|1 10|1 9|1 8|1 7|1 6|1 5|1 4|1 3|1 2|1 1|1
&xsuites poker=D C H S
&xcards poker=2 3 4 5 6 7 8 9 10 J Q K A
&xhands poker=rflush sflush 4kind fullhouse flush straight 3kind 2pair 1pair nothing
&xmax-bet poker=10
&text-help poker=[center(Poker commands: ,79,=)]%rpoker help --- this text%rpoker payoffs --- view the payoffs for various hands%rpoker bet <#> --- set bet amount to <#>%rpoker view --- view your hand%rpoker discard <#> --- Mark <#>'th card to be discarded.%rpoker keep <#> --- unmark a card if you change your mind.%rpoker done --- trade in cards (from 0 to 3, marked with 'poker discard #')%rpoker playercheck --- allow a new player to start a game if original player%r has disconnected or left the room.%r+pay [name(me)] --- start a game%r[repeat(-,79)]%rCoded by Tai@DM%r[repeat(=,79)]
&text-payoffs poker=[center(Poker machine payoff chart: ,79,=)]%rOn a bet of 1 unit, you win:%r%r[iter(v(xhands),[rjust(v(pays-##),8)] [u(check-handname,##)]%r)]%rNote: a pair must be Jacks or higher, and Aces count as either%rhigh or low in a straight.%r[repeat(=,79)]
&pays-rflush poker=500
&pays-sflush poker=50
&pays-4kind poker=25
&pays-fullhouse poker=8
&pays-flush poker=5
&pays-straight poker=4
&pays-3kind poker=3
&pays-2pair poker=2
&pays-1pair poker=1
&pays-nothing poker=0
@@ Temp attributes created on the poker game when it's played:
@@ &temp-user poker=the player's DB#
@@ &temp-bet poker=the current bet amount.
@@ &temp-deck poker=the cards still in the deck
@@ &temp-hand poker=the cards in the player's hand
@@ &temp-discards poker=0 1 0 0 0 --- a 1 marks a card to discard
@@ &temp-vhand poker=card values, sorted, low to high
@@ &temp-shand poker=card suites, sorted, low to high