Перейти к публикации
  • Сейчас на странице   Всего пользователей: 0   (0 пользователей, 0 гостей)

Rooster

Программирование[8]

Рекомендованные сообщения

(изменено)

Мвп это не про переписывание с нуля каждой новой итерации, а про обрастание жиром со временем 


Изменено пользователем flysahar

b200.gif

Поделиться сообщением


Ссылка на сообщение
GoldRobot, Feanaro, Nikki Sixx и 2 другим понравилось это

Торжество разума в том, чтобы уживаться с теми, у кого этого разума нет. Вольтер.
Чтобы хорошо высыпаться, нужно спать 8 часов в день. И еще столько же ночью.

Поделиться сообщением


Ссылка на сообщение
Just.Doit написал 3 часа назад:
JuJeu написал 4 часа назад:
Just.Doit написал 4 часа назад:
GoldRobot написал 6 часов назад:

Как консалтинг вообще происходит?

Я не догоняю досихпор. Вот у вас нет по вебу серьезных человек, вы такие нанимаете сеньера на пару месяцев, он вам кодит, и уходит?

в моем понимании скорее так

есть стартап, который до этого был на уровне "из говна и палок нахуячить МВП" - гипотеза оказалась денежной, подняли дохуя бабла инвестиций - как их лучше всего потратить (особенно учитывая рынок, убегающий от тебя к конкруентам)? нанимается челик на короткий период со "сверх компетенциями" (по крайней мере его так продают) который их передает, закладывает технические основы (архитектуры, инфраструктуры, процессов и тд) будущего продукта с определенными требованиями (производительность, красивость, способность гдето быть гибким) и определенным будущим (большая масштабируемость, поддержка и развитие "более заурядными" проггерами).

 

Архитектуру и стэк закладывают до мвп.

лол

мвп это почти что прототип

потом это всё переписывается к хуям

потому что на этапе мвп не понятно что нужно и как и делается все "lean" тоесть поминимуму

не исключаю что большое количество сервисов развивают то что сделали на этапе мвп, просто потому что этого достаточно

но уж точно до мвп не прорабатывают архитектуру будущего продукта который смасштабирован до уровня миллионов пользователей


Изменено 3 часа назад пользователем Just.Doit

Что-то у тебя плохо с мат. частью. Закладывают в начале, плюс в эпоху клауда это всё делается на раз-два.

 

flysahar написал 1 час назад:

Мвп это не про переписывание с нуля каждой новой итерации, а про обрастание жиром со временем 


Изменено 1 час назад пользователем flysahar

хоть кто-то шарит :pidorasy:


Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
 

Поделиться сообщением


Ссылка на сообщение
(изменено)
Kant написал 32 минуты назад:

~320 кейсов в одном switch...

 

хотя я конеш не шарю за геймдев, мб это ваще нормально

 

2к звезд :trollface:


Изменено пользователем `KV

DB: click

Поделиться сообщением


Ссылка на сообщение
`KV написал 15 минут назад:
Kant написал 47 минут назад:

~320 кейсов в одном switch...

 

хотя я конеш не шарю за геймдев, мб это ваще нормально

 

2к звезд :trollface:


Изменено 13 минут назад пользователем `KV

ну там вообще гениальное форматирование текста и название переменных. Особенное однолайнеры нравятся с entity++.


Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
 

Поделиться сообщением


Ссылка на сообщение

Конкретно в этом случае от "консалтинга" лишь тот факт что материнская компания называется Boston Consulting Group. Он с коллегами работает в подразделении, которое пилит мвп стартапов для больших компаний, называется Digital Ventures. И вот он с частью команды куда-то высаживается и что-то пилит с нуля полгода+ и потом идет на следующий проект. Скорее всего они и "настоящим" консалтингом может быть занимаются, но конкретно сейчас они вот в Сингапуре заняты доведением стартапа до беты, после чего они все свалят (в конце января).


userbar-53933.png

http://codepen.io/suez/ - they see me bydlocoding, they hatin.

Поделиться сообщением


Ссылка на сообщение

а, ну BCG, это многое объясняет :)


DB: click

Поделиться сообщением


Ссылка на сообщение
`KV написал 6 часов назад:

~320 кейсов в одном switch...

 

хотя я конеш не шарю за геймдев, мб это ваще нормально

Как минимум говно то что для всех этих 320 кейсов нет перечисления.

Человек сам как эту хуету читает?

Ужас


ward написал 04.01.2022 в 02:54:

Hades для стада долбоебичей которые прокликивали Дэш и думали ебать они в артхаузнвй рогалик играют, не такие как все.

mazt3r написал 20.09.2019 в 11:27:

ласт оф ас - хуета для лисят и прочих мальчиков с вагиной между ног.

 

Поделиться сообщением


Ссылка на сообщение

Гайс, а подскажите, тут был парень - профессор или что-то такое, в питон для веба врывался. как у него дела, дропнул уже или еще не?


Найди себе дело по душе и ты не будешь работать ни одного дня в своей жизни

Поделиться сообщением


Ссылка на сообщение
(изменено)

Привет! Народ, кто может помочь с кодом? Делов на 5 минут. Я плохо ориентируюсь. Язык Python. У меня есть код с гитхаба, нужно из него взять несколько блоков и соединить. Весь код переделывать не надо.

Что нужно:

 

1. Создаётся колода.

2. Раздаются карты игрокам и на стол.

3. Считаются комбинации игроков.

4. Комбинации сравниваются и выбирается победитель/и.

5. Данные выводятся в консоль.

 

Пример:
Board: 5c 6d Ac 4h 2h
Player 1: 5h Ad
Player 2: Kc Kh
Player 3: Qd Jс
Player 4: 10s 9c
Player 5: 8s Jh
Player 6: 2d 3h

