def play_plain(self, color, move): #print 'play_plain called' self.check_side2move(color) self.engine.make_move(simple_go.string_as_move(string.upper(move), self.engine.size)) if self.engine.play_randomly_initialization_done: self.engine.update_fast_random_status() log("move made: %s %s\n" % (color, move)) log(str(self.engine.current_board)) log("-"*60 + "\n")
def play_plain(self, color, move): #print 'play_plain called' self.check_side2move(color) self.engine.make_move( simple_go.string_as_move(string.upper(move), self.engine.size)) if self.engine.play_randomly_initialization_done: self.engine.update_fast_random_status() log("move made: %s %s\n" % (color, move)) log(str(self.engine.current_board)) log("-" * 60 + "\n")
def play_plain(self, color, move): self.check_side2move(color) self.engine.make_move(simple_go.string_as_move(string.upper(move), self.engine.size)) log(str(self.engine.current_board)) log(self.engine.current_board.as_string_with_unconditional_status()) log("move: " + move + "\n") log("score: %s unconditional score: W:%i B:%i\n" % ( self.final_score_as_string(), self.engine.current_board.unconditional_score(simple_go.WHITE), self.engine.current_board.unconditional_score(simple_go.BLACK)))
def play_plain(self, color, move): if (self.simple_engine.current_board.side==simple_go.BLACK) != (string.upper(color[0])=="B"): self.simple_engine.make_move(simple_go.PASS_MOVE) move2 = simple_go.string_as_move(string.upper(move), self.size) if not self.simple_engine.make_move(move2): return "? illegal move: maybe super-ko" result = self.play_gg(color, move) if result[0]=="?": return result self.engine.exec_cmd("play " + color + " " + move) log("move: " + move + "\n") return result
def play_plain(self, color, move): if (self.simple_engine.current_board.side == simple_go.BLACK) != (string.upper(color[0]) == "B"): self.simple_engine.make_move(simple_go.PASS_MOVE) move2 = simple_go.string_as_move(string.upper(move), self.size) if not self.simple_engine.make_move(move2): return "? illegal move: maybe super-ko" result = self.play_gg(color, move) if result[0] == "?": return result self.engine.exec_cmd("play " + color + " " + move) log("move: " + move + "\n") return result
def play_plain(self, color, move): self.engine.make_move(simple_go.string_as_move(string.upper(move), self.engine.size)) self.play_gg(color, move)
def test_string_move_functions(self): ''' test string/move conversion functions ''' test = {(1, 1): "A1", (2, 3): "B3", (5, 5): "E5"} for pos, string in test.items(): self.assertEqual(simple_go.move_as_string(pos, self.size), string) self.assertEqual(simple_go.string_as_move(string, self.size), pos)
def play(self, seed=1, print_flag=False): if self.size in (5, 7): random.seed(seed) self.random_engine.current_board.init_hash() if self.size == 5 and int(random.random() * 26) != 13: return START_HEURISTICS if self.size == 7: if int(random.random() * 50) != 25: return START_HEURISTICS if int(random.random() * 48) not in (17, 18, 23, 24, 29, 30, 31): return START_HEURISTICS random.seed(seed) self.boardsize(self.size) score = "" while not self.random_engine.has_2_passes(): if self.random_engine.current_board.side == simple_go.BLACK: move_tuple = self.random_engine.select_random_move() self.random_engine.make_move(move_tuple) move = simple_go.move_as_string(move_tuple) edge_flag = False if self.size == 5: if len(self.random_engine.move_history) <= 1: for coord in move_tuple: if coord in (2, self.size - 1): edge_flag = True if len(self.random_engine.move_history) <= 3: if self.random_engine.current_board.pos_near_edge( move_tuple): edge_flag = True if len(self.random_engine.move_history) <= 7: if move_tuple == simple_go.PASS_MOVE: edge_flag = True else: # self.size >= 9: if len(self.random_engine.move_history) <= 3: for coord in move_tuple: if coord in (2, self.size - 1): edge_flag = True if len(self.random_engine.move_history) <= 7: if self.random_engine.current_board.pos_near_edge( move_tuple): edge_flag = True if len(self.random_engine.move_history) <= 15: if move_tuple == simple_go.PASS_MOVE: edge_flag = True if edge_flag and not print_flag: return EDGE_HEURISTICS result = self.engine.exec_cmd("play black " + move) if result[0] == "?": raise ValueError, "engine didn't accept move" self.estimate_engine.exec_cmd("play black " + move) else: move = self.engine.exec_cmd("genmove white") move = move.split()[1] move_tuple = simple_go.string_as_move(move) if not self.random_engine.make_move(move_tuple): return SUPER_KO self.estimate_engine.exec_cmd("play white " + move) #if len(self.random_engine.move_history)%8==0: score = self.estimate_engine.exec_cmd("estimate_score") if print_flag: print score if print_flag: print move, len(self.random_engine.move_history) print self.random_engine.current_board else: score_lst = score.split() #if score[:8]=="= W+81.0": if self.size == 5: #if score: # print score, score_lst[1][0], float(score_lst[4][:-1]) if score and (score_lst[1][0] == "W" or abs(float(score_lst[4][:-1])) != 25): return ESTIMATED_WIN elif self.size == 7: if score and score_lst[1][0] == "W" and float( score_lst[1][1:]) >= 10.0: return ESTIMATED_WIN else: if score and score_lst[1][0] == "W" and float( score_lst[1][1:]) >= 20.0: return ESTIMATED_WIN elif score[:3] == "= B" and len( self.random_engine.move_history) >= 20: return BLACK_POSITIVE if print_flag: print self.random_engine print simple_go.move_list_as_string( self.random_engine.move_history) return GAME_FINISHED
def sgf2tuple(size, move): coords = sgf_to_coords(size, move) return simple_go.string_as_move(coords, size)
def play_plain(self, color, move): self.check_side2move(color) self.engine.make_move( simple_go.string_as_move(string.upper(move), self.engine.size)) log("move made: %s %s\n" % (color, move)) log("-" * 60 + "\n")
def play(self, seed=1, print_flag = False): if self.size in (5, 7): random.seed(seed) self.random_engine.current_board.init_hash() if self.size==5 and int(random.random() * 26)!=13: return START_HEURISTICS if self.size==7: if int(random.random() * 50)!=25: return START_HEURISTICS if int(random.random() * 48) not in (17, 18, 23, 24, 29, 30, 31): return START_HEURISTICS random.seed(seed) self.boardsize(self.size) score = "" while not self.random_engine.has_2_passes(): if self.random_engine.current_board.side==simple_go.BLACK: move_tuple = self.random_engine.select_random_move() self.random_engine.make_move(move_tuple) move = simple_go.move_as_string(move_tuple) edge_flag = False if self.size==5: if len(self.random_engine.move_history) <= 1: for coord in move_tuple: if coord in (2, self.size-1): edge_flag = True if len(self.random_engine.move_history) <= 3: if self.random_engine.current_board.pos_near_edge(move_tuple): edge_flag = True if len(self.random_engine.move_history) <= 7: if move_tuple==simple_go.PASS_MOVE: edge_flag = True else: # self.size >= 9: if len(self.random_engine.move_history) <= 3: for coord in move_tuple: if coord in (2, self.size-1): edge_flag = True if len(self.random_engine.move_history) <= 7: if self.random_engine.current_board.pos_near_edge(move_tuple): edge_flag = True if len(self.random_engine.move_history) <= 15: if move_tuple==simple_go.PASS_MOVE: edge_flag = True if edge_flag and not print_flag: return EDGE_HEURISTICS result = self.engine.exec_cmd("play black " + move) if result[0]=="?": raise ValueError, "engine didn't accept move" self.estimate_engine.exec_cmd("play black " + move) else: move = self.engine.exec_cmd("genmove white") move = move.split()[1] move_tuple = simple_go.string_as_move(move) if not self.random_engine.make_move(move_tuple): return SUPER_KO self.estimate_engine.exec_cmd("play white " + move) #if len(self.random_engine.move_history)%8==0: score = self.estimate_engine.exec_cmd("estimate_score") if print_flag: print score if print_flag: print move, len(self.random_engine.move_history) print self.random_engine.current_board else: score_lst = score.split() #if score[:8]=="= W+81.0": if self.size==5: #if score: # print score, score_lst[1][0], float(score_lst[4][:-1]) if score and (score_lst[1][0]=="W" or abs(float(score_lst[4][:-1]))!=25): return ESTIMATED_WIN elif self.size==7: if score and score_lst[1][0]=="W" and float(score_lst[1][1:]) >= 10.0: return ESTIMATED_WIN else: if score and score_lst[1][0]=="W" and float(score_lst[1][1:]) >= 20.0: return ESTIMATED_WIN elif score[:3]=="= B" and len(self.random_engine.move_history) >= 20: return BLACK_POSITIVE if print_flag: print self.random_engine print simple_go.move_list_as_string(self.random_engine.move_history) return GAME_FINISHED