[Tutor] I need advice about which way to go.

Alan G alan.gauld at freenet.co.uk
Wed Aug 3 09:14:55 CEST 2005


Hi Nathan,

The problem with this problem descripton is that you have an idea
clear in your own head but the rest oif us only have the words.
So...

> I am writing a poker game and a blackjack game.

Two separate games or one game that can play both?

> I was wondering which way would be Python smart and work properly.

That depends on you really, there is no Python way to write card games
(unless you count using PyGame but even thats not mandatory). This is
really a matter of design and Python doesn't impose many limits on 
that,
there are lots of valid approaches you could take.

> I am trying to figure out whether or not to use t(n) as a card 
> indicator,
> when n = randomly drawn number.

t(n) means a function called t that takes a parameter called n. I'm
not sure how you would use that as a card indicator. Are you confusing
functions and lists? Do you mean t[n] where n is an index into a list
called t? Then if t held all the card values (or names) n could 
indicate
one particular card. That might work.

Another way could be a dictionary with a coded name per card as the 
key
along with the value. (Aces pose a problem regardless of solution 
because
they have two values)

> I could go that way, or code it as t1, t2, t3, etc.

Having 52 variables, one per card could work but seems clumsy.
Also figuring out how to deal a hand would be tricky with discreet 
variables.

> Which way is the right and correct way to go?

There is no single right way, but a collection of some sort sounds
better than a set of independant variables.

> Also for blackjack, I want to use it as playertotal = playertotal + 
> n,
> and computertotal = computertotal + n. or 1,2,3, etc. Which is 
> better?

I don't understand that bit at all?! What does 'n'represent?
What are the 1,2,3 for?

Alan G. 



More information about the Tutor mailing list