Beispiel #1
0
def full_test():
    """
    Runs every test relevant to Batch First's performance.

    :return: A boolean value indicating if all tests were passed

    TODO:
    1) Add test to verify zero-window negamax search returns same result (bool) with or without use of the
    Transposition Table (Currently checked manually by commenting out functions used to add boards to the TT)
    """

    result_str = ["Failed", "Passed"]

    print("Starting tests.\n")

    constants_results = test_constants_are_different_jitted()

    print("Constants test:                                               %s"%result_str[constants_results])
    
    jitclass_perft_results = full_perft_tester(
        lambda fen, depth: traditional_perft_test(create_board_state_from_fen(fen), depth))

    print("PERFT test using JitClass:                                    %s"%result_str[jitclass_perft_results])

    scalar_perft_results = full_perft_tester(
        lambda fen, depth: structured_scalar_perft_test(create_node_info_from_fen(fen, 0, 0), depth))

    print("PERFT test using NumPy structured scalar:                     %s"%result_str[scalar_perft_results])

    move_verification_results = move_verification_tester(
        scalar_is_legal_move,
        lambda b: create_node_info_from_python_chess_board(b)[0])

    print("Move legality verification test:                              %s"%result_str[move_verification_results])

    zobrist_hash_results = zobrist_hash_test(cur_hash_getter)

    print("Incremental Zobrist hash test:                                %s"%result_str[zobrist_hash_results])

    training_pipe_results, inference_pipe_results = complete_board_eval_tester(
        tfrecords_writer=cur_tfrecords_writer,
        feature_getter=cur_tfrecords_to_features,
        inference_pipe_fn=get_board_data,
        boards_to_input_for_inference=cur_boards_to_input_list_fn,
        piece_to_filter_fn=cur_piece_to_filter_fn,
        ep_filter_index=1,
        castling_filter_indices=[8, 15])

    print("Board evaluation data creation and training pipeline test:    %s" % result_str[training_pipe_results])
    print("Board evaluation inference pipeline test:                     %s" % result_str[inference_pipe_results])




    if constants_results and jitclass_perft_results and scalar_perft_results and move_verification_results and zobrist_hash_results and training_pipe_results and inference_pipe_results:
        print("\nAll tests were passed!")
        return True
    else:
        print("\nSome tests failed! (see above).")
        return False
Beispiel #2
0
    def zero_window_search(board, depth, separator, hash_table):
        priority_bins = PriorityBins(np.linspace(0, 1, 1000),
                                     max_batch_size,
                                     testing=run_search_in_testing_mode)

        separator_to_use = np.nextafter(separator, MIN_FLOAT32_VAL)

        root_node = set_up_root_node_for_struct(
            move_predictor, hash_table,
            create_node_info_from_python_chess_board(board, depth,
                                                     separator_to_use))

        if root_node.board_struct[0]['terminated']:
            return root_node.board_struct[0]['best_value']

        if bool(depth % 2) == board.turn:
            board_eval_fn = lambda *args: -dummy_eval_for_bf(*args)
        else:
            board_eval_fn = dummy_eval_for_bf

        to_return = zero_window_negamax_search(
            root_node,
            priority_bins,
            board_eval_fn,
            move_predictor,
            hash_table=hash_table,
            testing=run_search_in_testing_mode)
        return to_return
Beispiel #3
0
 def search_helper(py_board,
                   depth,
                   alpha=MIN_FLOAT32_VAL,
                   beta=MAX_FLOAT32_VAL):
     color = 1 if py_board.turn else -1
     return negamax(
         create_node_info_from_python_chess_board(py_board)[0], depth,
         alpha, beta, color)
Beispiel #4
0
def cur_boards_to_input_list_fn(boards):
    struct_array = np.concatenate(
        [create_node_info_from_python_chess_board(board) for board in boards])

    return struct_array_to_ann_inputs(
        struct_array, np.array([], dtype=numpy_node_info_dtype),
        np.ones(len(struct_array), dtype=np.bool_), np.array([],
                                                             dtype=np.bool_),
        len(struct_array))
Beispiel #5
0
def cur_boards_to_input_list_fn(boards):
    return struct_array_to_ann_inputs(
        np.concatenate([
            create_node_info_from_python_chess_board(board) for board in boards]))
Beispiel #6
0
def full_test():
    """
    Runs every test relevant to Batch First's performance or correctness (that's been created so far).

    :return: A boolean value indicating if all tests were passed
    """
    result_str = ["Failed", "Passed"]

    print("Starting tests (this will likely take 1-5 minutes).\n")

    test_results = [False] * 7

    test_results[0] = full_perft_tester(
        lambda fen, depth: traditional_perft_test(
            create_board_state_from_fen(fen), depth))

    print("PERFT test using JitClass:                                    %s" %
          result_str[test_results[0]])

    test_results[1] = full_perft_tester(
        lambda fen, depth: structured_scalar_perft_test(
            create_node_info_from_fen(fen, 0, 0), depth))

    print("PERFT test using NumPy structured scalar:                     %s" %
          result_str[test_results[1]])

    test_results[2] = move_verification_tester(
        scalar_is_legal_move,
        lambda b: create_node_info_from_python_chess_board(b)[0])

    print("Move legality verification test:                              %s" %
          result_str[test_results[2]])

    test_results[3] = zobrist_hash_test(cur_hash_getter)

    print("Incremental Zobrist hash test:                                %s" %
          result_str[test_results[3]])

    test_results[4], test_results[5] = complete_board_eval_tester(
        tfrecords_writer=dummy_records_writer_creator(),
        feature_getter=cur_tfrecords_to_features,
        inference_pipe_fn=get_board_data,
        boards_to_input_for_inference=cur_boards_to_input_list_fn,
        piece_to_filter_fn=cur_piece_to_filter_fn,
        ep_filter_index=1,
        castling_filter_indices=[8, 15])

    print("Board evaluation data creation and training pipeline test:    %s" %
          result_str[test_results[4]])
    print("Board evaluation inference pipeline test:                     %s" %
          result_str[test_results[5]])

    test_results[6] = zero_window_search_tester(
        create_negamax_function(dummy_eval_for_simple_search),
        negamax_zero_window_search_creator(pseudo_random_move_eval),
        get_empty_hash_table)

    print("Zero-window search test:                                      %s" %
          result_str[test_results[6]])

    if all(test_results):
        print("\nAll tests were passed!")
        return True
    else:
        print("\nSome tests failed! (see above).")
        return False