Win: Player 6
Win: Straight - 2h 3h 4h 5c 6d 

 

Если победителей несколько, то список идёт вниз по порядку.

 

Я уже спрашивал на популярных сайтах по кодингу, но там молчат. Я сам бы мог, но просто у меня на это уйдет недели две. Помогите пожалуйста, кому нетрудно. 

 

  КОД
# Constants
suit_index_dict = {"s": 0, "c": 1, "h": 2, "d": 3}
reverse_suit_index = ("s", "c", "h", "d")
val_string = "AKQJT98765432"
hand_rankings = ("High Card", "Pair", "Two Pair", "Three of a Kind",
                 "Straight", "Flush", "Full House", "Four of a Kind",
                 "Straight Flush", "Royal Flush")
suit_value_dict = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14}
for num in range(2, 10):
    suit_value_dict[str(num)] = num
 
class Card:
    # Takes in strings of the format: "As", "Tc", "6d"
    def __init__(self, card_string):
        value, self.suit = card_string[0], card_string[1]
        self.value = suit_value_dict[value]
        self.suit_index = suit_index_dict[self.suit]
 
    def __str__(self):
        return val_string[14 - self.value] + self.suit
 
    def __repr__(self):
        return val_string[14 - self.value] + self.suit
 
    def __eq__(self, other):
        if self is None:
            return other is None
        elif other is None:
            return False
        return self.value == other.value and self.suit == other.suit
 
# Returns deck of cards with all hole cards and board cards removed
def generate_deck(hole_cards, board):
    deck = []
    for suit in reverse_suit_index:
        for value in val_string:
            deck.append(Card(value + suit))
    taken_cards = []
    for hole_card in hole_cards:
        for card in hole_card:
            if card is not None:
                taken_cards.append(card)
    if board and len(board) > 0:
        taken_cards.extend(board)
    for taken_card in taken_cards:
        deck.remove(taken_card)
    return tuple(deck)
 
# Generate all possible hole card combinations
def generate_hole_cards(deck):
    import itertools
    return itertools.combinations(deck, 2)
 
# Generate num_iterations random boards
def generate_random_boards(deck, num_iterations, board_length):
    import random
    import time
    random.seed(time.time())
    for _ in xrange(num_iterations):
        yield random.sample(deck, 5 - board_length)
 
# Generate all possible boards
def generate_exhaustive_boards(deck, num_iterations, board_length):
    import itertools
    return itertools.combinations(deck, 5 - board_length)
 
# Returns a board of cards all with suit = flush_index
def generate_suit_board(flat_board, flush_index):
    histogram = [card.value for card in flat_board
                 if card.suit_index == flush_index]
    histogram.sort(reverse=True)
    return histogram
 
# Returns a list of two tuples of the form: (value of card, frequency of card)
def preprocess(histogram):
    return [(14 - index, frequency) for index, frequency in
            enumerate(histogram) if frequency]
 
 
# Takes an iterable sequence and returns two items in a tuple:
# 1: 4-long list showing how often each card suit appears in the sequence
# 2: 13-long list showing how often each card value appears in the sequence
def preprocess_board(flat_board):
    suit_histogram, histogram = [0] * 4, [0] * 13
    # Reversing the order in histogram so in the future, we can traverse
    # starting from index 0
    for card in flat_board:
        histogram[14 - card.value] += 1
        suit_histogram[card.suit_index] += 1
    return suit_histogram, histogram, max(suit_histogram)
 
# Returns tuple: (Is there a straight flush?, high card)
def detect_straight_flush(suit_board):
    contiguous_length, fail_index = 1, len(suit_board) - 5
    # Won't overflow list because we fail fast and check ahead
    for index, elem in enumerate(suit_board):
        current_val, next_val = elem, suit_board[index + 1]
        if next_val == current_val - 1:
            contiguous_length += 1
            if contiguous_length == 5:
                return True, current_val + 3
        else:
            # Fail fast if straight not possible
            if index >= fail_index:
                if (index == fail_index and next_val == 5 and
                        suit_board[0] == 14):
                    return True, 5
                break
            contiguous_length = 1
    return False,
 
# Returns the highest kicker available
def detect_highest_quad_kicker(histogram_board):
    for elem in histogram_board:
        if elem[1] < 4:
            return elem[0]
 
# Returns tuple: (Is there a straight?, high card)
def detect_straight(histogram_board):
    contiguous_length, fail_index = 1, len(histogram_board) - 5
    # Won't overflow list because we fail fast and check ahead
    for index, elem in enumerate(histogram_board):
        current_val, next_val = elem[0], histogram_board[index + 1][0]
        if next_val == current_val - 1:
            contiguous_length += 1
            if contiguous_length == 5:
                return True, current_val + 3
        else:
            # Fail fast if straight not possible
            if index >= fail_index:
                if (index == fail_index and next_val == 5 and
                        histogram_board[0][0] == 14):
                    return True, 5
                break
            contiguous_length = 1
    return False,
 
# Returns tuple of the two highest kickers that result from the three of a kind
def detect_three_of_a_kind_kickers(histogram_board):
    kicker1 = -1
    for elem in histogram_board:
        if elem[1] != 3:
            if kicker1 == -1:
                kicker1 = elem[0]
            else:
                return kicker1, elem[0]
 
# Returns the highest kicker available
def detect_highest_kicker(histogram_board):
    for elem in histogram_board:
        if elem[1] == 1:
            return elem[0]
 
# Returns tuple: (kicker1, kicker2, kicker3)
def detect_pair_kickers(histogram_board):
    kicker1, kicker2 = -1, -1
    for elem in histogram_board:
        if elem[1] != 2:
            if kicker1 == -1:
                kicker1 = elem[0]
            elif kicker2 == -1:
                kicker2 = elem[0]
            else:
                return kicker1, kicker2, elem[0]
 
