I don't know how clear my title is, but I can't think of how to title this problem. I am writing a single card game of War. It is very simple. Every round the deck is populated and shuffled. A single card is dealt to each of two players. The card with the higher value wins, and the player gets a point. If there is a tie, nobody earns the point, and a new round begins. I am reusing code from a blackjack program provided in the book I am working out of. It uses a list to organize each of the players that would be in the blackjack game. I kept the list around so I could use the functions associated with it. However, in the Blackjack game, it compared each players hand value to a dealer. In my program, I want to compare the value of the card the player holds to each other's hand.
the player object is defined like this:
[CODE=python]
class War_Player(War_ Hand):
""" A War Player. """
wins = int(0)
def lose(self):
print self.name, "loses."
def win(self):
print self.name, "wins."
wins += 1
def tie(self):
print self.name, "ties."
[/CODE]
and then there is a War_Game object with this code:
[CODE=python]
class War_Game(object ):
""" A War Game. """
def __init__(self, names):
self.players = []
for name in names:
player = War_Player(name )
self.players.ap pend(player)
self.dealer = War_Dealer("Dea ler")
self.deck = War_Deck()
self.deck.popul ate()
self.deck.shuff le()
def play(self):
# Make sure deck is populated.
self.deck.clear (self)
self.deck.popul ate(self)
self.deck.shuff le(self)
# deal card to everyone
self.deck.deal( self.players, per_hand = 1)
for player in self.players:
print player
# compare each player still playing to each other
for player in self.players
if player.total > self.dealer.tot al:
player.win()
elif player.total < self.dealer.tot al:
player.lose()
else:
player.push()
# remove everyone's cards
for player in self.players:
player.clear()
self.dealer.cle ar()
[/CODE]
the bold, italicized, underlined portions are the remnants of the Blackjack code that I can't figure out how to change to fit this. I need to change it to compare each players hand to the other players hand rather than the dealer(which i have removed from the program completely). If you could explain to me how to do it, and why it works that way, that would be great! I am frustrated that I can't seem to figure this out. Thanks in advance for any help you can give!
the player object is defined like this:
[CODE=python]
class War_Player(War_ Hand):
""" A War Player. """
wins = int(0)
def lose(self):
print self.name, "loses."
def win(self):
print self.name, "wins."
wins += 1
def tie(self):
print self.name, "ties."
[/CODE]
and then there is a War_Game object with this code:
[CODE=python]
class War_Game(object ):
""" A War Game. """
def __init__(self, names):
self.players = []
for name in names:
player = War_Player(name )
self.players.ap pend(player)
self.dealer = War_Dealer("Dea ler")
self.deck = War_Deck()
self.deck.popul ate()
self.deck.shuff le()
def play(self):
# Make sure deck is populated.
self.deck.clear (self)
self.deck.popul ate(self)
self.deck.shuff le(self)
# deal card to everyone
self.deck.deal( self.players, per_hand = 1)
for player in self.players:
print player
# compare each player still playing to each other
for player in self.players
if player.total > self.dealer.tot al:
player.win()
elif player.total < self.dealer.tot al:
player.lose()
else:
player.push()
# remove everyone's cards
for player in self.players:
player.clear()
self.dealer.cle ar()
[/CODE]
the bold, italicized, underlined portions are the remnants of the Blackjack code that I can't figure out how to change to fit this. I need to change it to compare each players hand to the other players hand rather than the dealer(which i have removed from the program completely). If you could explain to me how to do it, and why it works that way, that would be great! I am frustrated that I can't seem to figure this out. Thanks in advance for any help you can give!
Comment