Я пытаюсь смоделировать колоду карт, которую можно перетасовать, создать руку из 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
Проверка сета в покере ⇐ Python
Программы на Python
1762966016
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')
Подробнее здесь: [url]https://stackoverflow.com/questions/79818010/checking-set-in-poker[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия