Esempio n. 1
0
/* Naively choose the move that will shrink the most dots. */
mask_t choose_move_greedy(grid_t grid, int allow_shrinkers, int *no_moves) {
    mask_t move = EMPTY_MASK;
    int i, num_dots, max_dots = -1;

    int num_moves;
    move_list_t moves;
    get_moves(grid, allow_shrinkers, &num_moves, moves);

    *no_moves = 0;
    if (SHOULD_SHRINK_RANDOM(num_moves, allow_shrinkers)) {
        *no_moves = 1;
        return random_mask();
    }

    for (i = 0; i < num_moves; i++) {
        grid_t new_grid;
        memcpy(new_grid, grid, sizeof(grid_t));
        num_dots = apply_move(new_grid, moves[i]);
        if (num_dots > max_dots) {
            max_dots = num_dots;
            move = moves[i];
        }
    }
    return move;
}
Esempio n. 2
0
void pancake::init_masks(uint8 n)
{
  hord_masks_.clear();
  ord_lookups_ = 0;		// add_mask will increase this correctly
  for (int i = 0; i < n; ++i){
    add_mask(random_mask(time(NULL)+i));
  }
}
Esempio n. 3
0
/* heuristic = score ** uncertainty_of_board
 *   where uncertainty_of_board = (sum of certainty_of_dots) / num_dots
 *         uncertainty_of_dot | 1/4 if shrunk by cycle
 *                            | 1/5 if shrunk by a regular move
 *                            | 1   otherwise
 */
void _choose_move(grid_t grid, int allow_shrinkers, int turns_remaining, int certainty, float *value, mask_t *move, int *no_moves) {
    float best_value = -1;
    mask_t best_move = EMPTY_MASK;

    int i, num_moves;
    move_list_t moves;

    get_moves(grid, allow_shrinkers, &num_moves, moves);

    if (certainty == 720 && SHOULD_SHRINK_RANDOM(num_moves, allow_shrinkers)) {
        *move = random_mask();
        *value = num_dots(*move);
        *no_moves = 1;
        return;
    }

    for (i = 0; i < num_moves; i++) {
        int score;
        float value;
        grid_t new_grid;

        if (turns_remaining > 1 || HAS_CYCLE(moves[i])) {
            memcpy(new_grid, grid, sizeof(grid_t));
            score = apply_move(new_grid, moves[i]);
        } else {
            score = num_dots(moves[i]);
        }

        value = pow(score, certainty / 720.0);

        if (turns_remaining > 1) {
            int next_certainty = certainty - score * (HAS_CYCLE(moves[i]) ? 15 : 16);
            float next_value;
            mask_t next_move;
            _choose_move(new_grid, allow_shrinkers, turns_remaining - 1, next_certainty, &next_value, &next_move, NULL);
            value += next_value;
        }

        if (value > best_value) {
            best_value = value;
            best_move = moves[i];
        }
    }

    *value = best_value;
    *move = best_move;
}