Server Help

ASSS Custom Projects - <py> Blackjack

Anonymous - Fri Jan 28, 2005 12:36 am
Post subject: <py> Blackjack
Code: Show/Hide
#BlackJack by Chambahs
#1-25-05

from asss import *

chat = get_interface(I_CHAT)
stats = get_interface(I_STATS)



def c_deal(cmd, params, p, targ):
   points = stats.GetStat(p, STAT_KILL_POINTS, INTERVAL_RESET)+ stats.GetStat(p, STAT_FLAG_POINTS, INTERVAL_RESET)
   chat.SendMessage(p, "1000 Points have been betted. - Points Left: %d" % points -1000)
   stats.GetStat(p, % points - 1000)
   A = 11
   K = 10
   Q = 10
   J = 10
   A+J = 21
   random_card1 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   random_card2 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   random_card3 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   random_card4 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   card_total = random_card1 + random_card2
   card_total2 = random_card3 + random_card4
   chat.SendMessage(p, "Your cards are:" random_card1, random.card2 " (Total = " card_total1 ")"
   chat.SendMessage(p, "Dealers cards are:" random.card3, random.card4 " (Total = " card_total2 ")"
   if card_total < 21:
      chat.SendMessage(p, "Hit or stand? (Type ?hit or ?stand)")
   else:
      chat.SendMessage(p, "You got 21!")
      stats.GetStat(p. % points +2500)
   if random_card1 + random_card2 == A+J:
      chat.SendMessage(p, "BLACKJACK!")
      stats.GetStat(p, % points + 3000)
   

def c_hit(cmd, params, p, targ):
   hit_card1 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   hit_card2 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   hit_card3 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   hit_card4 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   hit_card5 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   hit_card6 = random(["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])
   card_total3 = card_total + hit_card1
   card_total4 = card_total + hit_card1 + hit_card2
   card_total5 = card_total + hit_card1 + hit_card2 + hit_card3
   deal_total1 = card_total2 + hit_card4
   deal_total2 = card_total2 + hit_card4 + hit_card5
   deal_total3 = card_total2 + hit_card4 + hit_card5 + hit_card6
   chat.SendMessage(p, "Hit!")
   chat.SendMessage(p, "Current Cards = " random_card1, random_card2, hit_card1 " (Total = " random_card1+random_card2+hit_card1 ")"
   if card_total3 >= 22:
      chat.SendMessage(p, "Bust! You lose, Please play again")
   else:
      chat.SendMessage(p, "Hit again or stand? (Type ?hit2 or ?stand)")

def c_hit2(cmd, params, p, targ):
   chat.SendMessage(p, "Hit!")
   chat.SendMessage(p, "Current Cards = " random_card1, random_card2, hit_card1, hit_card2 " (Total = " random_card1+random_card2+hit_card1+hit_card2 ")"
   if card_total4 >= 22:
      chat.SendMessage(p, "Bust! You lose, Please play again")
   else:
      chat.SendMessage(p, "Hit again or stand? (Type ?hit3 or ?stand)")

def C_hit3(cmd, params, p, targ):
   chat.SendMessage(p, "Hit!")
   chat.SendMessage(p, "Current Cards = " random_card1, random_card2, hit_card1, hit_card2, hit_card3 " (Total = " random_card1+random_card2+hit_card1+hit_card2+hit_card3 ")"
   if card_total5 >= 22:
      chat.SendMessage(p, "Bust! You lose, Please play Again")
   else:
      chat.SendMessage(p, "5 Card Stand! You Win!!")
      stats.GetStat(p, %points + 2000)

def c_stand(cmd, params, p, targ):
   chat.SendMessage(p, "Stay it is.")
   if card_total2 <= 17:
      chat.SendMessage(p, "The Dealer Hits! - Current Cards = " random_card2, random_card3, hit_card4 " (Total = " deal_total1 ")"
      if deal_total1 <= 17:
         chat.SendMessage(p, "The Dealer Hits Again! - Current Cards = " random_card2, random_card3, hit_card4, hit_card5 " (Total = " deal_total2 ")"
         if deal_total2 <= 17:
            chat.SendMessage(p, "The Dealer Hits Again! - Current Cards = " random_card2, random_card3, hit_card4, hit_card5, hit_card6 " (Total = " deal_total3 ")"
            if deal_total3 <= 21:
               chat.SendMessage(p, "Dealer has 5 Card Stand! You lose, Please Play Again")
            else:
               chat.SendMessage(p, "Dealer is Bust! You Win!")
         elif deal_total2 <= 18 and >= 21:
            chat.SendMessage(p, "The dealer stands with" deal_total2)
         elif deal_total2 == 21:
            chat.SendMessage(p, "Dealer has 21!")
         elif deal_total1 == A+J:
            chat.SendMessage(p, "Dealer has Blackjack!")
         else:
            chat.SendMessage(p, "Dealer is Bust! You Win!")
      elif deal_total1 <= 18 and >= 21:
         chat.SendMessage(p, "The dealer stands with" deal_total1)
      elif deal_total1 == 21:
         chat.SendMessage(p, "Dealer has 21!")
      elif deal_total1 == A+J:
         chat.SendMessage(p, "Dealer has Blackjack!")
      else:
         chat.SendMessage(p, "Dealer is Bust! You Win!")
   elif card_total2 <= 18 and >= 21:
      chat.SendMessage(p, "The dealer stands with" card_total2)
   elif card_total2 == 21:
      chat.SendMessage(p, "Dealer has 21!")
   elif card_total2 == A+J:
      chat.SendMessage(p, "Dealer has Blackjack!")
   else:
      chat.SendMessage(p, "Dealer is Bust! You Win!")


Hey, my FIRST try at making a REAL module, written in Python, not sure if im "allowed" to post it, so moderators, feel free to delete, also hence the word try, this module doesnt work, i got very frustrated, and gave up, so anyone who would like to fix it up, go for it icon_smile.gif i quit lol, btw, its a game of blackjack if you didnt notice icon_smile.gif
Anonymous - Fri Jan 28, 2005 12:37 am
Post subject:
sry for the double post, but...

"Hey, my FIRST try at making a REAL module, written in C, not sure if im "allowed" to post it, "

i meant written in python tongue.gif
Assassin2684 - Fri Jan 28, 2005 8:19 am
Post subject:
Not bad chambahs notbad.
Solo Ace - Fri Jan 28, 2005 9:40 am
Post subject:
Haha, how can you judge this Assassin, without knowing what it is? sa_tongue.gif

Indeed, it looks more like Python than C to me.
i88gerbils - Fri Jan 28, 2005 10:33 am
Post subject:
Yeah, I was about to say, "that doesn't look like C..."
Bak - Fri Jan 28, 2005 12:10 pm
Post subject:
i88gerbils wrote:
Yeah, I was about to say, "that doesn't look like C..."


and you ended up saying it anyway... that's the voice of reason losing out
i88gerbils - Fri Jan 28, 2005 1:13 pm
Post subject:
Actually, reason losing out is that i actually did say it outloud as I was reading the post, and then wrote "about to say it" using "say" as a meaning for "write". Stupid vernacular.
D1st0rt - Fri Jan 28, 2005 3:18 pm
Post subject:
One thing I noticed... 1000 credits have been betted?
Cyan~Fire - Fri Jan 28, 2005 3:48 pm
Post subject:
If you want to play blackjack, don't play subspace.
Bak - Fri Jan 28, 2005 3:58 pm
Post subject:
Code: Show/Hide
random(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])


I didn't know there was a 1 card?
Dr Brain - Fri Jan 28, 2005 5:07 pm
Post subject:
Shows what you know, Bak.

Oh, wait, never mind. I'll go hide now. icon_wink.gif
Mine GO BOOM - Fri Jan 28, 2005 6:36 pm
Post subject:
Bak wrote:
Code: Show/Hide
random(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"])


I didn't know there was a 1 card?

I fixed that part at least in his code. One thing I do have to mention, is that you have no handling for the fact that an Ace counts as either 11 or 1. Would suck if you hit on an eleven, and busted.

A way I dealt with this problem when I made blackjack for my Casio calculator, was to keep a HadAce variable. Once you draw an ace, count it as only 1, and set your HadAce variable to be true. Then when calculating your current score, if <= 11 and HadAce, add ten.
SamHughes - Fri Jan 28, 2005 6:48 pm
Post subject:
This program doesn't take into account the lower probability of drawing a second card that's the same as the first tongue.gif (and higher probabilities for other values)
Bak - Fri Jan 28, 2005 6:53 pm
Post subject:
The code isn't designed well... but it is your first try so I woun't be overly critical of that.
Solo Ace - Fri Jan 28, 2005 7:10 pm
Post subject:
Bak wrote:
The code isn't designed well... but it is your first try so I woun't be overly critical of that.

Me thought the same. icon_smile.gif
Anonymous - Fri Jan 28, 2005 7:46 pm
Post subject:
icon_sad.gif (runs, hides, and cries)
Bak - Sat Jan 29, 2005 2:24 am
Post subject:
it doesn't work because you never keep track of the player's cards... you need per player data indicating the current player's hand and the total number of aces
Mine GO BOOM - Sat Jan 29, 2005 6:41 am
Post subject:
Bak wrote:
You need to account for multiple aces.

Why?

Think about this before you answer.
Anonymous - Sat Jan 29, 2005 9:22 am
Post subject:
well, the 1 would be the ace...just rename it to A1 or something and name the A to A11 and boom you got 2 aces, so i did the right thing, w00t
i88gerbils - Sat Jan 29, 2005 4:29 pm
Post subject:
Not quite. Remember, an ace can be either AND at the player's choice (well, you can guess and if the total 11+x > 21, then the ace becomes a 1).

Keep at it though!
Anonymous - Sat Jan 29, 2005 5:15 pm
Post subject:
lol im not adding to this code, i gave up a long time ago, i leave it to the experts tongue.gif
Anonymous - Sat Jan 29, 2005 5:21 pm
Post subject:
sorry for the double post, but i just thought of some code that would sort that out

def pick_a(cmd, params, p, targ):
if random_card == A:
chat.SendMessage(p, "Use ?ace to decide if you want to use the ace as a 1 or 11")
if params == 1:
random_card = 1
elif params == 11:
random_card = 11

cmd1 = add_command("ace". pick_a)

shouldnt that work? also i just wrote that out freehand and off the top of my head, it should work tho..i think, but what do i know, im just a newbie programmer lol
SamHughes - Sat Jan 29, 2005 9:20 pm
Post subject:
There's no need to make the player actively decide whether to use the ace as a one or an eleven. If having the ace be eleven makes the player go bust, you count the ace as a one. Simple.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group