E D R , A S I H C RSS

Eight Queen Problem Discussion

EightQueenProblem��� ����� ��패하���� ThreeFs ����해 ������.

�� ���� ���� �� ������ ����, ���� ������ �� ����, ���� ���� �����������, ���� ������ ���������? ���� ��패했���� ���� 했�� �� � ������ �� �� ������ ��패�� ������������ �����?

���� ������ �� �� ����, �� �� ������ ������한 ������ ������, �� ������ PairProgramming (� NetMeeting ����, VirtualPairProgramming)�� ������ ���� �������. �� ���� ���������? �� ���� ���� ������ ��������� ����(correctness)��합���? �� ���� �� ������ 합���(� ���� �� ���하 �� ������ ������)? �� ���� ���� ���� ������ �������? �� ���� ���� ���� ���� ����화 합���? �� ��험�� ���� ����������� ���� ���� ������ ���� ����합���?

�� ���������� ��패한��.. (7���� ����.. �������� �� ������) �� �������� �� ������.

������.. �� �� ������ ������ ��패한�� (���� 7�� ����.. �������� �� ������.) ���� �������� ������.

������.. ��������. �� 한�� 한���� ��� �������� ���� ����하�� ���� �� ��하��... �������� 확��한 ����ㅡㅡ;

-- �호

  • Facts - ������:
�� ���� ���� ������ (�� ���� ��������. -_-;)�� ������. ������ 테��트 ������ ��..

�� �������� 해 ����판�� ����한 ������ �� ��������. 판�� � ���� �� ����.
~cpp 
    def testBoardEmpty (self):
        self.assertEquals (self.bd.GetData (2,2), 0)

    def testSetQueen (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.GetData (2,2) ,1)

    def testPrintBoard (self):
        self.bd.SetQueen (1,1)
        self.bd.SetQueen (2,2)
        self.bd.SetQueen (7,7)
        self.assertEquals (self.bd.PrintBoard (), '''00000000\n01000000\n00100000\n00000000\n00000000\n00000000\n00000000\n00000001\n''')

�� �������� '� �� �� ���� �����?' 하�� ���� ��. �� SelftyZone �� �했��. �� ��크하�� �� ��/��/����향 ���� ��크해�� ���� 4���� �� ������ ��������. ���� ����크�� ���� ���� �� ����할 ����하�� ������ �� ����하�� ������.
~cpp 
    def testIsSelftyZone (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.IsSelftyZone (3,3), 0)
        self.assertEquals (self.bd.IsSelftyZone (1,5), 1)

    def testFindQueenInSameVertical (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.FindQueenInSameVertical (2), 1)
        self.assertEquals (self.bd.FindQueenInSameVertical (3), 0)

    def testFindQueenInSameHorizonal (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.FindQueenInSameHorizonal (2), 1)
        self.assertEquals (self.bd.FindQueenInSameHorizonal (3), 0)

    def testFindQueenInSameCrossLeftTopToRightBottom (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (3,3), 1)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (1,1), 1)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (4,1), 0)

    def testFindQueenInSameCrossLeftBottomToRightTop (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (3,3), 0)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (3,1), 1)
        self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (1,3), 1)

~cpp 
    def testGetFirstCornerInCrossLeftTopToRightBottom (self):
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (3,3), (0,0))
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (4,3), (1,0))
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (1,5), (0,4))
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (0,0), (0,0))

    def testGetFirstCornerInCrossLeftBottomToRightTop (self):
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (2,2), (0,4))
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (3,5), (1,7))
        self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (7,7), (7,7))

������ ���� ����. ���� � ����할 �� ���� �� ������ �� ����했��.
~cpp 
    def testIsAttackableOthers (self):
        self.bd.SetQueen (2,2)
        self.assertEquals (self.bd.IsAttackableOthers (3,3),1)
        self.bd.SetQueen (7,1)
        self.assertEquals (self.bd.IsAttackableOthers (7,1),0)
        self.assertEquals (self.bd.IsAttackableOthers (4,4),1)

level (0����~7����) �� ���� ���� �������� ����트 (��확히�� 튜플) �������� .
~cpp 
    def testGetUnAttackablePositon (self):
        self.bd.SetQueen (0,0)
        self.assertEquals (self.bd.GetUnAttackablePosition (1), ((2,1),(3,1),(4,1),(5,1),(6,1),(7,1)))
        self.assertEquals (self.bd.GetUnAttackablePosition (2), ((1,2),(3,2),(4,2),(5,2),(6,2),(7,2)))

�������� ����� ������ ���� ��크 �� �� 해 (����) ���������� 52������ ����. 하��, ���� Queen ����하�� �������� ����해������ 3�� ���� ����. --;

  • Feelings - ����: ���� ������� 한편���� ��팔���� 하��. -_-; ��.. �������� �� �� �� ���� ������. �� ��������하����.. �� ��� ������������ �������� ���� ��� 한��. (�� �� �� stack ��� recursive �� ��할������������������) ���� �� �� ������ test��한 �� �������� ���.

-- ��

��������.