# Returns a list of the five highest cards in the given board
# Note: Requires a sorted board to be given as an argument
def get_high_cards(histogram_board):
    return histogram_board[:5]
 
# Return Values:
# Royal Flush: (9,)
# Straight Flush: (8, high card)
# Four of a Kind: (7, quad card, kicker)
# Full House: (6, trips card, pair card)
# Flush: (5, [flush high card, flush second high card, ..., flush low card])
# Straight: (4, high card)
# Three of a Kind: (3, trips card, (kicker high card, kicker low card))
# Two Pair: (2, high pair card, low pair card, kicker)
# Pair: (1, pair card, (kicker high card, kicker med card, kicker low card))
# High Card: (0, [high card, second high card, third high card, etc.])
def detect_hand(hole_cards, given_board, suit_histogram,
                full_histogram, max_suit):
    # Determine if flush possible. If yes, four of a kind and full house are
    # impossible, so return royal, straight, or regular flush.
    if max_suit >= 3:
        flush_index = suit_histogram.index(max_suit)
        for hole_card in hole_cards:
            if hole_card.suit_index == flush_index:
                max_suit += 1
        if max_suit >= 5:
            flat_board = list(given_board)
            flat_board.extend(hole_cards)
            suit_board = generate_suit_board(flat_board, flush_index)
            result = detect_straight_flush(suit_board)
            if result[0]:
                return (8, result[1]) if result[1] != 14 else (9,)
            return 5, get_high_cards(suit_board)
 
    # Add hole cards to histogram data structure and process it
    full_histogram = full_histogram[:]
    for hole_card in hole_cards:
        full_histogram[14 - hole_card.value] += 1
    histogram_board = preprocess(full_histogram)
 
    # Find which card value shows up the most and second most times
    current_max, max_val, second_max, second_max_val = 0, 0, 0, 0
    for item in histogram_board:
        val, frequency = item[0], item[1]
        if frequency > current_max:
            second_max, second_max_val = current_max, max_val
            current_max, max_val = frequency, val
        elif frequency > second_max:
            second_max, second_max_val = frequency, val
 
    # Check to see if there is a four of a kind
    if current_max == 4:
        return 7, max_val, detect_highest_quad_kicker(histogram_board)
    # Check to see if there is a full house
    if current_max == 3 and second_max >= 2:
        return 6, max_val, second_max_val
    # Check to see if there is a straight
    if len(histogram_board) >= 5:
        result = detect_straight(histogram_board)
        if result[0]:
            return 4, result[1]
    # Check to see if there is a three of a kind
    if current_max == 3:
        return 3, max_val, detect_three_of_a_kind_kickers(histogram_board)
    if current_max == 2:
        # Check to see if there is a two pair
        if second_max == 2:
            return 2, max_val, second_max_val, detect_highest_kicker(
                histogram_board)
        # Return pair
        else:
            return 1, max_val, detect_pair_kickers(histogram_board)
    # Check for high cards
    return 0, get_high_cards(histogram_board)
 
# Returns the index of the player with the winning hand
def compare_hands(result_list):
    best_hand = max(result_list)
    winning_player_index = result_list.index(best_hand) + 1
    # Check for ties
    if best_hand in result_list[winning_player_index:]:
        return 0
    return winning_player_index
 
# Print results
def print_results(hole_cards, winner_list, result_histograms):
    float_iterations = float(sum(winner_list))
    print ("Winning Percentages:")
    for index, hole_card in enumerate(hole_cards):
        winning_percentage = float(winner_list[index + 1]) / float_iterations
        if hole_card == (None, None):
            print ("(?, ?) : "), winning_percentage
        else:
            print (hole_card, ": "), winning_percentage
    print ("Ties: ", float(winner_list[0]) / float_iterations, "\n")
    for player_index, histogram in enumerate(result_histograms):
        print ("Player" + str(player_index + 1) + " Histogram: ")
        for index, elem in enumerate(histogram):
            print (hand_rankings[index], ": "), float(elem) / float_iterations
        print
 
# Returns the winning percentages
def find_winning_percentage(winner_list):
    float_iterations = float(sum(winner_list))
    percentages = []
    for num_wins in winner_list:
        winning_percentage = float(num_wins) / float_iterations
        percentages.append(winning_percentage)
    return percentages
 
# Populate provided data structures with results from simulation
def find_winner(generate_boards, deck, hole_cards, num, board_length,
                given_board, winner_list, result_histograms):
    # Run simulations
    result_list = [None] * len(hole_cards)
    for remaining_board in generate_boards(deck, num, board_length):
        # Generate a new board
        if given_board:
            board = given_board[:]
            board.extend(remaining_board)
        else:
            board = remaining_board
        # Find the best possible poker hand given the created board and the
        # hole cards and save them in the results data structures
        suit_histogram, histogram, max_suit = (
            preprocess_board(board))
        for index, hole_card in enumerate(hole_cards):
            result_list[index] = detect_hand(hole_card, board, suit_histogram,
                                             histogram, max_suit)
        # Find the winner of the hand and tabulate results
        winner_index = compare_hands(result_list)
        winner_list[winner_index] += 1
        # Increment what hand each player made
        for index, result in enumerate(result_list):
            result_histograms[index][result[0]] += 1
 
 
# CHECK ==================================================================================================
 
# Wrapper class which holds the arguments for library calls
# Mocks actual argparse object
class LibArgs:
    def __init__(self, board, exact, num, input_file, hole_cards):
        self.board = board
        self.cards = hole_cards
        self.n = num
        self.input = input_file
        self.exact = exact
 
