Пример #1
0
 def select_move(self, gs):
   if self.strategy.should_pass(gs):
     return Move.pass_turn()
   elif self.strategy.should_resign(gs):
     return Move.resign()
   else:
     return self.agent.select_move(gs)
Пример #2
0
 def handle_play(self, color, move):
     if move.lower() == 'pass':
         self.game_state = self.game_state.apply_move(Move.pass_turn())
     elif move.lower() == 'resign':
         self.game_state = self.game_state.apply_move(Move.resign())
     else:
         self.game_state = self.game_state.apply_move(
             gtp_position_to_coord(move))
     return response.success()
Пример #3
0
 def legal_moves(self):
   if self.is_over():
     return list()
   ret = [Move.pass_turn(), Move.resign()]
   for ri in range(1, self.board.sz + 1):
     for ci in range(1, self.board.sz + 1):
       m = Move.play(Point(ri, ci))
       if self.is_valid_move(m):
         ret.append(m)
   return ret
Пример #4
0
 def play_their_move(self):
     their_name = self.their_color.name
     their_letter = their_name[0].upper()
     pos = self.command_and_response('genmove {}\n'.format(their_name))
     if pos.lower() == 'resign':
         self.game_state = self.game_state.apply_move(Move.resign())
         self.stopped = True
     elif pos.lower() == 'pass':
         self.game_state = self.game_state.apply_move(Move.pass_turn())
         self.sgf.append(';{}[]\n'.format(their_letter))
         if self.game_state.pmove.is_pass:
             self.stopped = True
     else:
         move = gtp_position_to_coord(pos)
         self.game_state = self.game_state.apply_move(move)
         self.sgf.append(';{}[{}]\n'.format(their_letter,
                                            self.sgf.coordinates(move)))