コード例 #1
0
 def priority(self, position):
     score = 0
     if self.last_conclusion is not None:
         dist = mdist(position, self.last_conclusion)
         score += max(5 - dist, 0)
     for adj in self.adjacencies[position]:
         if not self.is_unknown(adj):
             score += 1
     return score
コード例 #2
0
 def priority(self, position):
     score = 0
     if self.last_conclusion is not None:
         if self.last_conclusion in self.adjacencies[position]:
             score += self.conclusion_adjacent_value
         elif self.last_conclusion in self.corner_adjacencies[position]:
             score += self.conclusion_corner_adjacent_value
         else:
             dist = mdist(self.last_conclusion, position)
             if dist in self.conclusion_distance_values:
                 score += self.conclusion_distance_values[dist]
     for adj in self.adjacencies[position]:
         if not self.is_unknown(adj):
             score += self.known_adjacent_value
     return score
コード例 #3
0
 def valid_white_reachable(self, position=None, color=None):
     if color == BLACK:
         return True
     if color == WHITE:
         candidates = [position]
     else:
         candidates = self.white_positions.difference(self.given_positions)
     for pos_white in candidates:
         for pos_given in self.given_positions:
             number = self[pos_given]
             if mdist(pos_given, pos_white) < number:
                 break # this candidate has a given close enough
         else:
             return False # no numbers close enough
     return True
コード例 #4
0
 def priority(self, position):
     score = 0
     if self.last_conclusion is not None:
         if self.last_conclusion in self.adjacencies[position]:
             score += self.conclusion_adjacent_value
         else:
             dist = mdist(self.last_conclusion, position)
             if dist in self.conclusion_distance_values.keys():
                 score += self.conclusion_distance_values[dist]
     # known lines nearby
     adjs = self.adjacencies[position]
     known_score = self.known_adjacent_value * len(adjs)
     for adj in adjs:
         if self.is_unknown(adj):
             known_score -= self.known_adjacent_value
     score += known_score
     # givens nearby
     for gpos in self.adjacent_givens(position):
         number = self.givens[gpos]
         if number in self.given_adjacent_values.keys():
             score += self.given_adjacent_values[number]
     return score