EPR-Gruppenabgabe-07/game_bot.py
2022-12-22 17:29:12 +01:00

156 lines
No EOL
3.7 KiB
Python

__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
class BOT:
def __init__(self, name, cards):
self.name = name
self.cards = cards
self.points = 0
self.trumpf = False
self.trumpf_color = None
def play_card(self, played_cards):
'''
Plays a card
input:
- played_cards: list
list of cards that have been played already
output:
- card: dict
card to play
'''
if len(played_cards) == 0:
return self.cards.pop(0)
else:
for card in self.cards:
if card['suit'] == played_cards[0]['suit']:
return self.cards.pop(self.cards.index(card))
return self.cards.pop(0)
def add_points(self, points):
'''
Adds points to the bot
input:
- points: int
points to add
'''
self.points += points
# Getters
def get_points(self, played_cards):
'''
Calculates the points of the played cards
input:
- played_cards: list
list of cards that have been played already
output:
- points: int
points of the played cards
'''
points = 0
for card in played_cards:
if card['rank'] == 'Jack':
points += 2
elif card['rank'] == 'Queen':
points += 3
elif card['rank'] == 'King':
points += 4
elif card['rank'] == 'Ace':
points += 11
return points
def get_trumpf(self, trumpf_color):
'''
Sets the trumpf color
input:
- trumpf_color: str
trumpf color
'''
self.trumpf = True
self.trumpf_color = trumpf_color
def get_trumpf_color(self):
'''
Returns the trumpf color
output:
- trumpf_color: str
trumpf color
'''
return self.trumpf_color
def get_name(self):
'''
Returns the name of the bot
output:
- name: str
name of the bot
'''
return self.name
def get_cards(self):
'''
Returns the cards of the bot
output:
- cards: list
list of cards
'''
return self.cards
def get_points(self):
'''
Returns the points of the bot
output:
- points: int
points of the bot
'''
return self.points
def get_trumpf(self):
'''
Returns if the bot has trumpf
output:
- trumpf: bool
if the bot has trumpf
'''
return self.trumpf
# Setter
def set_trumpf(self, trumpf):
'''
Sets if the bot has trumpf
input:
- trumpf: bool
if the bot has trumpf
'''
self.trumpf = trumpf
def set_cards(self, cards):
'''
Sets the cards of the bot
input:
- cards: list
list of cards
'''
self.cards = cards
def set_points(self, points):
'''
Sets the points of the bot
input:
- points: int
points of the bot
'''
self.points = points
def set_trumpf_color(self, trumpf_color):
'''
Sets the trumpf color of the bot
input:
- trumpf_color: str
trumpf color of the bot
'''
self.trumpf_color = trumpf_color
def __str__(self):
return self.name