        class DirectionsTested
        {
            public boolean triedLeft = false, triedRight = false, triedUp = false, triedDown = false;
            public static final int NONE = -1, LEFT = 0, RIGHT = 1, UP = 2, DOWN = 3;            

            public int randomUntriedDirection()
            {
                int r = (int)(Math.random() * 4);
                for(int i = 0; i < 4; i++)
                {
                    int d = (r + i) % 4;
                    if(d == DirectionsTested.LEFT && !this.triedLeft)
                    {
                        this.triedLeft = true;
                        return DirectionsTested.LEFT;
                    }
                    else if(d == DirectionsTested.RIGHT && !this.triedRight)
                    {
                        this.triedRight = true;
                        return DirectionsTested.RIGHT;
                    }
                    else if(d == DirectionsTested.UP && !this.triedUp)
                    {
                        this.triedUp = true;
                        return DirectionsTested.UP;
                    }
                    else if(!this.triedDown)
                    {
                        this.triedDown = true;
                        return DirectionsTested.DOWN;
                    }
                }
                return DirectionsTested.NONE;
            }
        }