mirror of
https://github.com/JonasunderscoreJones/EPR-Gruppenabgabe-07.git
synced 2025-10-23 01:29:19 +02:00
added compare_cards()
This commit is contained in:
parent
80c794d8e6
commit
a4f7c922b1
1 changed files with 30 additions and 6 deletions
36
game.py
36
game.py
|
@ -1,15 +1,15 @@
|
|||
__author__ = "7987847, Werner, 7347119, Fajst, 1234567, dalimeli"
|
||||
|
||||
RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
|
||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
|
||||
def create_cards():
|
||||
ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack',
|
||||
'Queen', 'King']
|
||||
suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
|
||||
card_deck = []
|
||||
|
||||
for suit in suits:
|
||||
for rank in ranks:
|
||||
card = f'{rank} of {suit}'
|
||||
for suit in SUITS:
|
||||
for rank in RANKS:
|
||||
card = {'rank': rank, 'suit': suit}
|
||||
card_deck.append(card)
|
||||
return card_deck
|
||||
|
||||
|
@ -40,6 +40,30 @@ def deal_cards(card_deck:list, players:int, cards_per_player:int):
|
|||
return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3], temp_cards[4])
|
||||
|
||||
|
||||
def compare_cards(cards_to_compare:list):
|
||||
'''
|
||||
Compares the given cards and returns the winner
|
||||
|
||||
input:
|
||||
- cards_to_compare: list
|
||||
list of cards to compare
|
||||
output:
|
||||
- winner: int
|
||||
index of the winning card
|
||||
'''
|
||||
winner = 0
|
||||
# TODO: wtf is Trumpffarbe? help
|
||||
# Trumpffarbe-condition muss auch noch implementiert werden
|
||||
for i in range(1, len(cards_to_compare)):
|
||||
if RANKS.index(cards_to_compare[i]['rank']) > RANKS.index(cards_to_compare[winner]['rank']):
|
||||
winner = i
|
||||
if RANKS.index(cards_to_compare[i]['rank']) == RANKS.index(cards_to_compare[winner]['rank']):
|
||||
if SUITS.index(cards_to_compare[i]['suit']) > SUITS.index(cards_to_compare[winner]['suit']):
|
||||
winner = i
|
||||
return winner
|
||||
|
||||
|
||||
|
||||
card_deck = create_cards()
|
||||
print(card_deck)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue