def search(self, time_budget): """ Compute resistance for all moves in current state. """ toplay = white if self.state.toplay == self.state.PLAYERS["white"] else black raw_scores = score(stateToInput(self.state), toplay) score_padding = (boardsize - self.state.size)/2 self.scores = raw_scores[score_padding:self.state.size+score_padding,score_padding:self.state.size+score_padding]
def search(self, time_budget = 1): """ Compute resistance for all moves in current state. """ state = stateToInput(self.state) #get equivalent white to play game if black to play toplay = white if self.state.toplay == self.state.PLAYERS["white"] else black if(toplay == black): state = mirror_game(state) played = np.logical_or(state[white,padding:boardsize+padding,padding:boardsize+padding],\ state[black,padding:boardsize+padding,padding:boardsize+padding]).flatten() self.scores = self.evaluator(state) #set value of played cells impossibly low so they are never picked self.scores[played] = -2
def search(self, time_budget=1): """ Compute resistance for all moves in current state. """ state = stateToInput(self.state) #get equivalent white to play game if black to play toplay = white if self.state.toplay == self.state.PLAYERS[ "white"] else black if (toplay == black): state = mirror_game(state) played = np.logical_or(state[white,padding:boardsize+padding,padding:boardsize+padding],\ state[black,padding:boardsize+padding,padding:boardsize+padding]).flatten() self.scores = self.evaluator(state) #set value of played cells impossibly low so they are never picked self.scores[played] = -2
def evaluate(self, parent, state): #get equivalent white to play game if black to play children = [] toplay = white if state.toplay == self.state.PLAYERS["white"] else black state = stateToInput(state) if(toplay == black): state = mirror_game(state) played = np.logical_or(state[white,padding:boardsize+padding,padding:boardsize+padding],\ state[black,padding:boardsize+padding,padding:boardsize+padding]).flatten() scores = self.evaluator(state) value = -np.max(scores[np.logical_not(played)]) for i in range(len(scores)): if not played[i]: if(toplay == white): move = i else: move = boardsize*(i%boardsize)+i//boardsize children.append(node(Q = scores[i], N = 1, move = move, parent = parent)) parent.add_children(children) return value