# Parses arguments passed to holdem_calc as a library call
def parse_lib_args(args):
    error_check_arguments(args)
    # Parse hole cards and board
    hole_cards, board = None, None
    if not args.input:
        hole_cards, board = parse_cards(args.cards, args.board)
    return hole_cards, args.n, args.exact, board, args.input
 
# Parses command line arguments to holdem_calc
def parse_args():
    # Define possible command line arguments
    parser = argparse.ArgumentParser(
        description="Find the odds that a Texas Hold'em hand will win. Note "
        "that cards must be given in the following format: As, Jc, Td, 3h.")
    parser.add_argument("cards", nargs="*", type=str, metavar="hole card",
                        help="Hole cards you want to find the odds for.")
    parser.add_argument("-b", "--board", nargs="*", type=str, metavar="card",
                        help="Add board cards")
    parser.add_argument("-e", "--exact", action="store_true",
                        help="Find exact odds by enumerating every possible "
                        "board")
    parser.add_argument("-n", type=int, default=100000,
                        help="Run N Monte Carlo simulations")
    parser.add_argument("-i", "--input", type=str,
                        help="Read hole cards and boards from an input file. "
                        "Commandline arguments for hole cards and board will "
                        "be ignored")
    # Parse command line arguments and check for errors
    args = parser.parse_args()
    error_check_arguments(args)
    # Parse hole cards and board
    hole_cards, board = None, None
    if not args.input:
        hole_cards, board = parse_cards(args.cards, args.board)
    return hole_cards, args.n, args.exact, board, args.input
 
# Parses a line taken from the input file and returns the hole cards and board
def parse_file_args(line):
    if line is None or len(line) == 0:
        print (line)
        print ("Invalid format")
        exit()
    values = line.split("|")
    if len(values) > 2 or len(values) < 1:
        print (line)
        print ("Invalid format")
        exit()
    hole_cards = values[0].split()
    all_cards = list(hole_cards)
    board = None
    if len(values) == 2:
        board = values[1].split()
        all_cards.extend(board)
    error_check_cards(all_cards)
    return parse_cards(hole_cards, board)
 
# Parses hole cards and board
def parse_cards(cards, board):
    hole_cards = create_hole_cards(cards)
    if board:
        board = parse_board(board)
    return hole_cards, board
 
# Error check the command line arguments
def error_check_arguments(args):
    # Check that the number of Monte Carlo simulations is a positive number
    if args.n <= 0:
        print ("Number of Monte Carlo simulations must be positive.")
        exit()
    # Check that we can open the specified input file
    if args.input:
        file_name = args.input
        try:
            input_file = open(file_name, 'r')
            input_file.close()
        except IOError:
            print ("Error opening file ") + file_name
            exit()
    # Check to make sure all cards are of a valid format
    all_cards = list(args.cards)
    if args.board:
        all_cards.extend(args.board)
    error_check_cards(all_cards)
 
# Error check the command line arguments
def error_check_arguments(args):
    # Check that the number of Monte Carlo simulations is a positive number
    if args.n <= 0:
        print ("Number of Monte Carlo simulations must be positive.")
        exit()
    # Check that we can open the specified input file
    if args.input:
        file_name = args.input
        try:
            input_file = open(file_name, 'r')
            input_file.close()
        except IOError:
            print ("Error opening file ") + file_name
            exit()
    # Check to make sure all cards are of a valid format
    all_cards = list(args.cards)
    if args.board:
        all_cards.extend(args.board)
    error_check_cards(all_cards)
 
# Checking that the hole cards + board are formatted properly and unique
def error_check_cards(all_cards):
    card_re = re.compile('[AKQJT98765432][scdh]')
    for card in all_cards:
        if card != "?" and not card_re.match(card):
            print ("Invalid card given.")
            exit()
        else:
            if all_cards.count(card) != 1 and card != "?":
                print ("The cards given must be unique.")
                exit()
 
# Returns tuple of two-tuple hole_cards: e.g. ((As, Ks), (Ad, Kd), (Jh, Th))
def create_hole_cards(raw_hole_cards):
    # Checking that there are an even number of hole cards
    if (raw_hole_cards is None or len(raw_hole_cards) < 2 or
            len(raw_hole_cards) % 2):
        print ("You must provide a non-zero even number of hole cards")
        exit()
    # Create two-tuples out of hole cards
    hole_cards, current_hole_cards = [], []
    for hole_card in raw_hole_cards:
        if hole_card != "?":
            current_card = holdem_functions.Card(hole_card)
            current_hole_cards.append(current_card)
        else:
            current_hole_cards.append(None)
        if len(current_hole_cards) == 2:
            if None in current_hole_cards:
                if (current_hole_cards[0] is not None or
                        current_hole_cards[1] is not None):
                    print ("Unknown hole cards must come in pairs")
                    exit()
            hole_cards.append((current_hole_cards[0], current_hole_cards[1]))
            current_hole_cards = []
    if hole_cards.count((None, None)) > 1:
        print ("Can only have one set of unknown hole cards")
    return tuple(hole_cards)
 
# Returns list of board cards: e.g. [As Ks Ad Kd]
def parse_board(board):
    if len(board) > 5 or len(board) < 3:
        print ("Board must have a length of 3, 4, or 5.")
        exit()
    if "?" in board:
        print ("Board cannot have unknown cards")
        exit()
    return create_cards(board)
 
# Instantiates new cards from the arguments and returns them in a tuple
def create_cards(card_strings):
    return [holdem_functions.Card(arg) for arg in card_strings]

print (deck)

 


Изменено пользователем yellyex

moonfangtopich написал 29.08.2019 в 14:57:
У вас недостаточно широкий кругозор, пацаны

Я странствия этого еблана видел в покерных топанах, а потом в таверне - это один из самых безумных людей на форуме. Я искренне надеялся, что его зов о помощи останется незамеченным, но нет, нашелся доброволец и вот уже три страницы мы пожинаем плоды

