Я создаю эту игру, в которой мне нужно сравнить карты Player1 и Player2, которые хранятся в массиве.
Каждая карточка, представляющая один элемент в массиве, состоит из значения (1-30) и цвета (КРАСНЫЙ, ЧЕРНЫЙ или ЖЕЛТЫЙ).
Моя задача - сравнить оба цветакаждой карты и стоимости каждой карты отдельно, но какой встроенный метод я должен использовать, чтобы сосредоточиться только на цвете или значении элемента?
Вот мой код:
colours = ['RED','BLACK','YELLOW']
deck = [(random.randint(1,31),random.choice(colours)) for _ in range(30)]
random.shuffle(deck)
def Player1_Cards(deck):
return deck[:15] #Player1 takes the first 15 cards from the array deck
def Player2_Cards(deck): #Player2 takes the last 15 cards from the array deck
return deck[15:]
print('Player 1`s cards are :',Player1_Cards(deck))
print('Player 2`s cards are :',Player2_Cards(deck))
#Here's what the array of Player1's Cards looks like:
[(5, 'BLACK'), (4, 'RED'), (31, 'YELLOW'), (27, 'RED'), (19, 'RED'), (6, 'YELLOW'), (11, 'YELLOW'), (17, 'BLACK'), (15, 'RED'), (20, 'BLACK'), (13, 'BLACK'), (9, 'RED'), (30, 'YELLOW'), (9, 'YELLOW'), (20, 'YELLOW')]