def start(self): self.pid = os.getpid() logger.debug( f"Selfplay#Start Process index = {self.id}, pid = {self.pid}") idx = 1 self.buffer = [] while True: search_tree = defaultdict(VisitState) start_time = time() value, turns, state, store = self.start_game(idx, search_tree) end_time = time() if value != 1 and value != -1: winner = 'Draw' elif idx % 2 == 0 and value == 1 or idx % 2 == 1 and value == -1: winner = 'AlphaHe' else: winner = 'Eleeye' logger.debug( f"Process {self.pid}-{self.id} play game {idx} time={(end_time - start_time):.1f} sec, " f"turn={turns / 2}, value = {value:.2f}, winner is {winner}") if turns <= 10 and store: senv.render(state) if store: idx += 1
def start(self): # logger.info("pengge pengge pengge222") # logger.error("pengge pengge pengge111") # logger.debug("pengge pengge pengge") self.pid = os.getpid() ran = self.config.play.max_processes if self.config.play.max_processes > 5 else self.config.play.max_processes * 2 sleep((self.pid % ran) * 10) logger.error( f"Selfplay#Start Process index = {self.id}, pid = {self.pid}") idx = 1 self.buffer = [] search_tree = defaultdict(VisitState) while True: start_time = time() search_tree = defaultdict(VisitState) value, turns, state, store = self.start_game(idx, search_tree) end_time = time() logger.error( f"Process {self.pid}-{self.id} play game {idx} time={(end_time - start_time):.1f} sec, " f"turn={turns / 2}, winner = {value:.2f} (1 = red, -1 = black, 0 draw)" ) if turns <= 10: senv.render(state) if store: idx += 1 sleep(random())
def start(self): self.pid = os.getpid() logger.debug(f"Selfplay#Start Process index = {self.id}, pid = {self.pid}") idx = 1 self.buffer = [] search_tree = defaultdict(VisitState) while True: start_time = time() value, turns, state, search_tree, store = self.start_game(idx, search_tree) end_time = time() if value != 1 and value != -1: winner = 'Draw' elif idx % 2 == 0 and value == 1 or idx % 2 == 1 and value == -1: winner = 'AlphaHe' else: winner = 'Eleeye' logger.debug(f"Process {self.pid}-{self.id} play game {idx} time={(end_time - start_time):.1f} sec, " f"turn={turns / 2}, value = {value:.2f}, winner is {winner}") if turns <= 10 and store: senv.render(state) if store: idx += 1
def test_be_catched(): import cchess_alphazero.environment.static_env as senv state = senv.fen_to_state( 'rnbakab1r/9/1c3c2n/p1p5p/7p1/3PR4/P1P3P1P/C7C/9/RNBAKABN1 b') # state = senv.fliped_state(state) ori_state = state senv.render(state) print() action = '4454' print(senv.be_catched(ori_state, action))
def test_ucci(): import cchess_alphazero.environment.static_env as senv from cchess_alphazero.environment.lookup_tables import flip_move state = senv.INIT_STATE state = senv.step(state, '0001') fen = senv.state_to_fen(state, 1) print(fen) senv.render(state) move = 'b7b0' move = senv.parse_ucci_move(move) print(f'Parsed move {move}') move = flip_move(move) print(f'fliped move {move}') state = senv.step(state, move) senv.render(state) fen = senv.state_to_fen(state, 2) print(fen)
def start(self): logger.debug(f"Selfplay#Start Process index = {self.id}, pid = {self.pid}") idx = 1 self.buffer = [] search_tree = defaultdict(VisitState) while True: start_time = time() value, turns, state, search_tree, store = self.start_game(idx, search_tree) end_time = time() logger.debug(f"Process {self.pid}-{self.id} play game {idx} time={(end_time - start_time):.1f} sec, " f"turn={turns / 2}, winner = {value:.2f} (1 = red, -1 = black, 0 draw)") if turns <= 10: senv.render(state) if store: idx += 1
def start(self): logger.debug( f"Selfplay#Start Process index = {self.id}, pid = {self.pid}") idx = 1 self.buffer = [] search_tree = defaultdict(VisitState) while True: start_time = time() value, turns, state, search_tree, store = self.start_game( idx, search_tree) end_time = time() logger.debug( f"Process {self.pid}-{self.id} play game {idx} time={(end_time - start_time):.1f} sec, " f"turn={turns / 2}, winner = {value:.2f} (1 = red, -1 = black, 0 draw)" ) if turns <= 10: senv.render(state) if store: idx += 1
def test_onegreen(): import cchess_alphazero.environment.static_env as senv from cchess_alphazero.environment.lookup_tables import flip_move init = '9999299949999999249999869999999958999999519999999999999999997699' state = senv.init(init) print(state) senv.render(state) move = senv.parse_onegreen_move('8685') state = senv.step(state, move) print(state) senv.render(state) move = senv.parse_onegreen_move('7666') state = senv.step(state, flip_move(move)) print(state) senv.render(state)
def test_check_and_catch(): import cchess_alphazero.environment.static_env as senv state = senv.fen_to_state( 'rnba1cbnr/1a7/1c7/p1p3p1p/2p5k/2P1R4/P1P3P1P/1C5C1/9/RNBAKABN1 r') # state = senv.fliped_state(state) ori_state = state senv.render(state) print() action = '4454' state = senv.step(state, action) senv.render(state) state = senv.fliped_state(state) print() senv.render(state) print(senv.will_check_or_catch(ori_state, action))