Поделиться сообщением


Ссылка на сообщение
yellyex написал 1 час назад:

Привет! Народ, кто может помочь с кодом? Делов на 5 минут. Я плохо ориентируюсь. Язык Python. У меня есть код с гитхаба, нужно из него взять несколько блоков и соединить. Весь код переделывать не надо.

Что нужно:

 

1. Создаётся колода.

2. Раздаются карты игрокам и на стол.

3. Считаются комбинации игроков.

4. Комбинации сравниваются и выбирается победитель/и.

5. Данные выводятся в консоль.

 

Пример:
Board: 5c 6d Ac 4h 2h
Player 1: 5h Ad
Player 2: Kc Kh
Player 3: Qd Jс
Player 4: 10s 9c
Player 5: 8s Jh
Player 6: 2d 3h

Win: Player 6
Win: Straight - 2h 3h 4h 5c 6d 

 

Если победителей несколько, то список идёт вниз по порядку.

 

Я уже спрашивал на популярных сайтах по кодингу, но там молчат. Я сам бы мог, но просто у меня на это уйдет недели две. Помогите пожалуйста, кому нетрудно. 

 

  КОД

# Constants
suit_index_dict = {"s": 0, "c": 1, "h": 2, "d": 3}
reverse_suit_index = ("s", "c", "h", "d")
val_string = "AKQJT98765432"
hand_rankings = ("High Card", "Pair", "Two Pair", "Three of a Kind",
                 "Straight", "Flush", "Full House", "Four of a Kind",
                 "Straight Flush", "Royal Flush")
suit_value_dict = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14}
for num in range(2, 10):
    suit_value_dict[str(num)] = num
 
class Card:
    # Takes in strings of the format: "As", "Tc", "6d"
    def __init__(self, card_string):
        value, self.suit = card_string[0], card_string[1]
        self.value = suit_value_dict[value]
        self.suit_index = suit_index_dict[self.suit]
 
    def __str__(self):
        return val_string[14 - self.value] + self.suit
 
    def __repr__(self):
        return val_string[14 - self.value] + self.suit
 
    def __eq__(self, other):
        if self is None:
            return other is None
        elif other is None:
            return False
        return self.value == other.value and self.suit == other.suit
 
# Returns deck of cards with all hole cards and board cards removed
def generate_deck(hole_cards, board):
    deck = []
    for suit in reverse_suit_index:
        for value in val_string:
            deck.append(Card(value + suit))
    taken_cards = []
    for hole_card in hole_cards:
        for card in hole_card:
            if card is not None:
                taken_cards.append(card)
    if board and len(board) > 0:
        taken_cards.extend(board)
    for taken_card in taken_cards:
        deck.remove(taken_card)
    return tuple(deck)
 
# Generate all possible hole card combinations
def generate_hole_cards(deck):
    import itertools
    return itertools.combinations(deck, 2)
 
# Generate num_iterations random boards
def generate_random_boards(deck, num_iterations, board_length):
    import random
    import time
    random.seed(time.time())
    for _ in xrange(num_iterations):
        yield random.sample(deck, 5 - board_length)
 
# Generate all possible boards
def generate_exhaustive_boards(deck, num_iterations, board_length):
    import itertools
    return itertools.combinations(deck, 5 - board_length)
 
# Returns a board of cards all with suit = flush_index
def generate_suit_board(flat_board, flush_index):
    histogram = [card.value for card in flat_board
                 if card.suit_index == flush_index]
    histogram.sort(reverse=True)
    return histogram
 
# Returns a list of two tuples of the form: (value of card, frequency of card)
def preprocess(histogram):
    return [(14 - index, frequency) for index, frequency in
            enumerate(histogram) if frequency]
 
 
# Takes an iterable sequence and returns two items in a tuple:
# 1: 4-long list showing how often each card suit appears in the sequence
# 2: 13-long list showing how often each card value appears in the sequence
def preprocess_board(flat_board):
    suit_histogram, histogram = [0] * 4, [0] * 13
    # Reversing the order in histogram so in the future, we can traverse
    # starting from index 0
    for card in flat_board:
        histogram[14 - card.value] += 1
        suit_histogram[card.suit_index] += 1
    return suit_histogram, histogram, max(suit_histogram)
 
# Returns tuple: (Is there a straight flush?, high card)
def detect_straight_flush(suit_board):
    contiguous_length, fail_index = 1, len(suit_board) - 5
    # Won't overflow list because we fail fast and check ahead
    for index, elem in enumerate(suit_board):
        current_val, next_val = elem, suit_board[index + 1]
        if next_val == current_val - 1:
            contiguous_length += 1
            if contiguous_length == 5:
                return True, current_val + 3
        else:
            # Fail fast if straight not possible
            if index >= fail_index:
                if (index == fail_index and next_val == 5 and
                        suit_board[0] == 14):
                    return True, 5
                break
            contiguous_length = 1
    return False,
 
# Returns the highest kicker available
def detect_highest_quad_kicker(histogram_board):
    for elem in histogram_board:
        if elem[1] < 4:
            return elem[0]
 
# Returns tuple: (Is there a straight?, high card)
def detect_straight(histogram_board):
    contiguous_length, fail_index = 1, len(histogram_board) - 5
    # Won't overflow list because we fail fast and check ahead
    for index, elem in enumerate(histogram_board):
        current_val, next_val = elem[0], histogram_board[index + 1][0]
        if next_val == current_val - 1:
            contiguous_length += 1
            if contiguous_length == 5:
                return True, current_val + 3
        else:
            # Fail fast if straight not possible
            if index >= fail_index:
                if (index == fail_index and next_val == 5 and
                        histogram_board[0][0] == 14):
                    return True, 5
                break
            contiguous_length = 1
    return False,
 
