29 lines
1.4 KiB
Python
29 lines
1.4 KiB
Python
# Aufruf des Rust-Bewerters (rang/pokerbench-poolmodell-rang.exe) aus Python.
|
|
# klassen(brett (N,5) int8, haende (N,3,2) int8 mit -1 = keine) -> kl (N,3) uint8 (255 = keine), hs (N,3), wert (N,3), z (N,3,12,3)
|
|
# z[i, slot, c] = (Kombinationen der Klasse c ohne Board/Bezugshand, davon schlechter als die Bezugshand, davon gleich)
|
|
import os, subprocess, tempfile
|
|
import numpy as np
|
|
|
|
HIER = os.path.dirname(os.path.abspath(__file__))
|
|
EXE = os.path.join(HIER, "rang", "pokerbench-poolmodell-rang.exe")
|
|
K = 12
|
|
GRENZEN = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.88, 0.94, 0.98]
|
|
SATZ = 4 + 4 + 4 + K * 6
|
|
DT = np.dtype([("kl", "u1"), ("pad", "u1", 3), ("hs", "<f4"), ("wert", "<u4"), ("z", "<u2", (K, 3))])
|
|
assert DT.itemsize == SATZ
|
|
|
|
|
|
def klassen(brett, haende, faeden=8):
|
|
N = len(brett)
|
|
roh = np.full((N, 11), 255, np.uint8)
|
|
roh[:, :5] = brett.astype(np.int16) & 255
|
|
h = haende.reshape(N, 6).astype(np.int16)
|
|
roh[:, 5:] = np.where(h < 0, 255, h).astype(np.uint8)
|
|
with tempfile.TemporaryDirectory() as d:
|
|
ein = os.path.join(d, "ein.bin"); aus = os.path.join(d, "aus.bin")
|
|
roh.tofile(ein)
|
|
flags = 0x00004000 if os.name == "nt" else 0 # BELOW_NORMAL_PRIORITY_CLASS
|
|
subprocess.run([EXE, ein, aus, str(faeden)], check=True, creationflags=flags)
|
|
r = np.fromfile(aus, DT).reshape(N, 3)
|
|
return r["kl"], r["hs"], r["wert"], r["z"].astype(np.int32)
|