Beispiel #1
0
void	find_search(t_group *grp)
{
	t_hist *curr;

	if (TERM(curs_pos) == 0)
	{
		display_search(grp, TERM(cmd_save));
		REMOVE(&TERM(search));
		TERM(search) = SDUP(TERM(cmd_save));
		return ;
	}
	curr = grp->curr_hist == NULL ? grp->hist : grp->curr_hist;
	while (curr != NULL)
	{
		if (ft_strstr(curr->name, TERM(cmd_line)) != NULL)
		{
			display_search(grp, curr->name);
			REMOVE(&TERM(search));
			TERM(search) = SDUP(curr->name);
			break ;
		}
		curr = curr->next;
	}
	curr == NULL ? REMOVE(&TERM(search)) : 0;
}
bool GetPath(void *data, xyLoc s, xyLoc g, std::vector<xyLoc> &path){	
	/* clear open list */
	#ifdef _BUCKET_LIST_H
		open_list.Reset();
	#elif HEAP2_H
		open_list.reset();
		open_list.reserve(3000);
	#else
		open_list.clear();
	#endif
	
	/* initialize closed list */
	closed_list.resize(map.size());
	for( int i=0; i<map.size(); i++){
		closed_list[i] = false;
	}
	
	/* start location */
	start = s;
	
	/* goal location */
	goal = g;
	
	m_currentIteration++;
	
	/* start state */
	State* start = (State*)malloc(sizeof(State));//new State;
	#ifdef _SPEEDY_H
		start->set_values(distance(s,g),s);
	#endif
	
	#ifdef _WASTAR_H
		start->set_values(0,distance(s,g),s);
	#endif
	start->set_parent(NULL);
	start->m_iteration = m_currentIteration;
	
	/* push start state */
	#ifdef _BUCKET_LIST_H
		open_list.Push(start);
	#elif HEAP2_H
		open_list.add(start);
	#else
		open_list.push_back(start);
		std::push_heap(open_list.begin(),open_list.end(),StateComparator());
	#endif
	
	/* Speedy */
	#ifdef _BUCKET_LIST_H
	while( !open_list.Empty() ){
	#else
	while( !open_list.empty() ){
	#endif
		#ifdef _BUCKET_LIST_H
			State* curr = open_list.Pop();
		#elif HEAP2_H
			State* curr = open_list.remove();
		#else
			std::pop_heap (open_list.begin(),open_list.end(),StateComparator());
			State* curr = open_list.back();
			open_list.pop_back();
		#endif
		
		if( FindGoal(curr) ){
			return_path(curr, path);
			#ifdef DEBUG
				display_search();
			#endif
			break;
		}
		
		GetSuccessors(curr->pos(), succ);
		
		for( int i=0; i<succ.size(); i++){
			State* nb = (State*)malloc(sizeof(State));//new State;
			xyLoc pos = succ[i];
			
			#ifdef _SPEEDY_H
				/* estimate total number of moves to go */
				nb->set_values(distance(pos,g),pos);
			#endif
			
			#ifdef _WASTAR_H
				/* octile distance heuristic */
				if( succ[i].x == curr->pos().x || succ[i].y == curr->pos().y ){
				nb->set_values(curr->g()+1.0f,distance(pos,g),pos);
				}
				else{
					nb->set_values(curr->g()+sqrt(2),distance(pos,g),pos);
				}
			#endif
			
			nb->set_parent(curr);
			nb->m_iteration = m_currentIteration;
			int index = GetIndex(succ[i]);
			if( !closed_list[index] && map[index] ){
				closed_list[GetIndex(pos)] = true; //add state to closed list
				#ifdef _BUCKET_LIST_H
					open_list.Push(nb);
				#elif HEAP2_H
					open_list.add(nb);
				#else
					open_list.push_back(nb);
					std::push_heap(open_list.begin(),open_list.end(),StateComparator());
				#endif
			}
		}
	}
	
	return true;
}