# Returns tuple of the two highest kickers that result from the three of a kind
def detect_three_of_a_kind_kickers(histogram_board):
    kicker1 = -1
    for elem in histogram_board:
        if elem[1] != 3:
            if kicker1 == -1:
                kicker1 = elem[0]
            else:
                return kicker1, elem[0]
 
# Returns the highest kicker available
def detect_highest_kicker(histogram_board):
    for elem in histogram_board:
        if elem[1] == 1:
            return elem[0]
 
# Returns tuple: (kicker1, kicker2, kicker3)
def detect_pair_kickers(histogram_board):
    kicker1, kicker2 = -1, -1
    for elem in histogram_board:
        if elem[1] != 2:
            if kicker1 == -1:
                kicker1 = elem[0]
            elif kicker2 == -1:
                kicker2 = elem[0]
            else:
                return kicker1, kicker2, elem[0]
 
# Returns a list of the five highest cards in the given board
# Note: Requires a sorted board to be given as an argument
def get_high_cards(histogram_board):
    return histogram_board[:5]
 
# Return Values:
# Royal Flush: (9,)
# Straight Flush: (8, high card)
# Four of a Kind: (7, quad card, kicker)
# Full House: (6, trips card, pair card)
# Flush: (5, [flush high card, flush second high card, ..., flush low card])
# Straight: (4, high card)
# Three of a Kind: (3, trips card, (kicker high card, kicker low card))
# Two Pair: (2, high pair card, low pair card, kicker)
# Pair: (1, pair card, (kicker high card, kicker med card, kicker low card))
# High Card: (0, [high card, second high card, third high card, etc.])
def detect_hand(hole_cards, given_board, suit_histogram,
                full_histogram, max_suit):
    # Determine if flush possible. If yes, four of a kind and full house are
    # impossible, so return royal, straight, or regular flush.
    if max_suit >= 3:
        flush_index = suit_histogram.index(max_suit)
        for hole_card in hole_cards:
            if hole_card.suit_index == flush_index:
                max_suit += 1
        if max_suit >= 5:
            flat_board = list(given_board)
            flat_board.extend(hole_cards)
            suit_board = generate_suit_board(flat_board, flush_index)
            result = detect_straight_flush(suit_board)
            if result[0]:
                return (8, result[1]) if result[1] != 14 else (9,)
            return 5, get_high_cards(suit_board)
 
    # Add hole cards to histogram data structure and process it
    full_histogram = full_histogram[:]
    for hole_card in hole_cards:
        full_histogram[14 - hole_card.value] += 1
    histogram_board = preprocess(full_histogram)
 
    # Find which card value shows up the most and second most times
    current_max, max_val, second_max, second_max_val = 0, 0, 0, 0
    for item in histogram_board:
        val, frequency = item[0], item[1]
        if frequency > current_max:
            second_max, second_max_val = current_max, max_val
            current_max, max_val = frequency, val
        elif frequency > second_max:
            second_max, second_max_val = frequency, val
 
    # Check to see if there is a four of a kind
    if current_max == 4:
        return 7, max_val, detect_highest_quad_kicker(histogram_board)
    # Check to see if there is a full house
    if current_max == 3 and second_max >= 2:
        return 6, max_val, second_max_val
    # Check to see if there is a straight
    if len(histogram_board) >= 5:
        result = detect_straight(histogram_board)
        if result[0]:
            return 4, result[1]
    # Check to see if there is a three of a kind
    if current_max == 3:
        return 3, max_val, detect_three_of_a_kind_kickers(histogram_board)
    if current_max == 2:
        # Check to see if there is a two pair
        if second_max == 2:
            return 2, max_val, second_max_val, detect_highest_kicker(
                histogram_board)
        # Return pair
        else:
            return 1, max_val, detect_pair_kickers(histogram_board)
    # Check for high cards
    return 0, get_high_cards(histogram_board)
 
# Returns the index of the player with the winning hand
def compare_hands(result_list):
    best_hand = max(result_list)
    winning_player_index = result_list.index(best_hand) + 1
    # Check for ties
    if best_hand in result_list[winning_player_index:]:
        return 0
    return winning_player_index
 
# Print results
def print_results(hole_cards, winner_list, result_histograms):
    float_iterations = float(sum(winner_list))
    print ("Winning Percentages:")
    for index, hole_card in enumerate(hole_cards):
        winning_percentage = float(winner_list[index + 1]) / float_iterations
        if hole_card == (None, None):
            print ("(?, ?) : "), winning_percentage
        else:
            print (hole_card, ": "), winning_percentage
    print ("Ties: ", float(winner_list[0]) / float_iterations, "\n")
    for player_index, histogram in enumerate(result_histograms):
        print ("Player" + str(player_index + 1) + " Histogram: ")
        for index, elem in enumerate(histogram):
            print (hand_rankings[index], ": "), float(elem) / float_iterations
        print
 
# Returns the winning percentages
def find_winning_percentage(winner_list):
    float_iterations = float(sum(winner_list))
    percentages = []
    for num_wins in winner_list:
        winning_percentage = float(num_wins) / float_iterations
        percentages.append(winning_percentage)
    return percentages
 
# Populate provided data structures with results from simulation
def find_winner(generate_boards, deck, hole_cards, num, board_length,
                given_board, winner_list, result_histograms):
    # Run simulations
    result_list = [None] * len(hole_cards)
    for remaining_board in generate_boards(deck, num, board_length):
        # Generate a new board
        if given_board:
            board = given_board[:]
            board.extend(remaining_board)
        else:
            board = remaining_board
        # Find the best possible poker hand given the created board and the
        # hole cards and save them in the results data structures
        suit_histogram, histogram, max_suit = (
            preprocess_board(board))
        for index, hole_card in enumerate(hole_cards):
            result_list[index] = detect_hand(hole_card, board, suit_histogram,
                                             histogram, max_suit)
        # Find the winner of the hand and tabulate results
        winner_index = compare_hands(result_list)
        winner_list[winner_index] += 1
        # Increment what hand each player made
        for index, result in enumerate(result_list):
            result_histograms[index][result[0]] += 1
 
 
