コード例 #1
0
ファイル: utils.py プロジェクト: jinjin0912/Poker-app
 def mark_straight(self):
     cases = [[highest - i for i in range(5)]
              for highest in range(12, 3, -1)]
     cases.append([12, 3, 2, 1, 0])
     for base in cases:
         base_idx = 0
         for pos in base:
             base_idx += (10**pos)
             self.USED[pos] = 1
         hand = list(map(int, reversed("{:013d}".format(base_idx))))
         base_rank = NO_FLUSH_5[hash_quinary(hand, 13, 5)]
         self.get_additional(self.NUM_CARDS - 5)
         additionals = self.QUINARIES_ADDITIONAL[:]
         self.QUINARIES_ADDITIONAL = []
         self.USED = [0] * 13
         for additional in additionals:
             idx = base_idx
             for i in additional:
                 idx += 10**i
             hand = list(map(int, reversed("{:013d}".format(idx))))
             hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
             if self.VISIT[hash_] > 0:
                 continue
             self.TABLE[hash_] = base_rank
             self.VISIT[hash_] = 1
コード例 #2
0
ファイル: evaluator7.py プロジェクト: jinjin0912/Poker-app
def evaluate_7cards(a, b, c, d, e, f, g):
    suit_hash = 0

    suit_hash += suitbit_by_id[a]
    suit_hash += suitbit_by_id[b]
    suit_hash += suitbit_by_id[c]
    suit_hash += suitbit_by_id[d]
    suit_hash += suitbit_by_id[e]
    suit_hash += suitbit_by_id[f]
    suit_hash += suitbit_by_id[g]

    if SUITS[suit_hash]:
        suit_binary = [0] * 4

        suit_binary[a & 0x3] |= binaries_by_id[a]
        suit_binary[b & 0x3] |= binaries_by_id[b]
        suit_binary[c & 0x3] |= binaries_by_id[c]
        suit_binary[d & 0x3] |= binaries_by_id[d]
        suit_binary[e & 0x3] |= binaries_by_id[e]
        suit_binary[f & 0x3] |= binaries_by_id[f]
        suit_binary[g & 0x3] |= binaries_by_id[g]

        return FLUSH[suit_binary[SUITS[suit_hash] - 1]]

    quinary = [0] * 13

    quinary[a >> 2] += 1
    quinary[b >> 2] += 1
    quinary[c >> 2] += 1
    quinary[d >> 2] += 1
    quinary[e >> 2] += 1
    quinary[f >> 2] += 1
    quinary[g >> 2] += 1

    return NO_FLUSH_7[hash_quinary(quinary, 13, 7)]
コード例 #3
0
def evaluate_cards(*args):
    cards = [Card(arg) for arg in args]
    suit_hash = 0
    value_flush = 10000
    value_noflush = 10000

    if len(cards) == 9:
        suit_counter = [0] * 4
        for card in cards:
            suit_counter[card & 0x3] += 1

        for i in range(4):
            if suit_counter[i] >= 5:
                suit_binary = [0] * 4
                for card in cards:
                    suit_bits = card & 0x3
                    suit_binary[suit_bits] = suit_binary[
                        suit_bits] | binaries_by_id[card]

                value_flush = FLUSH[suit_binary[i]]
                break

    else:
        for card in cards:
            suit_hash += suitbit_by_id[card]

        if SUITS[suit_hash]:
            suit_binary = [0] * 4
            for card in cards:
                suit_bits = card & 0x3
                suit_binary[
                    suit_bits] = suit_binary[suit_bits] | binaries_by_id[card]

            value_flush = FLUSH[suit_binary[SUITS[suit_hash] - 1]]

            if len(cards) < 8:
                return value_flush

    quinary = [0] * 13

    for card in cards:
        quinary[card >> 2] += 1

    hash_val = hash_quinary(quinary, 13, len(cards))

    if len(cards) == 5:
        return NO_FLUSH_5[hash_val]
    elif len(cards) == 6:
        return NO_FLUSH_6[hash_val]
    elif len(cards) == 7:
        return NO_FLUSH_7[hash_val]
    elif len(cards) == 8:
        value_noflush = NO_FLUSH_8[hash_val]
    elif len(cards) == 9:
        value_noflush = NO_FLUSH_9[hash_val]

    if value_flush < value_noflush:
        return value_flush
    else:
        return value_noflush
コード例 #4
0
ファイル: utils.py プロジェクト: jinjin0912/Poker-app
    def mark_template(self, ks):
        self.gen_quinary(ks, 0, self.NUM_CARDS - 5)
        for base, additionals in self.QUINARIES:
            base_idx = 0
            for i in range(len(ks)):
                base_idx += (10**base[i]) * ks[i]
            hand = list(map(int, reversed("{:013d}".format(base_idx))))
            base_rank = NO_FLUSH_5[hash_quinary(hand, 13, 5)]
            for additional in additionals:
                idx = base_idx
                for i in additional:
                    idx += 10**i
                hand = list(map(int, reversed("{:013d}".format(idx))))
                hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
                if self.VISIT[hash_] > 0:
                    continue
                self.TABLE[hash_] = base_rank
                self.VISIT[hash_] = 1

        self.QUINARIES = []
