44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Erzeugt Stichproben von Haenden (7 Karten) und berechnet fuer jede den pokerkit-Rang
|
|
(StandardHighHand.entry.index). Ausgabe: haende.txt (eine Hand je Zeile), pk_idx.npy.
|
|
Aufruf: python pk_index.py <N_gleich> <N_eng> <seed>"""
|
|
import random
|
|
import sys
|
|
import numpy as np
|
|
from pokerkit import StandardHighHand, Card
|
|
|
|
RANKS = "23456789TJQKA"
|
|
DECK = [r + s for r in RANKS for s in "cdhs"]
|
|
|
|
|
|
def hand_index(strs):
|
|
cs = list(Card.parse("".join(strs)))
|
|
return StandardHighHand.from_game(cs[:2], cs[2:]).entry.index
|
|
|
|
|
|
def main():
|
|
n_gleich, n_eng, seed = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])
|
|
rng = random.Random(seed)
|
|
haende = [rng.sample(DECK, 7) for _ in range(n_gleich)]
|
|
# enge Stichprobe: Hand aus einem Teildeck (4 Raenge voll + 8 Zusatzkarten) -> viele Full Houses,
|
|
# Vierlinge, Straight Flushes, Gleichstaende
|
|
for _ in range(n_eng):
|
|
ranks = rng.sample(RANKS, rng.choice([5, 6, 7]))
|
|
sub = [r + s for r in ranks for s in "cdhs"]
|
|
haende.append(rng.sample(sub, 7))
|
|
cache = {}
|
|
idx = np.empty(len(haende), dtype=np.int32)
|
|
for i, h in enumerate(haende):
|
|
idx[i] = hand_index(h)
|
|
if i % 200000 == 0:
|
|
print(i, flush=True)
|
|
with open("haende.txt", "w", encoding="utf-8", newline="\n") as f:
|
|
for h in haende:
|
|
f.write(" ".join(h) + "\n")
|
|
np.save("pk_idx.npy", idx)
|
|
print("fertig", len(haende), "verschiedene Raenge", len(set(idx.tolist())))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|