New Text Document
New Text Document
New Text Document
}
if (rpmObject->rsp[2] == 1)
y=1;
}
//west:if (rpmObject->rsp[3] == 1)
{
if (x == 0)
x=2;
if (x == 1)
x=3;
}
if ((rpmObject->rsp[2] == 1) and (rpmObject->rsp[1] == 0) and (rpmObject->rsp[0]
== 0))
{
if (x == 0)
x=2;
if (x == 1)
x=3;
}
//south:if (rpmObject->rsp[5] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
if (rpmObject->rsp[4] == 1)
{
if ((rpmObject->rsp[3] == 0) or (rpmObject->rsp[0] == 0))
{
if (rpmObject->rsp[4] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
}
if (rpmObject->rsp[6] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
}
//routing direction founded by region vectors. Now routing.
switch(y)
{
case 0:
switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g nowhere" << endl;
break;
}
case 1:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
case 2:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g west" << endl;
directions.push_back(DIRECTION_WEST);
break;
}
case 3:
{
for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(1,0,0,0,0,0,1,1);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x <<"going east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,0,1,1,1,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
break;
}
case 1:
switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
case 1:
{ for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,0,0,0,0,1,1);
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 3:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,0,0,1,1);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,1,1,0,0,0);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going west" << endl;
directions.push_back(DIR
ECTION_WEST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
break;
}
break;
}
case 2:
switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
case 1:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,0,0,0,0,0,0,1);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going east" << endl;
directions.push_back(DIRECTION_E
AST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 2:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,1,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 3:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,1,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(1,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
}
break;
}
case 3:
switch(x)
{
case 0:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
case 1:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
break;
}
case 2:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
break;
}
case 3:
child_d = fork();
if (child_d == 0)
{
region(0,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
}
}
}}
if (rpmObject->rsp[8]==1)
{rpmObject->destns[core_no]=0;
for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g nowhere" << endl;
kill(getpid(), SIGTERM);
}
fclose (stdout);
dest.close();
return directions;
}