Exemplo n.º 1
0
void test(){
	
	int seq [6] = {0,0,0,0,0,0};
	Board * start ;
	Board * current;
	int record=0;
	initialize();
	int step_size =0 ;
	while(gen_next_recur(seq)){
		record ++ ;
		//if(record < 20)
		//	continue;
		print_seq(seq);
		for(int piindex = 0 ; piindex < PATTERN_NUM ;piindex++){
			start = new Board();
			start->init_with_sequence(seq,piindex);
			open_list.push(start);
			step_size =0;	
			
			while(!open_list.empty()){
				current = open_list.top();
				open_list.pop();
				close_list.push(current);
				//current->print();
				if(current->is_goal()){
					printf("Goal Found for pattern %d , step =%d\n",piindex,current->step);
					//current->print();
					break;
				}
				if(step_size<current->step){
					step_size = current->step;
					printf("%d\n",step_size);
				}
				for(int tile_id =0 ;tile_id < PATTERN_SIZE ;tile_id++){
					for (int direc =0; direc < 4 ;direc++){
						Board * tmp = current->gen_board(tile_id,direc);
						if(tmp){
							if(!close_list.exist(tmp)&&!open_list.exist(tmp)){	
								open_list.push(tmp);
							}else
								delete tmp;
						}
					}
				}
			}

			write_db(seq,piindex,current->step);
			
			while(!open_list.empty()){
				current = open_list.top(); 
				open_list.pop();
				delete current;
			}
			
			while(!close_list.empty()){
				current = close_list.top();
				close_list.pop();
				delete current;
			}
			//break;
		}
		//break;
	}
}