コード例 #1
0
ファイル: boe.locutils.cpp プロジェクト: LibreGames/cboe
void update_explored(location dest) {
	if(cartoon_happening) return;
	location shortdest,look;
	
	location look2;
	
	shortdest.x = (short) dest.x;
	shortdest.y = (short) dest.y;
	
	which_party_sec.x = univ.party.outdoor_corner.x + univ.party.i_w_c.x;
	which_party_sec.y = univ.party.outdoor_corner.y + univ.party.i_w_c.y;
	
	if(overall_mode == MODE_OUTDOORS) {
		univ.out.out_e[dest.x][dest.y] = 2;
		for(look.x = shortdest.x - 4; look.x < shortdest.x + 5; look.x++)
			for(look.y = shortdest.y - 4; look.y < shortdest.y + 5; look.y++) {
				// TODO: Windows had an extra check, is this needed?
				//if((look.x == minmax(0,95,(int)look.x)) && (look.y == minmax(0,95,(int)look.y))) {
				if(univ.out.out_e[look.x][look.y] == 0)
					if(can_see_light(shortdest, look, sight_obscurity) < 5)
						univ.out.out_e[look.x][look.y] = 1;
				//}
			}
		
		
	}
	
	if(overall_mode > MODE_OUTDOORS) {
		make_explored(dest.x,dest.y);
		for(look2.x = max(0,dest.x - 4); look2.x < min(univ.town->max_dim(),dest.x + 5); look2.x++)
			for(look2.y = max(0,dest.y - 4); look2.y < min(univ.town->max_dim(),dest.y + 5); look2.y++)
				if(!is_explored(look2.x,look2.y))
					if((can_see_light(dest, look2,sight_obscurity) < 5) && (pt_in_light(dest,look2)))
						make_explored(look2.x,look2.y);
	}
}
コード例 #2
0
ファイル: lab11p1.cpp プロジェクト: LaitaStefan/labs-2014
int main() {
  /* Deschidem un fisier si citim din el configuratia initiala si finala. */
  std::ifstream in("src-lab11/Puzzle.in");

  /* Dimensiunea puzzel-ului este setata global, per clasa. */
  in >> Node::N;
  Node* initial_node = new Node();
  Node* solution_node = new Node();
  in >> *initial_node >> *solution_node;

  std::cout << *initial_node << std::endl;
  std::cout << *solution_node << std::endl;

  /* Pentru nodurile in curs de explorare, implementate ca o coada de
   * prioritati. */
  std::priority_queue<Node*, std::vector<Node*>, NodeComparator> open(
      NodeComparator(NodeComparator::AStarOptimized, solution_node));

  /* Initial doar nodul de start este in curs de explorare. */
  initial_node->set_distance(0);
  initial_node->set_parent(NULL);
  open.push(initial_node);

  /* Pentru nodurile care au fost deja expandate. */
  std::vector<Node*> closed;

  do {
    if (open.empty()) {
      std::cout << "Nu a fost gasita nicio solutie." << std::endl;
      break;
    }

    Node* next = open.top(); 
    open.pop();

    if (next->has_same_state(*solution_node)) {
      std::cout << "A fost gasita solutia:" << std::endl;
      next->print_path();
      delete next;
      break;
    }

    /* Se exploreaza doar nodurile care nu au fost explorate deja. */
    if (!is_explored(closed, *next)) {
      /* Explorarea nodului este finalizata. */
      closed.push_back(next);

      /* Lista vecinilor. */
      std::vector<Node*> expand_next;
      next->expand(expand_next);
      for (std::vector<Node*>::iterator it = expand_next.begin();
           it != expand_next.end();
           ++it) {
        open.push(*it);
      }
    } else {
      delete next;
    }
  } while (true);

  /* Eliberare memoria folosită de noduri. */
  while (!open.empty()) {
    delete open.top();
    open.pop();
  }

  for (std::vector<Node*>::iterator it = closed.begin(); it != closed.end();
       ++it) {
    delete *it;
  }

  delete solution_node;

  return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: MrNerverDie/hackerrank
void nextMove(int x, int y, int pacman_x, int pacman_y, int food_x, int food_y, char grid[x][y]){
    int explored[1000][2] = {0};
    explored[0][0] = pacman_x;
    explored[0][1] = pacman_y;
    int explored_size = 1; 

    int path[1000][2] = {0};
    path[0][0] = pacman_x;
    path[0][1] = pacman_y; 
    int path_size = 1;

    // 2 - log the path pointer
    int stack[100][3] = {0};
    int stack_size = 0;

    int current_x = pacman_x;
    int current_y = pacman_y;
    do{
        // case UP
        if (current_x - 1 >= 0){
            if ((!is_explored(current_x - 1, current_y, explored, explored_size)) && grid[current_x - 1][current_y] != '%'){
                stack[stack_size][0] = current_x - 1;
                stack[stack_size][1] = current_y;
                stack[stack_size][2] = path_size;
                stack_size++;
            }
        }
        // case LEFT
        if (current_y - 1 >= 0){
            if ((!is_explored(current_x, current_y - 1, explored, explored_size)) && grid[current_x][current_y - 1] != '%'){
                stack[stack_size][0] = current_x;
                stack[stack_size][1] = current_y - 1;
                stack[stack_size][2] = path_size;
                stack_size++;
            }
        }
        
        // case RIGHT
        if (current_y + 1 < y){
            if ((!is_explored(current_x, current_y + 1, explored, explored_size)) && grid[current_x][current_y + 1] != '%'){
                stack[stack_size][0] = current_x;
                stack[stack_size][1] = current_y + 1;
                stack[stack_size][2] = path_size;
                stack_size++;
            }
        }
        // case DOWN
        if (current_x + 1 < x){
            if ((!is_explored(current_x + 1, current_y, explored, explored_size)) && grid[current_x + 1][current_y] != '%'){
                stack[stack_size][0] = current_x + 1;
                stack[stack_size][1] = current_y;
                stack[stack_size][2] = path_size;
                stack_size++;
            }
        }

        while (is_explored(stack[stack_size - 1][0], stack[stack_size - 1][1], explored, explored_size))
            stack_size--;
        path_size = stack[stack_size - 1][2];
        path[path_size][0] = stack[stack_size - 1][0];
        path[path_size][1] = stack[stack_size - 1][1];
        explored[explored_size][0] = path[path_size][0];
        explored[explored_size][1] = path[path_size][1];
        explored_size++;
        path_size++;
        stack_size--;

        current_x = path[path_size - 1][0];
        current_y = path[path_size - 1][1];
    } while (current_x != food_x || current_y != food_y);
    
    printf("%d\n", explored_size);
    for (int i = 0; i < explored_size; ++i)
        printf("%d %d\n", explored[i][0], explored[i][1]);

    printf("%d\n", path_size - 1);
    for (int i = 0; i < path_size; ++i)
        printf("%d %d\n", path[i][0], path[i][1]);
}