Python card game error -
Python card game error -
well script runs i'm not getting error's , it's not working right. more specificly, programme supposed deal out cards, create dictionary gives each card value depending on rank , suit. cards shuffled, dealt , sorted. ever has 3c starts first. how computer supossed pick card goes through list of cards , if finds 1 has higher value previous card, plays it. works if play card (usually t(10) or higher) doesn't work, computer plays card worth less. reading :d
import random class player(): def __init__(self, hand, name): self.hand = hand self.passed = false self.name = name #computer ai playing def complay(player): if '3c' in player.hand: playcard(player, '3c') homecoming else: print previous[-1] in player.hand: if > previous[-1]: playcard(player, i) homecoming else: print 'nothing higher', i, key[i] #human options playing card def humplay(player): if preplayer[-1] == 'player1': print 'hi' homecoming else: done = false low = 0 while done == false: print player.hand if low > 1: take = raw_input('that card low, card want play?\n') else: take = raw_input('what card want play?\n') if take not in player.hand: print 'not in' go on if key[choose] > key[previous[-1]]: playcard(player, choose) done = true else: low == 1 #function playing card def playcard(player, card): place = player.hand.index(card) playcard = player.hand.pop(place) print player.name, 'has played the', playcard previous.append(playcard) preplayer.append(player.name) #sorts cards in hand def sort(player): n in range(len(player.hand)): in player.hand: place = player.hand.index(i) try: if key[i] > key[player.hand[place + 1]]: player.hand.insert(place + 1, player.hand.pop(place)) except indexerror: pass def main(): global previous global preplayer global key suits = 'cshd' mark = '3456789tjqka2' deck = [] players = [] previous = ['3l'] preplayer = [] card in mark: suit in suits: deck.append(card+suit) key = {} in range(len(deck)): key[deck[i]] = key['3l'] = -1 in deck: print i, '\t\t', key[i] random.shuffle(deck) player1 = player(deck[0::2], 'player1') player2 = player(deck[1::2], 'player2') player3 = player(deck[2::4], 'player2') player4 = player(deck[3::4], 'player3') players = [player1, player2, player3, player4] sort(player1) sort(player2) sort(player3) sort(player4) if '3c' in player1.hand: preplayer.append(player2.name) if '3c' in player2.hand: preplayer.append(player1.name) while len((player1.hand or player2.hand or player3.hand or player4.hand)) != 0: if preplayer[-1] == 'player1': complay(player2) if preplayer[-1] == 'player2': humplay(player1) main()
to determine whether computer should play card, use
for in player.hand: if > previous[-1]: playcard(player, i) homecoming
but cards strings "3c" , "td". when utilize ">" comparison, compares them as strings. string 'td' > 'qd', etc. should write little function determine value of card , utilize results of that.
ps: can see other problems below?
player1 = player(deck[0::2], 'player1') player2 = player(deck[1::2], 'player2') player3 = player(deck[2::4], 'player2') player4 = player(deck[3::4], 'player3')
python playing-cards
Comments
Post a Comment