# CHECK ==================================================================================================
 
# Wrapper class which holds the arguments for library calls
# Mocks actual argparse object
class LibArgs:
    def __init__(self, board, exact, num, input_file, hole_cards):
        self.board = board
        self.cards = hole_cards
        self.n = num
        self.input = input_file
        self.exact = exact
 
# Parses arguments passed to holdem_calc as a library call
def parse_lib_args(args):
    error_check_arguments(args)
    # Parse hole cards and board
    hole_cards, board = None, None
    if not args.input:
        hole_cards, board = parse_cards(args.cards, args.board)
    return hole_cards, args.n, args.exact, board, args.input
 
# Parses command line arguments to holdem_calc
def parse_args():
    # Define possible command line arguments
    parser = argparse.ArgumentParser(
        description="Find the odds that a Texas Hold'em hand will win. Note "
        "that cards must be given in the following format: As, Jc, Td, 3h.")
    parser.add_argument("cards", nargs="*", type=str, metavar="hole card",
                        help="Hole cards you want to find the odds for.")
    parser.add_argument("-b", "--board", nargs="*", type=str, metavar="card",
                        help="Add board cards")
    parser.add_argument("-e", "--exact", action="store_true",
                        help="Find exact odds by enumerating every possible "
                        "board")
    parser.add_argument("-n", type=int, default=100000,
                        help="Run N Monte Carlo simulations")
    parser.add_argument("-i", "--input", type=str,
                        help="Read hole cards and boards from an input file. "
                        "Commandline arguments for hole cards and board will "
                        "be ignored")
    # Parse command line arguments and check for errors
    args = parser.parse_args()
    error_check_arguments(args)
    # Parse hole cards and board
    hole_cards, board = None, None
    if not args.input:
        hole_cards, board = parse_cards(args.cards, args.board)
    return hole_cards, args.n, args.exact, board, args.input
 
# Parses a line taken from the input file and returns the hole cards and board
def parse_file_args(line):
    if line is None or len(line) == 0:
        print (line)
        print ("Invalid format")
        exit()
    values = line.split("|")
    if len(values) > 2 or len(values) < 1:
        print (line)
        print ("Invalid format")
        exit()
    hole_cards = values[0].split()
    all_cards = list(hole_cards)
    board = None
    if len(values) == 2:
        board = values[1].split()
        all_cards.extend(board)
    error_check_cards(all_cards)
    return parse_cards(hole_cards, board)
 
# Parses hole cards and board
def parse_cards(cards, board):
    hole_cards = create_hole_cards(cards)
    if board:
        board = parse_board(board)
    return hole_cards, board
 
# Error check the command line arguments
def error_check_arguments(args):
    # Check that the number of Monte Carlo simulations is a positive number
    if args.n <= 0:
        print ("Number of Monte Carlo simulations must be positive.")
        exit()
    # Check that we can open the specified input file
    if args.input:
        file_name = args.input
        try:
            input_file = open(file_name, 'r')
            input_file.close()
        except IOError:
            print ("Error opening file ") + file_name
            exit()
    # Check to make sure all cards are of a valid format
    all_cards = list(args.cards)
    if args.board:
        all_cards.extend(args.board)
    error_check_cards(all_cards)
 
# Error check the command line arguments
def error_check_arguments(args):
    # Check that the number of Monte Carlo simulations is a positive number
    if args.n <= 0:
        print ("Number of Monte Carlo simulations must be positive.")
        exit()
    # Check that we can open the specified input file
    if args.input:
        file_name = args.input
        try:
            input_file = open(file_name, 'r')
            input_file.close()
        except IOError:
            print ("Error opening file ") + file_name
            exit()
    # Check to make sure all cards are of a valid format
    all_cards = list(args.cards)
    if args.board:
        all_cards.extend(args.board)
    error_check_cards(all_cards)
 
# Checking that the hole cards + board are formatted properly and unique
def error_check_cards(all_cards):
    card_re = re.compile('[AKQJT98765432][scdh]')
    for card in all_cards:
        if card != "?" and not card_re.match(card):
            print ("Invalid card given.")
            exit()
        else:
            if all_cards.count(card) != 1 and card != "?":
                print ("The cards given must be unique.")
                exit()
 
# Returns tuple of two-tuple hole_cards: e.g. ((As, Ks), (Ad, Kd), (Jh, Th))
def create_hole_cards(raw_hole_cards):
    # Checking that there are an even number of hole cards
    if (raw_hole_cards is None or len(raw_hole_cards) < 2 or
            len(raw_hole_cards) % 2):
        print ("You must provide a non-zero even number of hole cards")
        exit()
    # Create two-tuples out of hole cards
    hole_cards, current_hole_cards = [], []
    for hole_card in raw_hole_cards:
        if hole_card != "?":
            current_card = holdem_functions.Card(hole_card)
            current_hole_cards.append(current_card)
        else:
            current_hole_cards.append(None)
        if len(current_hole_cards) == 2:
            if None in current_hole_cards:
                if (current_hole_cards[0] is not None or
                        current_hole_cards[1] is not None):
                    print ("Unknown hole cards must come in pairs")
                    exit()
            hole_cards.append((current_hole_cards[0], current_hole_cards[1]))
            current_hole_cards = []
    if hole_cards.count((None, None)) > 1:
        print ("Can only have one set of unknown hole cards")
    return tuple(hole_cards)
 
