나는 현재 내가 받고있는 회전에 따라 다른 셀 블록을 추가하는 표가 있습니다. (전방 센서들 0 ROT)반복적 인 if 문 조건을 확인하는 더 나은 방법
전방 센서 ---> 좌측 센서^및 우측 센서 V
@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ ### @@@
@@@ ### S ### @@@
@@@ 4 3 ??? 3 4 @@@
@@@ 4 3 2 ??? 2 3 4 @@@
@@@ 4 3 2 1 G 1 2 3 4 @@@
@@@ 4 3 2 1 2 3 4 @@@
@@@ 4 3 2 3 4 @@@
@@@ 4 3 4 @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@
@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
아래 도면에있어서
@@@ = Map border ### = Obstacle 0-9 = Distance to goal-node ??? = Goal Path
로봇 시작 자세
이제 로봇이 어떻게 배치되어 있는지 확인하여 회전에 따라 장애물을 올바르게 추가 할 수 있습니다.
는 지금 내가이 (조각) 같은 경우 명령문의 무리를하고 있어요 = X I = Y, J :(currentRot이 0-360 사이)을. 위에 지금
if(currentRot >= 0 && currentRot <= 45){
printf("\n0-45");
if (ir.sensor[5] > FULL_DANGER){ //left
if(GetCellState(grid,newStart.i-1,newStart.j) != MAP_BORDER){ChangeCellState(grid,newStart.i-1,newStart.j,-3);printf("\n1,1");goto SUCCESS;} //add obs in map
}
if (ir.sensor[2] > FULL_DANGER){ //right
if(GetCellState(grid,newStart.i+1,newStart.j) != MAP_BORDER){ChangeCellState(grid,newStart.i+1,newStart.j,-3);printf("\n1,2");goto SUCCESS;}
}
if (ir.sensor[0] > FULL_DANGER || ir.sensor[7] > FULL_DANGER){ //ahead
if(GetCellState(grid,newStart.i,newStart.j+1) != MAP_BORDER){ChangeCellState(grid,newStart.i,newStart.j+1,-3);printf("\n1,3");goto SUCCESS;}
}
}
if(currentRot >= 45 && currentRot <= 90){
printf("\n45-90");
if (ir.sensor[5] > FULL_DANGER){ //left
if(GetCellState(grid,newStart.i,newStart.j-1) != MAP_BORDER){ChangeCellState(grid,newStart.i,newStart.j-1,-3);printf("\n1,1");goto SUCCESS;} //add obs in map
}
if (ir.sensor[2] > FULL_DANGER){ //right
if(GetCellState(grid,newStart.i,newStart.j+1) != MAP_BORDER){ChangeCellState(grid,newStart.i,newStart.j+1,-3);printf("\n1,2");goto SUCCESS;}
}
if (ir.sensor[0] > FULL_DANGER || ir.sensor[7] > FULL_DANGER){ //ahead
if(GetCellState(grid,newStart.i-1,newStart.j) != MAP_BORDER){ChangeCellState(grid,newStart.i-1,newStart.j,-3);printf("\n1,3");goto SUCCESS;}
}
}
질문 : 이러한 조건을 확인하고 같은 논리를 적용하는 더 나은 (스마트) 방법이? 마찬가지로, 중첩 된 for-loop를 사용하는 방법을 생각했지만 정확히 어떻게 작동하는지 정확히 알지 못합니다. 현재로서는 반복적이고 추악합니다.
전체 파일 here, row 519 찾을 수 있습니다 : 당신이 싶어 비교 모든 정보를 유지 구조의 테이블을 사용할 수 있는지
내가 사용하는 매크로를 것 :
나는 당신에게 명확 그래서 약간의 예를 넣을 수 있습니다. 그러나 http://codereview.stackexchange.com에 대한 질문이 아닙니까? –
@ Jean-FrançoisFabre 서브 스택에 익숙하지 않습니다. Stackoverflow는 대개 질문이있을 때 내가가는 곳입니다. 나 좀 봐. 이론적으로는 코드 검토 질문이 아니라 다른 방식으로 작업을 해결하는 논리에 관한 프로그래밍 질문입니다. – Joel
누군가 대답하면 좋습니다. 당신의 질문이 닫히면 codereview에 같은 것을 올리면 upvotes가 나옵니다. –