コード例 #5
0
def evaluate_9cards(a, b, c, d, e, f, g, h, i):
  suit_hash = 0
  value_flush = 10000
  value_no_flush = 10000
  suit_counter = [0] * 4

  suit_counter[a & 0x3] += 1
  suit_counter[b & 0x3] += 1
  suit_counter[c & 0x3] += 1
  suit_counter[d & 0x3] += 1
  suit_counter[e & 0x3] += 1
  suit_counter[f & 0x3] += 1
  suit_counter[g & 0x3] += 1
  suit_counter[h & 0x3] += 1
  suit_counter[i & 0x3] += 1

  for l in range(4):
    if suit_counter[l] >= 5:
      suit_binary = [0] * 4

      suit_binary[a & 0x3] |= binaries_by_id[a]
      suit_binary[b & 0x3] |= binaries_by_id[b]
      suit_binary[c & 0x3] |= binaries_by_id[c]
      suit_binary[d & 0x3] |= binaries_by_id[d]
      suit_binary[e & 0x3] |= binaries_by_id[e]
      suit_binary[f & 0x3] |= binaries_by_id[f]
      suit_binary[g & 0x3] |= binaries_by_id[g]
      suit_binary[h & 0x3] |= binaries_by_id[h]
      suit_binary[i & 0x3] |= binaries_by_id[i]

      value_flush = FLUSH[suit_binary[l]]
      break

  quinary = [0] * 13

  quinary[a >> 2] += 1
  quinary[b >> 2] += 1
  quinary[c >> 2] += 1
  quinary[d >> 2] += 1
  quinary[e >> 2] += 1
  quinary[f >> 2] += 1
  quinary[g >> 2] += 1
  quinary[h >> 2] += 1
  quinary[i >> 2] += 1

  hash_value = hash_quinary(quinary, 13, 9)

  value_no_flush = NO_FLUSH_9[hash_value]

  if value_flush < value_no_flush:
    return value_flush
  else:
    return value_no_flush
コード例 #6
0
    def mark_full_house(self):
        self.gen_quinary(2, 2)
        for base in self.QUINARIES:
            idx = 0
            idx += (10**base[0]) * 3
            idx += (10**base[1]) * 2
            hand = list(map(int, reversed("{:013d}".format(idx))))
            hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
            self.TABLE[hash_] = self.CUR_RANK
            self.VISIT[hash_] = 1
            self.CUR_RANK += 1

        self.QUINARIES = []
コード例 #7
0
    def mark_straight(self):
        for highest in range(12, 3, -1):  # From Ace to 6
            # k=5 case for base
            base = [highest - i for i in range(5)]
            idx = 0
            for pos in base:
                idx += (10**pos)
            hand = list(map(int, reversed("{:013d}".format(idx))))
            hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
            self.TABLE[hash_] = self.CUR_RANK
            self.VISIT[hash_] = 1
            self.CUR_RANK += 1

        # Five High Straight Flush
        base = [12, 3, 2, 1, 0]
        idx = 0
        for pos in base:
            idx += (10**pos)
        hand = list(map(int, reversed("{:013d}".format(idx))))
        hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
        self.TABLE[hash_] = self.CUR_RANK
        self.VISIT[hash_] = 1
        self.CUR_RANK += 1
コード例 #8
0
    def mark_four_of_a_kind(self):
        # Order 13C2 lexicographically
        self.gen_quinary(2, 2)
        for base in self.QUINARIES:
            idx = 0
            idx += (10**base[0]) * 4
            idx += 10**base[1]
            hand = list(map(int, reversed("{:013d}".format(idx))))
            hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
            self.TABLE[hash_] = self.CUR_RANK
            self.VISIT[hash_] = 1
            self.CUR_RANK += 1

        self.QUINARIES = []
コード例 #9
0
    def mark_two_pair(self):
        self.gen_quinary(3, 3)
        for base in self.QUINARIES:
            idx = 0
            idx += (10**base[0]) * 2
            idx += (10**base[1]) * 2
            idx += (10**base[2])
            hand = list(map(int, reversed("{:013d}".format(idx))))
            hash_ = hash_quinary(hand, 13, self.NUM_CARDS)
            if self.VISIT[hash_] == 0:
                self.TABLE[hash_] = self.CUR_RANK
                self.VISIT[hash_] = 1
                self.CUR_RANK += 1

        self.QUINARIES = []
