def __init__(self): self.start = time.time() super().__init__(0, 0x0000000810000000, 0x0000001008000000) self.model = Model() #self.model.load('model/Gen' + str(0)) self.score = 0 self.table = {} self.currentNode = mcts.Node(mcts.FakeNode(), 0, 0, Core(self.turn, self.black, self.white)) self.currentNode.isGameRoot = True self.currentNode.isSearchRoot = True self.mctsBatch = mcts.MCTSBatch(self.model,NUM_MCTS)
def InputEnemy(self): nb, nw = self.Count() nmTurn = 64 - nb - nw if nmTurn < 16: site, socre, self.table = moveAI(self.black,self.white,self.turn, nmTurn, self.table, self.score) self.score = socre self.AddSite(site) else: # site, score, self.table = moveAINN(self.black,self.white,self.turn, 3, self.table, self.score,self.model) # self.score = score # self.AddSite(site) self.currentNode = mcts.Node(mcts.FakeNode(), 0, self.turn, Core(self.turn, self.black, self.white)) self.currentNode.isGameRoot = True self.currentNode.isSearchRoot = True pi = self.mctsBatch.alpha([self.currentNode], 1)[0] print(pi) self.currentNode = self.makeMove(self.currentNode,int(np.argmax(pi)))
def InputPlayer(self): nb, nw = self.Count() nmTurn = 64 - nb - nw if nmTurn < RAND: self.currentNode = mcts.Node( mcts.FakeNode(), 0, self.turn, Core(self.turn, self.black, self.white)) self.currentNode.isGameRoot = True self.currentNode.isSearchRoot = True pi = self.mctsBatch.alpha([self.currentNode], 1)[0] move = int(np.argmax(pi)) self.addHistory(pi, self.turn) self.currentNode = self.makeMove(self.currentNode, move) else: while True: move = random.randrange(0, 64) site = 1 << move if self.judge & site: # self.AddSite(site) self.currentNode = self.makeMove(self.currentNode, move) break
def InputEnemy(self): nb, nw = self.Count() nmTurn = 64 - nb - nw if nmTurn < 16: site, maxScore, sumScore, self.table = moveAITrain( self.black, self.white, self.turn, nmTurn, self.table, nw - nb) if maxScore > 0: maxScore = 1 elif maxScore < 0: maxScore = -1 site.sort(reverse=True) pi = np.zeros(64) for move in site: pi[bitFind(move[1])] = move[0] / (sumScore if sumScore else 1) self.addHistory(pi, self.turn) temp = copy.deepcopy(self.history) self.addValue(self.history, maxScore) for i in range(len(site) // 4 + 1): history2 = copy.deepcopy(temp) self.AddSite(site[i][1]) self.NextBoard() site2, maxScore2, sumScore2, self.table = moveAITrain( self.black, self.white, self.turn ^ 1, nmTurn - 1, self.table, nw - nb) self.NextBoard() maxScore2 = -maxScore2 if maxScore2 > 0: maxScore2 = 1 elif maxScore2 < 0: maxScore2 = -1 if site2: site2.sort(reverse=True) pi2 = np.zeros([64]) for move2 in site2: pi2[bitFind(move2[1])] = move2[0] / (sumScore2 if sumScore2 else 1) features = [] features.append(self.black) features.append(self.white) features.append(self.judge) history2.append([features, pi2, self.turn ^ 1]) self.addValue(history2, maxScore2) self.history.extend(history2) self.AddSite(0) elif nmTurn < RAND: self.currentNode = mcts.Node( mcts.FakeNode(), 0, self.turn, Core(self.turn, self.black, self.white)) self.currentNode.isGameRoot = True self.currentNode.isSearchRoot = True pi = self.mctsBatch.alpha([self.currentNode], 1)[0] move = int(np.argmax(pi)) self.addHistory(pi, self.turn) self.currentNode = self.makeMove(self.currentNode, move) else: while True: move = random.randrange(0, 64) site = 1 << move if self.judge & site: # self.AddSite(site) self.currentNode = self.makeMove(self.currentNode, move) break