def get_captures(board: chess.Board, prev_moce: chess.Move, count: int, piece_count: Dict[int, int]) \ -> Tuple[int, int, int]: if not board.is_en_passant(prev_moce): # is it not en passant, the norm piece = piece_delta(board, count, piece_count, board.turn) else: # needs seperate code path piece = (1, uci_to_1d_array_index(prev_moce.uci()), count) return piece
def _flip_move(move: chess.Move): uci = move.uci() from_column = uci[0] from_row = 9 - int(uci[1]) to_column = uci[2] to_row = 9 - int(uci[3]) flipped_move = chess.Move.from_uci("{}{}{}{}".format( from_column, from_row, to_column, to_row)) return flipped_move
def log_move(board: Board, move: Move, score: Score, show_uci=False, highlight=False): """ 23. Qe4 CP: 123 """ move_str = "%s%s" % (fullmove_string(board), board.san(move)) log_str = " %s" % move_str if show_uci: log_str += "%s (%s)" % (Color.DARK_GREEN, move.uci()) log_str = log_str.ljust(22 + len(Color.DARK_GREEN)) else: log_str = log_str.ljust(15) log_str += Color.ENDC + Color.BLUE log_str += " " + _score_str(score) if highlight: log_str += Color.YELLOW + " Investigate!" log(Color.GREEN, log_str)
def get_move_prob(pi: np.ndarray, move: chess.Move): """ Extracts the probablilty, according to the policy vector, of making a legal move at the current position. Scalar from 0 to 1. """ uci_move = str(move.uci()) parts = [uci_move[i:i+2] for i in range(0, len(uci_move), 2)] c1, r1 = col_map[parts[0][:1]], row_map[parts[0][1:]] c2, r2 = col_map[parts[1][:1]], row_map[parts[0][1:]] layer = move.from_square * 64 # layer number pos = move.to_square #* 64 # cell number in 8x8 (normal moves) # break move into constituants. if len(uci_move) == 4: return pi[layer + pos] elif len(uci_move) == 5: r3 = promotion_map[parts[2]] r3 += 0 if r2 == 1 else 4 return pi[layer + 64 + (((c2 - 8) + (r3 * 8) - 1))] else: raise Exception("I dont know what you did, but its BAD.")
def move_to_policy(move: chess.Move): mask = np.zeros(8192) uci_move = str(move.uci()) parts = [uci_move[i:i+2] for i in range(0, len(uci_move), 2)] c1, r1 = col_map[parts[0][:1]], row_map[parts[0][1:]] c2, r2 = col_map[parts[1][:1]], row_map[parts[0][1:]] layer = move.from_square * 64 # layer number pos = move.to_square #* 64 # cell number in 8x8 (normal moves) # break move into constituants. if len(uci_move) == 4: mask[layer + pos] = 1 return mask elif len(uci_move) == 5: r3 = promotion_map[parts[2]] r3 += 0 if r2 == 1 else 4 mask[layer + 64 + (((c2 - 8) + (r3 * 8) - 1))] = 1 return mask else: raise Exception("I dont know what you did, but its BAD.") pass
def force_promotion_to_queen(move: chess.Move): return move if len(move.uci()) == 4 else chess.Move.from_uci(move.uci()[:4] + 'q')
def _chess_move(move: chess.Move): return {'__custom_type': 'chess_move', 'uci': move.uci()}
def get_legal_ucis(self): out = [] for i in self.board.legal_moves: out.append(Move.uci(i)) return out
def _send_move(self, move: chess.Move): assert self.game_started self.__send_cmd("move", move.uci())