|
Replies:
2
-
Pages:
1
-
Last Post:
Nov 8, 2011 5:52 PM
by: Bennjamin
|
|
|
Posts:
27
From:
I live near Portland but in Washington.
Registered:
9/18/10
|
|
|
|
Hearts
Posted:
Oct 16, 2011 1:24 PM
|
|
I am working on a project to make hearts with python!!! i used the cards class from chapter 23 to make the game... i would appreciate suggestions on how to create the AI for the computer, thanks. Here's the code so far: import random from card import Card deck = [] for suit_id in range(1, 5): for rank_id in range(1, 14): deck.append(Card(suit_id, rank_id)) playerhand = [] computerhand = [] playertricks = [] computertricks = [] lastcardwasincomputer = True for cards in range(0, 26): a = random.choice(deck) playerhand.append(a) deck.remove(a) for cards in range(0, 26): a = random.choice(deck) computerhand.append(a) deck.remove(a) yourlead = True def playerturn(): hand = "" for card in playerhand: hand.__add__(card.short_name+", ") print "Your lead. Your hand is: " + hand leadcard = raw_input("Type in card to lead:") for card in playerhand: if leadcard = card.short_name: if card.suit = "Hearts": if Heartsplayed: thecard = card cardfound = True else: pass else: thecard = card cardfound = True if cardfound: return thecard def computerturn(): # insert code here to make computer choose card, as local variable card for card in computerhand: if leadcard = card.short_name: if card.suit = "Hearts": if Heartsplayed: thecard = card cardfound = True else: pass else: thecard = card cardfound = True if cardfound: return thecard
|
|
Posts:
33
From:
Ottawa, Canada
Registered:
1/27/09
|
|
|
|
Re: Hearts
Posted:
Oct 21, 2011 7:28 PM
in response to:
Bennjamin
|
|
Hey Bennjamin,
Great project idea!
Just so you know, the code you posted on the forum isn't the same as the code you typed into IDLE. It's missing the indentation due to a bug with the forums. If you'd like other people to be able to use your code, you might want to try using a code sharing service such as Google Code or GitHub.
When you're designing an AI, you typically want to think about a strategy. What's a good strategy for playing Hearts? You can then turn that strategy into a set of rules for the computer.
Carter
|
|
Posts:
27
From:
I live near Portland but in Washington.
Registered:
9/18/10
|
|
|
|
Re: Hearts
Posted:
Nov 8, 2011 5:52 PM
in response to:
carter.sande
|
|
good idea carter! thanks! i'll keep it in mind...
|
|
|
Legend
|
|
Gold: 300
+
pts
|
|
Silver: 100
- 299
pts
|
|
Bronze: 25
- 99
pts
|
|
Manning Author
|
|
Manning Staff
|
|