# Returns list of board cards: e.g. [As Ks Ad Kd]
def parse_board(board):
    if len(board) > 5 or len(board) < 3:
        print ("Board must have a length of 3, 4, or 5.")
        exit()
    if "?" in board:
        print ("Board cannot have unknown cards")
        exit()
    return create_cards(board)
 
# Instantiates new cards from the arguments and returns them in a tuple
def create_cards(card_strings):
    return [holdem_functions.Card(arg) for arg in card_strings]

print (deck)

 


Изменено 1 час назад пользователем yellyex

ты там отдохнул уже? батя не заставляет мойку мыть?

Поделиться сообщением


Ссылка на сообщение

Лучший отдых - это смена деятельности.


moonfangtopich написал 29.08.2019 в 14:57:
У вас недостаточно широкий кругозор, пацаны

Я странствия этого еблана видел в покерных топанах, а потом в таверне - это один из самых безумных людей на форуме. Я искренне надеялся, что его зов о помощи останется незамеченным, но нет, нашелся доброволец и вот уже три страницы мы пожинаем плоды

Поделиться сообщением


Ссылка на сообщение
(изменено)

чё нет желающих?

Требуются в офис в Минске в букмекерскую компанию:
1. Full stack (php+java):
PHP7+, Phalcon 3+, Redis, MariaDB(MySQL), RESTful API, Docker, HTTP-протокол, Git, ReactJS 16+, Redux, JavaScript Native, ES6, HTML5, CSS3, SASS/LESS

2. Back-end разработчик:
PHP7+, Redis, Phalcon 3+, MariaDB (MySQL), WebSocket, RESTful API, Docker, HTTP-протокол, Git

Требуемый опыт работы:
1 - 3 года
Занятость:
полная, полный день
Что вас ожидает:

зп 2к$+
работа в крупной букмекерской компании (более 7 лет на рынке РБ) и молодом креативном коллективе;
оформление в соответствии с ТК РБ;
заработная плата зависит от уровня ваших способностей и знаний;
возможность реализовать свой потенциал и профессионально расти;
оплачиваемые курсы, литература, спортзал, можем обсудить оплату вашего хобби;
реальная возможность профессионального и денежного роста;
в офисе бильярд, плейстейшн, фуд-корт, постоянные корпоративные мероприятия;
розыгрыш путевок на отдых за границей;
удобный график работы 5/2 с 10 00-18 00.
Помощь с трансфером.

Для более подробной информации писать в телеграм: @funsterrr17


Изменено пользователем Eraser

Поделиться сообщением


Ссылка на сообщение

Уже не надо


moonfangtopich написал 29.08.2019 в 14:57:
У вас недостаточно широкий кругозор, пацаны

Я странствия этого еблана видел в покерных топанах, а потом в таверне - это один из самых безумных людей на форуме. Я искренне надеялся, что его зов о помощи останется незамеченным, но нет, нашелся доброволец и вот уже три страницы мы пожинаем плоды

Поделиться сообщением


Ссылка на сообщение

скандалы, интриги, расследования на кегле

https://www.kaggle.com/c/petfinder-adoption-prediction/discussion/125436#715594

тред про то, как это было сделано

https://www.kaggle.com/bminixhofer/how-bestpetting-cheated


Мастер разъебки 1%

 

2019-07-08-16-37-27.png

2019-07-09-13-05-05.png

 

Поделиться сообщением


Ссылка на сообщение
yellyex написал 7 часов назад:

Привет! Народ, кто может помочь с кодом? Делов на 5 минут. Я плохо ориентируюсь. Язык Python. У меня есть код с гитхаба, нужно из него взять несколько блоков и соединить. Весь код переделывать не надо.

почему у тебя весь код в одном файлике?
разбей на разные файлы по логическим состовляющим(погугли mvc pattern) создай репозиторий, запуш на гитхаб, потом вернись и попроси помощи еще раз.


Найди себе дело по душе и ты не будешь работать ни одного дня в своей жизни

Поделиться сообщением


Ссылка на сообщение

Да блин. Код тот уже не нужен. Я бросил копипастить и пытаюсь сам разобраться.

Почему у меня карта не показывается?

import random

class Card():

    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def showCard(self):
        print(rank, suit)

card = Card
card.showCard(1, 1)

 


moonfangtopich написал 29.08.2019 в 14:57:
У вас недостаточно широкий кругозор, пацаны

Я странствия этого еблана видел в покерных топанах, а потом в таверне - это один из самых безумных людей на форуме. Я искренне надеялся, что его зов о помощи останется незамеченным, но нет, нашелся доброволец и вот уже три страницы мы пожинаем плоды

Поделиться сообщением


Ссылка на сообщение
yellyex написал 8 минут назад:

Да блин. Код тот уже не нужен. Я бросил копипастить и пытаюсь сам разобраться.

Почему у меня карта не показывается?


import random

class Card():

    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def showCard(self):
        print(rank, suit)

card = Card
card.showCard(1, 1)

 

Print(self.rank)

Поделиться сообщением


Ссылка на сообщение

Ошибка.

Кто-нибудь может мне на коленке колоду карт сделать? У меня 40 примеров с гитхаба, все разные, и я хуй знает, что и как там написано. Можете по-детски код колоды карт написать? Я хотя-бы точку отправки получу. Спасибо.


moonfangtopich написал 29.08.2019 в 14:57:
У вас недостаточно широкий кругозор, пацаны

Я странствия этого еблана видел в покерных топанах, а потом в таверне - это один из самых безумных людей на форуме. Я искренне надеялся, что его зов о помощи останется незамеченным, но нет, нашелся доброволец и вот уже три страницы мы пожинаем плоды

Поделиться сообщением


Ссылка на сообщение
Гость
Эта тема закрыта для публикации сообщений.

×
×
  • Создать...