Esempio n. 1
0
    def keys_to_serialized_example(dict_keys):
        boards = board_info_array_from_dict_keys(dict_keys)

        jitted_set_up_struct_moves(boards)

        lengths = boards['children_left']

        moves_lists = list(
            map(lambda b: b['unexplored_moves'][:b['children_left']], boards))

        moves = np.concatenate(moves_lists)

        children = np.repeat(boards, lengths)

        push_moves(children, moves)

        evaluated_results = node_batch_eval_fn(children)

        result_splitters = np.r_[0, np.cumsum(lengths, dtype=np.int32)]

        the_results = list(
            evaluated_results[start:end]
            for start, end in zip(result_splitters[:-1], result_splitters[1:]))

        return list(
            map(create_serialized_example, dict_keys, moves_lists,
                the_results))
Esempio n. 2
0
    def simple_struct_copy_push(board, move):
        to_push = np.array([board.copy()])
        push_moves(to_push, np.array([move]))

        to_return = to_push[0]
        to_return['children_left'] = 0
        to_return['unexplored_moves'][:] = 255

        return to_return
Esempio n. 3
0
def cur_hash_getter(fen_to_start,move_lists,max_possible_moves):
    hashes = np.zeros((len(move_lists), max_possible_moves), dtype=np.uint64)
    initial_board = create_node_info_from_fen(fen_to_start, 255, 0)
    for j in range(len(move_lists)):
        board = initial_board.copy()
        for i,move in enumerate(move_lists[j]):
            push_moves(board, np.array([[move.from_square, move.to_square, 0 if move.promotion is None else move.promotion]], dtype=np.uint8))
            hashes[j,i] = board[0]['hash']
    return hashes