Exemplo n.º 1
0
bool search::bfs(){
	pop();
	temp_state.move_left();
	temp_state.display();
	if(is_goal()){
		return true;
	}
	push();
	temp_state.move_right();
	temp_state.display();
	if(is_goal()){
		return true;
	}
	push();
	
	temp_state.move_top();
	if(is_goal()){
		return true;
	}
	temp_state.display();
	push();
	
	temp_state.move_bottom();
	if(is_goal()){
		return true;
	}
	temp_state.display();
	push();

	bfs();

}
Exemplo n.º 2
0
//******************************************************************************
//******************************************************************************
//This function is used to get the coordinates of the users ships
void inputS(board &player, int i){
    int x=0;
    int y=0; 
    int x2=0; 
    int y2=0;
    char Cypos;
    bool reDo=false;
    
    //enter
    do{
        reDo=false;
        cout<<"Enter "<<player.getN(i)<<" which is of size"
                " "<<player.getSzs(i)<<endl;
        cout<<"enter the initial x position 1-10"<<endl;
        do{
            cin>>x;
            try{
                if(x>10||x<1)
                {
                    string error1="Please enter a value between 1 and 10";
                    throw error1;
                }
            }
            catch (string error1)
            {
                cout<<error1<<endl;
            }
        }while(x>10||x<1);
            //enter
        do{    
            cout<<"enter the initial y position A-J"<<endl;
            cin>>Cypos;
        }while(CtoInt(toupper(Cypos))==11);
        //convert
        y=CtoInt(toupper(Cypos));

        //enter
        do{
            cout<<"enter the final x position 1-10"<<endl;
            cin>>x2;
        }while(x2>10||x2<1);
        //enter
        do{    
            cout<<"enter the final y position A-J"<<endl;
            cin>>Cypos;
        }while(CtoInt(toupper(Cypos))==11);
        //convert
        y2=CtoInt(toupper(Cypos));
        try{
            reDo=player.testCor(i, x, y, x2, y2);
        }
        catch(board::invalid){
            cout<<endl;
            cout<<"Invalid Coordinates were entered"<<endl;
            cout<<"Re-Enter Values with the with correct size"<<endl;
            cout<<endl;
            player.display();
        }
    }while(!reDo);
    
    
    //create ship with initial x and pos positions
    player.makeShp(i, x, y, x2, y2);
    player.shipOn(i);
    player.disCoor(i);
    player.fillrest(i);

}