Пример #1
0
 def version(self):
     self.write("version")
     answer = self.readline().strip()
     try:
         return answer.split(" ")[1]
     except Exception, e:
         raise GCCException("GCCException in version()\nanswer='" + answer +
                            "'\n" + unicode(e))
Пример #2
0
 def name(self):
     self.write("name")
     answer = self.readline().strip()
     try:
         return " ".join(answer.split(" ")[1:])
     except Exception, e:
         raise GCCException("GCCException in name()\nanswer='" + answer +
                            "'\n" + unicode(e))
Пример #3
0
 def play_white(self):
     self.write("genmove white")
     answer = self.readline().strip()
     try:
         move = answer.split(" ")[1].upper()
         self.history.append(["w", move])
         return move
     except Exception, e:
         raise GCCException("GCCException in genmove_white()\nanswer='" +
                            answer + "'\n" + unicode(e))
Пример #4
0
 def undo_standard(self):
     self.write("undo")
     answer = self.readline()
     try:
         if answer[0] == "=":
             return True
         else:
             return False
     except Exception, e:
         raise GCCException("GCCException in undo()\nanswer='" + answer +
                            "'\n" + unicode(e))
Пример #5
0
 def set_time(self, main_time=30, byo_yomi_time=30, byo_yomi_stones=1):
     self.write("time_settings " + str(main_time) + " " +
                str(byo_yomi_time) + " " + str(byo_yomi_stones))
     answer = self.readline()
     try:
         if answer[0] == "=":
             return True
         else:
             return False
     except Exception, e:
         raise GCCException("GCCException in set_time()\nanswer='" +
                            answer + "'\n" + unicode(e))
Пример #6
0
 def set_free_handicap(self, positions):
     self.free_handicap_stones = positions[:]
     stones = ""
     for p in positions:
         stones += p + " "
     self.write("set_free_handicap " + stones.strip())
     answer = self.readline().strip()
     try:
         if answer[0] == "=":
             return True
         else:
             return False
     except Exception, e:
         raise GCCException(
             "GCCException in set_free_handicap()\nanswer='" + answer +
             "'\n" + unicode(e))
Пример #7
0
 def undo(self):
     self.reset()
     self.komi(self.komi_value)
     try:
         # adding handicap stones
         if len(self.free_handicap_stones) > 0:
             self.set_free_handicap(self.free_handicap_stones)
         self.history.pop()
         history = self.history[:]
         self.history = []
         for color, move in history:
             if color == "b":
                 if not self.place_black(move):
                     return False
             else:
                 if not self.place_white(move):
                     return False
         return True
     except Exception, e:
         raise GCCException("GCCException in undo()\n" + unicode(e))