퇴근5분전



전에 큐브를 구현해보려고 한적이 있었음.
한 면을 두고 그 면에 회전방향을 지정해서 돌리는 로직을 만들었었는데
간단히 올려봄. 

아래 소스는 동일하게 동작한다.
과연 무엇을 쓸것인가?
하나는 그나마 보기에 좋고 소스가 조금더 길다( 쬐끔 )
하나는 보기어렵고 소스가 짧다.

        void RotationFor(bool CW)
        {
            string[] buffer = new string[3];

            buffer[CW ? 2 : 0]  = CubeBuffer[CW ? 11 : 0 ];
            buffer[1]           = CubeBuffer[CW ? 10 : 1 ];
            buffer[CW ? 0 : 2]  = CubeBuffer[CW ?  9 : 2 ];

            for (int loop = 0; loop < 3; loop++)
            {
                CubeBuffer[(CW ? 11 - (loop * 3)-0 : (loop * 3) + 0 ) ] = CubeBuffer[(CW ?11 - (loop * 3) - 3 : (loop * 3) + 3  )];
                CubeBuffer[(CW ? 11 - (loop * 3)-1 : (loop * 3) + 1 ) ] = CubeBuffer[(CW ?11 - (loop * 3) - 4 : (loop * 3) + 4  )];
                CubeBuffer[(CW ? 11 - (loop * 3)-2 : (loop * 3) + 2 ) ] = CubeBuffer[(CW ?11 - (loop * 3) - 5 : (loop * 3) + 5  )];               
            }

            CubeBuffer[CW ? 2 :  9] = buffer[CW ? 2 : 0] ;
            CubeBuffer[CW ? 1 : 10] = buffer[1];
            CubeBuffer[CW ? 0 : 11] = buffer[CW ? 0 : 2] ;
        }

        void Rotation(bool CW)
        {
            string[] buffer = new string[3];
            if (!CW)
            {
                buffer[ 0] = CubeBuffer[ 0];
                buffer[ 1] = CubeBuffer[ 1];
                buffer[ 2] = CubeBuffer[ 2];

                CubeBuffer[ 0] = CubeBuffer[ 3];
                CubeBuffer[ 1] = CubeBuffer[ 4];
                CubeBuffer[ 2] = CubeBuffer[ 5];

                CubeBuffer[ 3] = CubeBuffer[ 6];
                CubeBuffer[ 4] = CubeBuffer[ 7];
                CubeBuffer[ 5] = CubeBuffer[ 8];

                CubeBuffer[ 6] = CubeBuffer[ 9];
                CubeBuffer[ 7] = CubeBuffer[10];
                CubeBuffer[ 8] = CubeBuffer[11];

                CubeBuffer[ 9] = buffer[ 0];
                CubeBuffer[10] = buffer[ 1];
                CubeBuffer[11] = buffer[ 2];
            }
            else
            {
                buffer[ 2] = CubeBuffer[11];
                buffer[ 1] = CubeBuffer[10];
                buffer[ 0] = CubeBuffer[ 9];
               
                CubeBuffer[11] = CubeBuffer[ 8];
                CubeBuffer[10] = CubeBuffer[ 7];
                CubeBuffer[ 9] = CubeBuffer[ 6];
               
                CubeBuffer[ 8] = CubeBuffer[ 5];
                CubeBuffer[ 7] = CubeBuffer[ 4];
                CubeBuffer[ 6] = CubeBuffer[ 3];
               
                CubeBuffer[ 5] = CubeBuffer[ 2];
                CubeBuffer[ 4] = CubeBuffer[ 1];
                CubeBuffer[ 3] = CubeBuffer[ 0];

                CubeBuffer[2] = buffer[ 2];           
                CubeBuffer[1] = buffer[ 1];             
                CubeBuffer[0] = buffer[ 0];
               
               
            }

        }



'# 2) .Net ( Vs 2005 ) > 기타' 카테고리의 다른 글

PWD 암호화 객체.  (0) 2009.05.08
인터페이스와델리게이트조합1  (2) 2009.05.08
DB로컬 연결시 문구  (0) 2009.05.02
XML 컨트롤...  (0) 2009.05.02
DB Connection Factory  (0) 2009.05.01