-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsapiens_player.py
89 lines (75 loc) · 2.4 KB
/
sapiens_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''
Team Name : Sapiens
Team Members: Shreya Date, Supriya Mokashi, Zeenat Ali
'''
import random
class Player(object):
def __init__(self):
self.sAgentName = "Sapiens"
self.hand = []
self.cards = []
self.players = []
self.pastTricks = []
self.scoreMap = { } # dictionary to maintain mapping of player name and his/her score
def get_name(self):
"""
Returns a string of the agent's name
"""
return self.sAgentName
def get_hand(self):
"""
Returns a list of two character strings reprsenting cards in the agent's hand
"""
return self.hand
def new_hand(self, names):
"""
Takes a list of names of all agents in the game in clockwise playing order
and returns nothing. This method is also responsible for clearing any data
necessary for your agent to start a new round.
"""
self.players = names
self.scoreMap = { key: 0 for key in self.players }
def add_cards_to_hand(self, cards):
"""
Takes a list of two character strings representing cards as an argument
and returns nothing.
This list can be any length.
"""
self.hand = cards
def play_card(self, lead, trick):
"""
Takes a a string of the name of the player who lead the trick and
a list of cards in the trick so far as arguments.
Returns a two character string from the agents hand of the card to be played
into the trick.
"""
suit = ""
playCard = random.choice(self.hand)
if (len(trick) > 0):
suit = trick[0][0]
res = [card for card in self.hand if card[0].lower() == suit.lower()]
if (len(res) == 0):
playCard = random.choice(self.hand)
else:
playCard = random.choice(res)
else:
ace = [card for card in self.hand if card[1] == 'A']
if (len(ace) == 0):
playCard = random.choice(self.hand)
else:
playCard = random.choice(ace)
return playCard
def collect_trick(self, lead, winner, trick):
"""
Takes three arguements. Lead is the name of the player who led the trick.
Winner is the name of the player who won the trick. And trick is a four card
list of the trick that was played. Should return nothing.
"""
trickHistoryData = (lead, winner, trick)
self.pastTricks.append(trickHistoryData)
self.scoreMap[winner] += 1
def score(self):
"""
Calculates and returns the score for the game being played.
"""
return self.scoreMap[self.sAgentName]