Implement combinations and implement turns

This commit is contained in:
Mark Veidemanis 2022-03-11 21:35:12 +00:00
parent 74bd1c4415
commit 575b3ef340
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 21 additions and 4 deletions

View File

@ -65,6 +65,8 @@ class Game(object):
self.playdeck.put(first_card)
starter = self.determine_start(first_card)
print(f"{starter} to start!")
self.player_index = self.players.index(starter)
print("player index", self.player_index)
def deal(self):
for player in self.players:
@ -88,8 +90,22 @@ class Game(object):
self.last_player = player
return is_playable
#def play_combination(self, player, *cards):
# print(f"Player {player} attempting to play combination {cards}")
def play_combination(self, player, *cards):
print(f"Player {player} attempting to play combination {cards}")
last_card = self.playdeck.last_card
for index, card in enumerate(cards):
print("Combination iter", index, card)
# Special cards only active on last card
if index == len(cards)-1:
print("We are checking the last card")
special = True
else:
special = False
is_playable = self.rules.is_playable_on(last_card, card, special)
if not is_playable:
return False
last_card = card
self.play_card(player, card)
class Player(object):
@ -156,7 +172,7 @@ class Deck(SetOfCards):
def fill(self):
for suit_str in "SHCD":
values_str_10 = [str(x) for x in range(2, 11)]
for val_str in [*values_str_10, "J", "Q", "K", "A"]:
for val_str in [*values_str_10, *"JQKA"]:
card_str = f"{suit_str}{val_str}"
print("card_str", card_str)
card = Card(card_str)
@ -251,8 +267,9 @@ class Rules(object):
return True
return False
def is_playable_on(self, bottom_card, card, special):
def is_playable_on(self, bottom_card, card, special, combination=False):
print(f"Is playable on {bottom_card} {card}")
if special:
if bottom_card in self.specials_power:
print("Bottom card in specials all")