Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions Auto.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 8 additions & 0 deletions CardClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
79 changes: 22 additions & 57 deletions GamePlayMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand All @@ -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)]


'''
Expand All @@ -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;
Expand All @@ -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]);