Пример #1
0
def evaluate_6cards(a, b, c, d, e, f):
    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]

    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]

        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
    hash_ = hash_quinary(quinary, 13, 6)

    return NOFLUSH6[hash_]
Пример #2
0
  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]
      base_rank = NOFLUSH5[hash_quinary(base_idx, 13, 5)]
      for additional in additionals:
        idx = base_idx
        for i in additional:
          idx += 10 ** i
        hash_ = hash_quinary(idx, 13, self.NUM_CARDS)
        if self.VISIT[hash_] > 0:
          continue
        self.TABLE[hash_] = base_rank
        self.VISIT[hash_] = 1

    self.QUINARIES = []
Пример #3
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)
            hash_ = hash_quinary(idx, 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)
        hash_ = hash_quinary(idx, 13, self.NUM_CARDS)
        self.TABLE[hash_] = self.CUR_RANK
        self.VISIT[hash_] = 1
        self.CUR_RANK += 1
Пример #4
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
            hash_ = hash_quinary(idx, 13, self.NUM_CARDS)
            self.TABLE[hash_] = self.CUR_RANK
            self.VISIT[hash_] = 1
            self.CUR_RANK += 1

        self.QUINARIES = []
Пример #5
0
 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
     base_rank = NOFLUSH5[hash_quinary(base_idx, 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
       hash_ = hash_quinary(idx, 13, self.NUM_CARDS)
       if self.VISIT[hash_] > 0:
         continue
       self.TABLE[hash_] = base_rank
       self.VISIT[hash_] = 1
Пример #6
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]
            hash_ = hash_quinary(idx, 13, self.NUM_CARDS)
            self.TABLE[hash_] = self.CUR_RANK
            self.VISIT[hash_] = 1
            self.CUR_RANK += 1

        self.QUINARIES = []
Пример #7
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])
            hash_ = hash_quinary(idx, 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 = []
Пример #8
0
    def mark_high_card(self):
        self.gen_quinary(5, 5)
        for base in self.QUINARIES:
            idx = 0
            idx += (10**base[0])
            idx += (10**base[1])
            idx += (10**base[2])
            idx += (10**base[3])
            idx += (10**base[4])
            hash_ = hash_quinary(idx, 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 = []
Пример #9
0
def evaluate_8cards(a, b, c, d, e, f, g, h):
    suit_hash = 0
    value_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_ = hash_quinary(quinary, 13, 8)

    value_noflush = NOFLUSH8[hash_]

    if value_flush < value_noflush:
        return value_flush
    else:
        return value_noflush