-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (67 loc) · 2.98 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import shogi
import threading
import time
class CruSHogi():
def __init__(self):
self.QualifiedMoves=[]
self.Premoves={}
self.UnusedThreads=0
self.ThreadList=[]
def ProcessMove(self,moves,currboard,depth,threadid):
for move in moves:
brd=currboard
brd.push(moves[0])
currbranch=[]
currbranch.append(0)
if self.UnusedThreads>0:
nxtthreadid=threadid
nxtthreadid.append[0]
thrdid=0
pmoves=list(currboard.legal_moves)
div=int(len(pmoves)/self.UnusedThreads)
if div<1:
self.UnusedThreads-=len(pmoves)
for move in pmoves:
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=([move],brd,depth-1,nxtthreadid,)))
self.threadlist[-1].start()
time.sleep(0.8)
thrdid+=1
nxtthreadid[-1]=thrdid
else:
for i in range(self.UnusedThreads-1):
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=(pmoves[div*i:div*(i+1)],brd,depth-1,nxtthreadid,)))
self.threadlist[-1].start()
time.sleep(0.8)
thrdid+=1
nxtthreadid[-1]=thrdid
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=(pmoves[len(pmoves)-div:len(pmoves)],brd,depth-1,nxtthreadid,)))
self.threadlist[-1].start()
def Play(self,threads,fen,depth):
if fen in self.Premoves:
return self.Premoves[fen]
else:
brd=shogi.Board()
brd.set_fen(fen)
pmoves=list(brd.legal_moves)
if len(pmoves)==1:
return pmoves[0].uci()
else:
threadid=0
self.UnusedThreads=threads
div=int(len(pmoves)/threads)
if div<1:
self.UnusedThreads-=len(pmoves)
for move in pmoves:
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=([move],brd,depth,[threadid],)))
self.threadlist[-1].start()
time.sleep(0.8)
threadid+=1
else:
for i in range(threads-1):
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=(pmoves[div*i:div*(i+1)],brd,depth,[threadid],)))
self.threadlist[-1].start()
time.sleep(0.8)
threadid+=1
self.threadlist.append(threading.Thread(target=self.ProcessMove,args=(pmoves[len(pmoves)-div:len(pmoves)],brd,depth,[threadid],)))
self.threadlist[-1].start()
return None