PyJack

Paul Rubin http
Wed Aug 11 19:54:11 EDT 2004


jumpthewall at gmail.com (Chris Patton) writes:
> import whrandom, os

Use random rather than whrandom.  whrandom is obsolete and deprecated.
If you're imagining a situation where players will bet real money on
the hands dealt by this program, you have to get even more serious
about the sources of randomness.

> def scorer(score,playerdeck):...
>                         while d < len(playerdeck):
>                                 if score > 10 and 'A' in playerdeck:
> typevalues['A'] = 1

This is pretty ugly, changing the contents of what's conceptually a
fixed table, depending on the player score.  I think it's better to
just score the hand with A=1, then count the aces and adjust the score
accordingly.

>         while decksize < 52:
>                 a = whrandom.randint(0,12)
>                 if left[a] > 0:
>                         left[a] = left[a] - 1
>                         deck.append(types[a])
>                         decksize = decksize + 1
>                 elif left[a] == 0: pass

This is a horrendous method of shuffling the cards.  When there's only
one card left to deal, it will take several tries to find it.  See
the random.shuffle function for a direct way to shuffle.

>         humandeck = []
>         while c <= 1:
>                 humandeck.append(deck[0])
>                 del deck[0]
>                 c = c + 1

>         compdeck = []
>         c = 0
>         while c <= 1:
>                 compdeck.append(deck[0])
>                 del deck[0]
>                 c = c + 1


Move these to a function that deals one hand, and call it for
the player and the computer.

>         score = 0
>         compscore = 0
>         stay = 0
>         over = 0
>         compstay = 0
>         compover = 0

Maybe you want to think of using fewer variables, e.g. create class
instances for the two players.  Right now you only handle a two-player
game (the human and the computer).  What if you want to handle n players?



More information about the Python-list mailing list