コード例 #10
0
def evaluate_8cards(a, b, c, d, e, f, g, h):
    suit_hash = 0
    value_flush = 10000
    value_no_flush = 10000

    suit_hash += suitbit_by_id[a]
    suit_hash += suitbit_by_id[b]
    suit_hash += suitbit_by_id[c]
    suit_hash += suitbit_by_id[d]
    suit_hash += suitbit_by_id[e]
    suit_hash += suitbit_by_id[f]
    suit_hash += suitbit_by_id[g]
    suit_hash += suitbit_by_id[h]

    if SUITS[suit_hash]:
        suit_binary = [0] * 4

        suit_binary[a & 0x3] |= binaries_by_id[a]
        suit_binary[b & 0x3] |= binaries_by_id[b]
        suit_binary[c & 0x3] |= binaries_by_id[c]
        suit_binary[d & 0x3] |= binaries_by_id[d]
        suit_binary[e & 0x3] |= binaries_by_id[e]
        suit_binary[f & 0x3] |= binaries_by_id[f]
        suit_binary[g & 0x3] |= binaries_by_id[g]
        suit_binary[h & 0x3] |= binaries_by_id[h]

        value_flush = FLUSH[suit_binary[SUITS[suit_hash] - 1]]

    quinary = [0] * 13

    quinary[a >> 2] += 1
    quinary[b >> 2] += 1
    quinary[c >> 2] += 1
    quinary[d >> 2] += 1
    quinary[e >> 2] += 1
    quinary[f >> 2] += 1
    quinary[g >> 2] += 1
    quinary[h >> 2] += 1

    hash_value = hash_quinary(quinary, 13, 8)

    value_no_flush = NO_FLUSH_8[hash_value]

    if value_flush < value_no_flush:
        return value_flush
    else:
        return value_no_flush
コード例 #11
0
def evaluate_omaha_cards(c1, c2, c3, c4, c5, h1, h2, h3, h4):
    value_flush = 10000
    value_noflush = 10000
    suit_count_board = [0, 0, 0, 0]
    suit_count_hole = [0, 0, 0, 0]

    suit_count_board[c1 & 0x3] += 1
    suit_count_board[c2 & 0x3] += 1
    suit_count_board[c3 & 0x3] += 1
    suit_count_board[c4 & 0x3] += 1
    suit_count_board[c5 & 0x3] += 1

    suit_count_hole[h1 & 0x3] += 1
    suit_count_hole[h2 & 0x3] += 1
    suit_count_hole[h3 & 0x3] += 1
    suit_count_hole[h4 & 0x3] += 1

    for i in range(4):
        if suit_count_board[i] >= 3 and suit_count_hole[i] >= 2:
            suit_binary_board = [0, 0, 0, 0]

            suit_binary_board[c1 & 0x3] |= binaries_by_id[c1]
            suit_binary_board[c2 & 0x3] |= binaries_by_id[c2]
            suit_binary_board[c3 & 0x3] |= binaries_by_id[c3]
            suit_binary_board[c4 & 0x3] |= binaries_by_id[c4]
            suit_binary_board[c5 & 0x3] |= binaries_by_id[c5]

            suit_binary_hole = [0, 0, 0, 0]
            suit_binary_hole[h1 & 0x3] |= binaries_by_id[h1]
            suit_binary_hole[h2 & 0x3] |= binaries_by_id[h2]
            suit_binary_hole[h3 & 0x3] |= binaries_by_id[h3]
            suit_binary_hole[h4 & 0x3] |= binaries_by_id[h4]

            if suit_count_board[i] == 3 and suit_count_hole[i] == 2:
                value_flush = FLUSH[suit_binary_board[i] | suit_binary_hole[i]]
            else:
                padding = [0x0000, 0x2000, 0x6000]

                suit_binary_board[i] |= padding[5 - suit_count_board[i]]
                suit_binary_hole[i] |= padding[4 - suit_count_hole[i]]

                board_hash = hash_binary(suit_binary_board[i], 5)
                hole_hash = hash_binary(suit_binary_hole[i], 4)

                value_flush = FLUSH_OMAHA[board_hash * 1365 + hole_hash]

            break

    quinary_board = [0] * 13
    quinary_hole = [0] * 13

    quinary_board[(c1 >> 2)] += 1
    quinary_board[(c2 >> 2)] += 1
    quinary_board[(c3 >> 2)] += 1
    quinary_board[(c4 >> 2)] += 1
    quinary_board[(c5 >> 2)] += 1

    quinary_hole[(h1 >> 2)] += 1
    quinary_hole[(h2 >> 2)] += 1
    quinary_hole[(h3 >> 2)] += 1
    quinary_hole[(h4 >> 2)] += 1

    board_hash = hash_quinary(quinary_board, 13, 5)
    hole_hash = hash_quinary(quinary_hole, 13, 4)

    value_noflush = NO_FLUSH_OMAHA[board_hash * 1820 + hole_hash]

    if value_flush < value_noflush:
        return value_flush
    else:
        return value_noflush