diff --git a/Auto.py b/Auto.py index 0b9e3d9..a5cf85a 100644 --- a/Auto.py +++ b/Auto.py @@ -1,30 +1,36 @@ -from random import randint - -class Auto: +from random import * +from GamePlayMethods import * +class Automate: def __init__(self): pass - def playCard(Player,sofar): - r = randint(0,len(Player.hand)) + def playCard(self, Player,sofar): + r = randint(0,len(Player.hand)-1) + if(Player.hand.count(0) == 1): + Player.hand.remove(0); + Player.hasTwoOfClubs = False; + return 0; if len(sofar) == 0: - play = Player.hand(r) - Player.hand.pop(r) - elif len(sofar) > 0: + return Player.hand.pop(r) + else: lead_card = sofar[0] lead_suit = lead_card/13 + options = [] for i in Player.hand: - options = [] if i/13 == lead_suit: options.append(i) - if len(options)>0: - play = options[randint(0,len(options)-1)] - Player.hand.remove(play) - play = Player.hand(r) - Player.hand.pop(r) + if(len(options) > 0): + r = randint(0, len(options)-1) + play = options[r]; + Player.hand.remove(play); + return play + else: + r = randint(0, len(Player.hand)-1); + play = Player.hand[r]; + Player.hand.remove(play); + return play; - return play - - def passCard(Player): + def passCard(self, Player): a = Player.hand.pop() b = Player.hand.pop() c = Player.hand.pop() diff --git a/CardClass.py b/CardClass.py index 9cb0139..c626e9e 100644 --- a/CardClass.py +++ b/CardClass.py @@ -24,6 +24,14 @@ def value(card): def name_of_card(card): return value(card) + " of " + suit(card) + +def pointValue(card): + points = 0; + if(card >= 39): + points = 1; + if(card == 36): + points = 13; + return points def winner(cardList): max = cardList[0] diff --git a/GamePlayMethods.py b/GamePlayMethods.py index ae45aa9..83eb6ac 100644 --- a/GamePlayMethods.py +++ b/GamePlayMethods.py @@ -7,28 +7,24 @@ ''' import random; import CardClass; -import PlayCardAuto; +from Auto import Automate; class Game: - heartsBroken = false; - cardsPlayed = range() + heartsBroken = False; + cardsPlayed = [[],[],[],[]] def __init__(self): - self.heartsBroken = false; + self.heartsBroken = False class Player: - points = 0; - hasTwoOfClubs = false; - hand = []; - def __init__(self): - self.points = 0; - + points = 0 + hasTwoOfClubs = False def setHand(self,hand): - self.hand = hand; - self.hasTwoOfClubs = false; - if(self.hand[0] == 0) - self.hasTwoOfClubs = true; + self.hand = hand + self.hasTwoOfClubs = False; + if(self.hand[0] == 0): + self.hasTwoOfClubs = True; ''' getHand method: @@ -55,12 +51,12 @@ def playCardUser(self, sofar, card): #test if the player has the two of clubs: if(self.count(0) == 1): if(card == 0): - return [true, '']; + return [True, '']; else: - return [false, 'You must play the two of clubs on the first round.'] + return [False, 'You must play the two of clubs on the first round.'] else: self.hand.remove(card); - return [true, '']; + return [True, '']; else: leadingCard = sofar[0]; lb = (leadingCard/13)*13; @@ -71,12 +67,12 @@ def playCardUser(self, sofar, card): valids.append(hands[i]); if(len(valids) == 0): #if they have no cards of the leading suit self.hand.remove(card); - return [true,'']; + return [True,'']; else: if(valids.count(card) == 1): #if they have a card of the leading suit - return [true, '']; + return [True, '']; else: - return [false, 'You must play a card of suit:' + CardClass.suit(leadingCard)] + return [False, 'You must play a card of suit:' + CardClass.suit(leadingCard)] ''' @@ -97,12 +93,14 @@ def passCards(self, cardsToPass): ''' def playCardAuto(self, sofar): - return Auto.playCard(self, sofar); + + auto = Automate(); + return auto.playCard(self, sofar); def passCardsAuto(): - return Auto.passCard(self) + return Automate.passCard(self) - def addPassCards(self,passed); + def addPassCards(self,passed): self.hand.append(passed); self.hand.sort(); return 0; @@ -122,37 +120,4 @@ def Deal(playerList): hands = [p1,p2,p3,p4]; for i in range(4): hands[i].sort(); - playerList[i].setHand(hands[i]); - -a = Player(); -b = Player(); -c = Player(); -d = Player(); -Deal([a,b,c,d]); -for i in [a,b,c,d]: - print i.hand; - -players = [a,b,c,d]; -sofar = []; -for i in range(4): - sofar.append(PlayCardAuto.playCard()); - - - - - - - - - - - - - - - - - - - - + playerList[i].setHand(hands[i]); \ No newline at end of file