[Tutor] Still making Cribbage game, NEED HELP Please
Lie Ryan
lie.1296 at gmail.com
Fri Dec 11 12:39:24 CET 2009
On 12/10/2009 1:24 PM, Christopher schueler wrote:
> I am still working on my cribbage game..
>
> if you want rules or an outline of the rules/project information,
> it is HERE ->
> http://jongarvin.com/cawthra/files/ics3u/cribbage_project..pdf
> <http://jongarvin.com/cawthra/files/ics3u/cribbage_project.pdf>
>
> I have attached a copy of what i have so far..
> i have built a deck with 52 cards AND made a dictionary containing each
> card and its value such as Jacks and kings worth a value of 10.
>
> I was wondering if people could give me ways to finish this project
> WITHOUT CLASSES because we havent learnd them yet OR could somebody
> right their own program for this cribbage game so i can compare or get
> ideas from your coding.
>
> This also contains my PSUEDOCODE if anybody wants to review how i did
> things or what certain things do
>
First, black box evaluation, I'll just write things that comes to mind
before seeing the code:
- disallow empty names
- prompts for cards: you may want to allow user to type "3D" instead of
the card's number (the prompt "what CARD..." teases me to type the
"card" I want even if the prompt says "1 - 6").
- minor: invalid input ideally shouldn't crash the program (though many
teacher considers this outside marking criteria, since it's not
possible to draw the line).
- super-minor: try to minimize Speling erorrs (Instruction, comments,
etc). Use spell-checkers if necessary.
- minor: stylistic issues: See other command line programs to get a
"feel" of how prompt statements should look like.
General suggestion:
- See in the project description, there is a stage 1,2,3, and for
each stage there are sub-stages? Make at least one function from each
of those sub-stages. It'll make your program flow clearer.
- If you and all your teammates never played cribbage before, you'd
better seek other resources for the rule. The rule given in the
project description leaves a *lot* of thing unexplained, it is simply
impossible to write a game just from that alone.
- From reading the game rules described in the project description,
apparently the game is divided into six separate rounds. Make six
functions, each representing one round, and you main program will
simply look like this:
def play_game():
pre_game()
round_deal()
round_cut()
round_pegging()
round_show()
round_crib()
round_end()
- DRY: Don't Repeat Yourself. If you see two blocks of code
that looks similar, try to make them into a function (or loops, or
whatever seems appropriate to reduce similarity):
e.g. this two blocks looks disturbingly similar
for X in range(0,6):
Y = randint(0,ele)
draw = Deck[Y]
P1hand.append(draw)once
Deck.pop(Y)
ele -= 1
for X2 in range (0,6):
Y1 = randint(0,ele)
draw2 = Deck[Y1]
P2hand.append(draw2)
Deck.pop(Y1)
ele -= 1
- try to minimize variables, especially global variables (don't confuse
between variables and constants). e.g. ele is just the number of card
in the deck, you can use len(Deck) instead.
- It depends on you, but I think it will be easier to random.shuffle
the deck before the play and just Deck.pop() each time we need to
draw a new card rather than randomly picking from a sorted deck. It
also looks more like a real card game, where the dealer shuffled the
deck before game and just pulled the top of the decks when dealing.
- if you're using python 2.6 or above, take a look at itertools.product
if you're using python 2.7 or python 3, take a look at the new
combinatoric generators functions in itertools
Specific suggestion:
- try rewriting this using random.choice()
Top = randint(0,39)
Topcard = Deck[Top]
- try to turn these two into one function only
def GetPlayer1():
print
Player1 = str(raw_input("Player 1's name "))
return Player1
def GetPlayer2():
print
Player2 = str(raw_input("Player 2's name "))
return Player2
Crystal Ball:
- my guess why your teacher disallowed using class and object is
because his plan for your next project is to turn the cribbage game
to use classes. So, make sure you choose designs where it will be
easy to convert to objects-oriented at later date. This way, you'll
have to know both procedural and OOP while putting OOP at much better
light than if he only teach OOP.
More information about the Tutor
mailing list