�������� 항�� "What is the simplest thing that could possibly work?"�� ������TestDrivenDevelopment����? 테��트/���� ����클 행하����텝 ���� 하���� ����했����? ���� ���� �� ���� ����, ���� ���� ��했����? �� �� 테��트 ����클�� ��텝 �� ����하���� 했����? ���� ���� �� ���� ���� ����� ���� ���� 테��트�� ������? (���� ���� 한�� ���� ����하�� �� ���� ����) �� ���� �������� ���� ������ ���� ����? 테��트 ���� ����한 ���� �� ������� ������ ��������? TestDrivenDevelopment����� ��� 패��하���� 하�� 테��트 ���������� ��������? ���� ��하�� ���� ������ �� ���� ������? ������ �� EightQueenProblem������ �� 30 �� ���� 50 �� ������(테��트 ���� ����) ���������. TestDrivenDevelopment����. --��

.

���� ���� ���� ����하�� ���� �� ���� ������ 힘���� ����. (�� �� ������ �������� ������ ������ �� ����) �� ����했���� �������� , � ����하�� ���� �������� �� TestDrivenDevelopment ��했���� ������. (�������� ���� 호�� �� ��� ������������ ������. )

�������� ���� �� 80/20 ���� 통����������. :) 3���� �� �� ���� ���� ��������.
~cpp 
    def DefineQueen (self, Level):
        if Level == 8:
            self.Count = self.Count + 1
            print "%d. level : %d \n" % (self.Count, Level)
            print self.PrintBoard ()
            return 0
        
        PositionList = self.GetUnAttackablePosition (Level)

        for position in PositionList:
            self.SetQueen (position[0], position[1])
            Ret = self.DefineQueen (Level + 1)
            if not Ret:
                self.SetData (position[0],position[1], 0)
��, ���� Queen�� �� ����하�� ���� ����������. �� �� TestCase �� �������� ������ 판�� ������ Queen�� ��������하�� �� ���� ����. �������� �� �������� �������� 했������, �������� ���������� 확�� �� ��했��. 확�� �� 테��트������ �� �� ���� 할텐��, ������ �� �� � 테��트���� ����������.

������ 'Level 8�� ���� 판 �� ����, ��황�� ����������� ���� ����해���� ������ ����트�� �� ������, �� ������ ������ ��������트하�� ���� �� �� ������' �� ������ �������� 하��. (������ 100�� ������ ���� 하��. ^^;)

������ �������� ������ TFP �� �� ����했��, ����하�� ����하�� ����������. (�� Queen ���� �� �������� ������함) 테��트����/�������� �� ���� 하 ����������. (�� �� �� ��. ^^;) 흠.. ������ 'The Simplest Thing' ���������� ����, ��� 해 ������ �������� ����하��, 해 ������ 해 Top-Down 형태�� ���� �������� ������ 해 테��트 ������������ ������ ����. --��

�� ���� C++, Python, Java OOPL ����했���� �� �� OOP�� � ���� �� ���� -- class 키���� ������ OOP�� 하�� 힘������. ���� ���� ��하���� ������ ������ 평�� ����한 �� ��탈��티�� ������ 하��. ������ OOP 편하�� ����하���� ���� ������ ������ ���� �� ��������. �� ���� �������� OOP ������ �������� �� ��������. --��

���� ��호�������� ������..

Eight Queens program written by Marcel van Kervinck
~cpp 
/* Marcel van Kervinck <xxxxxxx@xxxxx.xxx.xxx.xx> */
t(a,b,c){int d=0,e=a&~b&~c,f=1;if(a)for(f=0;d=(e-=d)&-e;f+=t(a-d,(b+d)*2,(
c+d)/2));return f;}main(q){scanf("%d",&q);printf("%d\n",t(~(~0<<q),0,0));}

When the program is run, one has to give a number n (smaller than 32), and the program will return in how many ways n Queens can be put on a n by n board in such a way that they cannot beat each other.
Note that the d=(e-=d)&-e; statement can be compiled wrong on certain compilers. The inner assignment should be executed first. Otherwise replace it with e-=d,d=e&-e;.


��패한 ����
  • ���� ���� ����, ��� ����. �������� ����한 ����, 크��큰 ���� ������ ����. ���� ���� ������. TT
  • ���� ���� ����판���� �� 하��. (���� ���히한 �� TT)
  • TFD�� ������. test code ������ �� ��하��. ��, test�� ���� ��한 �� ����.

�� ���� ��...������
DeleteMe) ��.. ������ ����������..~ ^^ --1002

ThreeFs
�� PairProgramming�� ������������. TDD ���� 30 ���� ���� 1��30 TDD�� 했������.

���������� �� �� ��해 헤������ ����������. ���� TDD ��하�� 파트���� 테��트 �� ��해할 �� ����� 한 ���� 페�� ������ ���� ������������. �� ������ 파트�� ������, 파트 �������� ���� ��������. ��해 ���� ���� ���� ��하�� ���� �������������.

���������� ����하�� ���� ��������, �������� � ���하���� ������ ������. --Leonardong
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:11
Processing time 0.0288 sec