Exemplo n.º 1
0
def choose_increase_min_move(board, deck, score):
    move_combinations = board.get_possible_moves()
    possible_moves = combine_moves_and_deck(move_combinations, deck.get_deck())

    original_score = score.get_score()
    min_score = np.min(original_score)
    min_idxs = np.where(original_score == min_score)[0]
    num_min_idxs = min_idxs.shape[0]

    moves_scores = board.batch_calculate_move_scores(possible_moves)
    updated_move_scores, _, _ = score.batch_peek_next_scores(moves_scores)
    min_scores = updated_move_scores[:, min_idxs].reshape(-1, num_min_idxs)
    total_min_scores = np.sum(min_scores, axis=1)
    max_total_min_score = np.max(total_min_scores)

    if max_total_min_score > 0:
        max_total_min_scores_idxs = np.where(
            total_min_scores == max_total_min_score)[0]

        if max_total_min_scores_idxs.shape[0] == 1:
            max_index = max_total_min_scores_idxs[0]
            return possible_moves[max_index]

        best_moves_so_far = possible_moves[max_total_min_scores_idxs, :]
        best_moves_updated_scores = updated_move_scores[
            max_total_min_scores_idxs, :]
        scores_diff = best_moves_updated_scores - np.expand_dims(
            original_score, 0)
        total_scores_diff = np.sum(scores_diff, axis=1)
        max_index = np.argmax(total_scores_diff)
        return best_moves_so_far[max_index]

    else:
        # Where you can't increase your lowest score just choose max
        return choose_max_scoring_move(board, deck, score)
Exemplo n.º 2
0
 def get_representations(board, deck, score, other_score, turn_of, repr_fn):
     move_combinations = board.get_possible_moves()
     possible_moves = combine_moves_and_deck(move_combinations,
                                             deck.get_deck())
     representations, possible_moves_subset = repr_fn(
         board, deck, score, other_score, turn_of, possible_moves)
     return representations, possible_moves_subset
Exemplo n.º 3
0
def choose_reduce_deficit_move(board, deck, score, other_score, margin):
    move_combinations = board.get_possible_moves()
    possible_moves = combine_moves_and_deck(move_combinations, deck.get_deck())
    moves_scores = board.batch_calculate_move_scores(possible_moves)
    updated_move_scores, _, _ = score.batch_peek_next_scores(moves_scores)
    other_score = np.expand_dims(other_score.get_score(), 0)

    diffs = other_score - updated_move_scores + 36 + margin
    diffs = fast_calculate_diffs(diffs)
    diffs -= 36

    total_diffs = np.sum(diffs, axis=1)
    min_diff = np.min(total_diffs)
    min_diff_idxs = np.where(total_diffs == min_diff)[0]
    num_min_diff_moves = min_diff_idxs.shape[0]

    if num_min_diff_moves == 1:
        return possible_moves[min_diff_idxs[0]]

    original_score = np.expand_dims(score.get_score(), 0)
    scores_diff = updated_move_scores - original_score
    total_scores_diff = np.sum(scores_diff, axis=1)

    min_diff_subset = total_scores_diff[min_diff_idxs]
    max_min_diff_idx = np.argmax(min_diff_subset)

    return possible_moves[min_diff_idxs][max_min_diff_idx]
Exemplo n.º 4
0
def choose_max_scoring_move(board, deck, score):
    move_combinations = board.get_possible_moves()
    possible_moves = combine_moves_and_deck(move_combinations, deck.get_deck())
    original_score = np.expand_dims(score.get_score(), 0)
    move_scores = board.batch_calculate_move_scores(possible_moves)
    updated_scores, _, _ = score.batch_peek_next_scores(move_scores)
    scores_diff = updated_scores - original_score
    total_scores_diff = np.sum(scores_diff, axis=1)
    max_index = np.argmax(total_scores_diff)
    return possible_moves[max_index]
Exemplo n.º 5
0
def choose_random_move(board, deck):
    move_combinations = board.get_possible_moves()
    possible_moves = combine_moves_and_deck(move_combinations, deck.get_deck())
    random_idx = np.random.randint(0, high=possible_moves.shape[0] - 1)
    return possible_moves[random_idx]