How to navigate a spider in a grid system?
<p>I have a problem where it needs to navigate a spider in a grid system (X, Y co-ordinate) with proper instruction. Initially, the spider is in (0,0) and face towards the positive Y axis. </p>

<p>There are 3 possible instructions for the navigation: 'F' for forward (1 grid in the same direction ), 'R' for right turn (90 degree) and 'L' for left turn (90 degree) and initially, the spider faces towards positive Y axis. </p>

<p>Say, if I pass the direction String of "LFF", the position should be (-2,0). I solve the problem and the current state of code is as following,</p>

<pre><code>public static void spiderNavigator(String str ){

    if( str == null || str.length() == 0)
        return;

    int [] initial = {0,0};

    boolean xPos = false, xNeg = false, yPos = true, yNeg = false; 

    char[] ch = str.toCharArray();

    for( char c: ch){

        // the initial position of the spider is towards the positive Y axis 

        if(c == 'L'){

            if(xPos){

                xPos = false;
                yPos = true;
            }

            else if ( xNeg){


                xNeg = false;
                yNeg = true;
            }

            else if(yPos){

                xNeg = true;
                yPos = false; 

            }

            else if (yNeg){

                yNeg = false;
                xPos = true;
            }
        }

        else if ( c == 'R'){

            if(xPos){

                xPos = false;
                yNeg = true;
            }

            else if ( xNeg){

                yPos = true;
                xNeg = false;
            }

            else if(yPos){

                yPos = false;
                xPos = true;
            }

            else if (yNeg){

                yNeg = false;
                xNeg = true;
            }

        }

        else if (c == 'F'){

            if(xNeg){

                initial[0]  -= 1;
            }

            else if (xPos){

                initial[0] += 1;
            }

            else if (yNeg){

                initial[1] -=1;
            }

            else if( yPos){

                initial[1] += 1;
            }

        }
    }

    System.out.println(Arrays.toString(initial));
}
</code></pre>

<p>However, the code feels quite ugly even to me. How can I design the algorithm in better way ?</p>