Files
@ b06733513452
Branch filter:
Location: OneEye/src/util.py - annotation
b06733513452
1.3 KiB
text/x-python
StateBag: tests and fixes
077600f0c5f8 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 782476e472ab 782476e472ab 782476e472ab 782476e472ab 782476e472ab 782476e472ab 782476e472ab 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 928d9a0edc05 5f4489f36388 5f4489f36388 5f4489f36388 5f4489f36388 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 077600f0c5f8 f9ab2070bd69 32221aadca28 32221aadca28 32221aadca28 f9ab2070bd69 f9ab2070bd69 f9ab2070bd69 f9ab2070bd69 | import random
import multiprocessing
import logging as log
EMPTY=0
BLACK=1
WHITE=-1
colorNames={BLACK:"B",WHITE:"W"}
class MsgQueue:
def __init__(self,handler=None):
self._queue=multiprocessing.Queue()
self._event=multiprocessing.Event()
self._handleEvent=handler
def send(self,actionName,args=tuple(),kwargs=None):
if kwargs is None: kwargs=dict()
self._queue.put((actionName,args,kwargs))
self._event.set()
def listen(self,handleEvent=None):
if handleEvent is not None: self._handleEvent=handleEvent
while True:
self._event.wait()
msg=self._queue.get()
if self._queue.empty():
self._event.clear()
log.info(msg)
if msg[0]=="!kill": break
self._handleEvent(msg)
def setHandler(self,handler):
self._handleEvent=handler
rand=random.Random()
rand.seed(361)
zobristNums=tuple(
tuple(
tuple(rand.getrandbits(32) for i in range(3)) for c in range(19)
) for r in range(19)
)
def hashBoard(board):
res=0
for (r,row) in enumerate(board):
for (c,item) in enumerate(row):
res^=zobristNums[r][c][item+1]
return res
def diffHash(r,c,oldItem,newItem):
h=zobristNums[r][c]
return h[oldItem+1] ^ h[newItem+1]
def exportBoard(board):
substitutions={EMPTY:".", BLACK:"X", WHITE:"O"}
return "\n".join("".join(substitutions.get(x,"?") for x in row) for row in board)
|