problems with glupickmatrix()

I´m programing a robot who go to one point to other point. My robot shoud study if there is some wall in the middle. If there is some wall, the robot should look for other direction to go to the point.
The robot uses the function asignarobot(x, y) to study if there is some wall in direction north, west, south…The position of robot is (x, y). To study direcction south the robot does:

//study direction south
xx1=x;
yy1=y+20;
yy1=(y + yy1)/2;
bb=18;
yy1=356-yy1;
aa=8;
pivotes1[cont].semsur=Procesolibre(xx1, yy1, aa, bb);

The fuction procesolibre returns if the direction to study is free or no.
The function asignarobot and procesolibre are:

void asignarobot(double x, double y, int j)

{
double xx1, yy1, aa, bb;
cont=cont+1;
pivotes1[cont].x1=x;
pivotes1[cont].y1=y;

	
//study position est
xx1=x+20;
xx1=(x + xx1)/2;
aa=18;
bb=8;
yy1=356-y;
pivotes1[cont].semeste=Procesolibre(xx1, yy1, aa, bb);

//study position west
xx1=x-20;
xx1=(x + xx1)/2;
aa=18;
bb=8;
yy1=356-y;
pivotes1[cont].semoeste=Procesolibre(xx1, yy1, aa, bb);

//study direction south
xx1=x;
yy1=y+20;
yy1=(y + yy1)/2;
bb=18;
yy1=356-yy1;
aa=8;
pivotes1[cont].semsur=Procesolibre(xx1, yy1, aa, bb);
	
//study direction north
xx1=x;
yy1=y-20;
yy1=(y + yy1)/2;
bb=18;
yy1=356-yy1;
aa=8;
pivotes1[cont].semnorte=Procesolibre(xx1, yy1, aa, bb);


xx1=x+20;

//the robot goes to est and study north
yy1=y-20;
yy1=(y+yy1)/2;
bb=18;
aa=8;
yy1=356-yy1;
pivotes1[cont].esnorte=Procesolibre(xx1, yy1, aa, bb);

xx1=x+20;

//the robot goes to est and study south yy1=y+20;
yy1=(y+yy1)/2;
yy1=356-yy1;
bb=18;
aa=8;
pivotes1[cont].essur=Procesolibre(xx1, yy1, aa, bb);

//study directio oenorte
xx1=x-20;
//the robot goes to west and study north yy1=(y+yy1)/2;
yy1=356-yy1;
bb=18;
aa=8;
pivotes1[cont].oenorte=Procesolibre(xx1, yy1, aa, bb);

//study directio oesur
xx1=x-20;
//the robot goes to west and study south yy1=y+20;
yy1=(y+yy1)/2;
yy1=356-yy1;
bb=18;
aa=8;
pivotes1[cont].oesur=Procesolibre(xx1, yy1, aa, bb);

//study directio nooeste
yy1=y-20;
//the robot goes to north and study west xx1=x-20;
xx1=(x+xx1)/2;
yy1=356-yy1;
bb=8;
aa=18;
pivotes1[cont].nooeste=Procesolibre(xx1, yy1, aa, bb);

//study directio noeste
yy1=y-20;
//the robot goes to north and study est xx1=x+20;
xx1=(x+xx1)/2;
yy1=356-yy1;
bb=8;
aa=18;
pivotes1[cont].noeste=Procesolibre(xx1, yy1, aa, bb);

//study directio sueste
yy1=y+20;
//the robot goes to south and study est xx1=x+20;
xx1=(x+xx1)/2;
yy1=356-yy1;
bb=8;
aa=18;
pivotes1[cont].sueste=Procesolibre(xx1, yy1, aa, bb);

//study directio suoeste
yy1=y+20;
//the robot goes to south and study west xx1=x-20;
xx1=(x+xx1)/2;
yy1=356-yy1;
bb=8;
aa=18;
pivotes1[cont].suoeste=Procesolibre(xx1, yy1, aa, bb);

return;
}

bool Procesolibre(double xx, double yy, double a, double b)
{
bool semaforo;

// Space for selection buffer
GLuint selectBuff[BUFFER_LENGTH11];

// Hit counter and viewport storeage
GLint hits, viewport[4];

// Setup selection buffer
glSelectBuffer(BUFFER_LENGTH11, selectBuff);

// Get the viewport
glGetIntegerv(GL_VIEWPORT, viewport);

// Switch to projection and save the
    // matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();

// Change render mode
glRenderMode(GL_SELECT);

// Establish new clipping volume to
     // be unit cube around
// point (xPos, yPos) 
    //and extending two pixels
// in the vertical and horizontal 
   //direction
glLoadIdentity();
gluPickMatrix(xx, yy, 2*a, 2*b, viewport);
// Apply perspective matrix 
gluPerspective(45.0f, fAspect, 1.0, 425.0);

// Draw the scene
RenderScene();

// Collect the hits
hits = glRenderMode(GL_RENDER);

// If a single hit occured, display
    // the info.
//if hits>1 the position is not 
    //free, there is some wall behind 
    //the position 
if (hits>1) semaforo=false;
else semaforo =true;

// Restore the projection matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix();

// Go back to modelview for normal
    // rendering
glMatrixMode(GL_MODELVIEW);
return semaforo;
}

My problem is that the fuctio asignarobot works very well with directions south, north, est and west, but it don´t work with the other direction sueste, suoeste, noeste, nooeste, essur, esnorte, oesur and oenorte.
With this direction, in the case in there is a wall in this direction, the functio procesolibre return that the direction is free.
Could someone help me?

Sorry my very bad english.
Thanks.