Проверка сета в покереPython

Программы на Python
Ответить
Anonymous
 Проверка сета в покере

Сообщение Anonymous »

Я пытаюсь смоделировать колоду карт, которую можно перетасовать, создать руку из 15 человек, а затем проверить руку, чтобы увидеть, есть ли в ней три одинаковых карты.
Я добавил код, который до сих пор использовал для создания колоды, перетасовки и создания руки. Я понимаю, что есть несколько способов сделать это. Имеет ли смысл создать список, в котором каждое значение действует как счетчик номера/стоимости карты? И если да, то как мне это сделать?
#imoport dataframes
import random
import numpy

#create a list for card values
values = ['2','3','4','5','6','7','8','9','Jack','Queen','King','Ace']

#create a list for card suits
suits = ['Hearts', 'Clubs', 'Diamonds', 'Spades']

#create a list of lists called deck.
#inner brackets creates three values: x of y title (value0), value (value1), and suit (value2)
#outer brackets iterate through suits and values
deck = [[v + ' of ' + s,v,s] for s in suits for v in values]

#shuffle the deck

random.shuffle(deck)
#get a hand of the first 15 cards in the newly shuffled deck to create a hand
hand = deck [0:15]

#convert hand to a 2d numpy array
hand = numpy.array(hand)
#make a new 1 dimensional numpy array
#that is just the second column of hand
newhand = hand[:,1]

#create variables unique and count. unique is all of the unique values in newhand and count is a count of those values
unique, counts = numpy.unique(newhand, return_counts=True)

#make an array to see whether the hand contains a three of a kind
value_counter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] #creating a new list to count each value found within our hand
#(based on index, ex: value_counter[0] represents the count of values[0] which=='2')


Подробнее здесь: https://stackoverflow.com/questions/798 ... t-in-poker
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»