Пример #1
0
        /**
         * @brief currentTool의 setter
         * @details 현재 사용하고 있는 색상을 설정하기 위해서 사용된다.
         * @param f set하고자 하는 currentTool
         */
        public void setCurrentTool(FIGURE f)
        {
            if (f == FIGURE.TEXT || f == FIGURE.CURVE)
            {
                MessageBox.Show("Sorry!!..");
                return;
            }

            currentTool = f;
        }
 public static void TestCorrection(List <Card> cards, Set set, FIGURE requiredFigure, int currentTest)
 {
     if (set.Figure != requiredFigure)
     {
         Assert.Fail($"Figure {requiredFigure} not detected. \n{GenerateStatistics(cards, set, requiredFigure, currentTest)}");
     }
     else if (set.cardsSet.Count != 5)
     {
         Assert.Fail($"Not enough cards in set deck. \n{GenerateStatistics(cards, set, requiredFigure, currentTest)}");
     }
 }
 public static void TestCorrection(List <Card> cards, Set set, FIGURE requiredFigure, VALUE highCard, int currentTest)
 {
     if (set.cardsSet[0].Value_Enum != highCard)
     {
         Assert.Fail($"Selected high card {highCard} is different from this in set ({set.cardsSet[0].Value_Enum}). \n{GenerateStatistics(cards, set, requiredFigure, currentTest)}");
     }
     else
     {
         TestCorrection(cards, set, requiredFigure, currentTest);
     }
 }
        public static string GenerateStatistics(List <Card> cards, Set set, FIGURE requiredFigure, int currentTest)
        {
            string msg;

            msg = $"Error occoured on test {currentTest}. Passed cards:";
            foreach (var c in cards)
            {
                msg += $" {c.Value}{c.Color} ";
            }
            msg += $"Detected figure: {set.Figure} Cards on figure set: ";
            foreach (var c in set.cardsSet)
            {
                msg += $" {c.Value}{c.Color} ";
            }
            return(msg);
        }
Пример #5
0
        /**
         * @brief Document 클래스의 생성자이다.
         * @details View를 하나 생성하고 View의 parent로 입력받은 폼을 설정한다. 생성한 View를 viewList에 저장하고 툴, 색상, 다중선택 여부를 초기화한다.
         * @param parent View의 부모폼으로 설정될 폼
         */
        public Document(Form parent)
        {
            View child = new View(parent, this);

            viewList.Add(child);
            child.Show();
            isMultSel    = false;
            currentTool  = FIGURE.ARROW;
            currentColor = Color.Black;


            /**
             * @brief   : Default 배경 설정. 흰색에 옵션 1으로 설정
             * @author  : 장한결([email protected])
             * @date    : 2019-05-11
             */
            bgOption = 2;
            this.bgReset();
        }
Пример #6
0
        private void InsertBestCardsToList(FIGURE figure)
        {
            if (cardsSet.Count >= 5)
            {
                var dynamicList = new List <Card>();
                switch (figure)
                {
                case FIGURE.HIGH_CARD:
                {
                    for (int i = 0; i < 5; i++)
                    {
                        dynamicList.Add(cardsSet[i]);
                    }
                    break;
                }

                case FIGURE.PAIR:
                {
                    for (int i = 0; i < cardsSet.Count - 1; i++)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum)
                        {
                            dynamicList.Add(cardsSet[i]);
                            dynamicList.Add(cardsSet[i + 1]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            break;
                        }
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        dynamicList.Add(cardsSet[i]);
                    }
                    break;
                }

                case FIGURE.TWO_PAIRS:
                {
                    for (int x = 0; x < 2; x++)
                    {
                        for (int i = 0; i < cardsSet.Count - 1; i++)
                        {
                            if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum)
                            {
                                dynamicList.Add(cardsSet[i]);
                                dynamicList.Add(cardsSet[i + 1]);
                                cardsSet.Remove(cardsSet[i]);
                                cardsSet.Remove(cardsSet[i]);
                                break;
                            }
                        }
                    }
                    dynamicList.Add(cardsSet[0]);
                    break;
                }

                case FIGURE.THREE_OF_A_KIND:
                {
                    for (int i = 0; i < cardsSet.Count - 2; i++)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum &&
                            cardsSet[i + 1].Value_Enum == cardsSet[i + 2].Value_Enum)
                        {
                            dynamicList.Add(cardsSet[i]);
                            dynamicList.Add(cardsSet[i + 1]);
                            dynamicList.Add(cardsSet[i + 2]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            break;
                        }
                    }
                    for (int i = 0; i < 2; i++)
                    {
                        dynamicList.Add(cardsSet[i]);
                    }
                    break;
                }

                case FIGURE.FOUR_OF_A_KIND:
                {
                    for (int i = 0; i < cardsSet.Count - 3; i++)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum &&
                            cardsSet[i + 1].Value_Enum == cardsSet[i + 2].Value_Enum &&
                            cardsSet[i + 2].Value_Enum == cardsSet[i + 3].Value_Enum)
                        {
                            dynamicList.Add(cardsSet[i]);
                            dynamicList.Add(cardsSet[i + 1]);
                            dynamicList.Add(cardsSet[i + 2]);
                            dynamicList.Add(cardsSet[i + 3]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            break;
                        }
                    }
                    dynamicList.Add(cardsSet[0]);
                    break;
                }

                case FIGURE.FULL:
                {
                    for (int i = 0; i < cardsSet.Count - 2; i++)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum &&
                            cardsSet[i + 1].Value_Enum == cardsSet[i + 2].Value_Enum)
                        {
                            dynamicList.Add(cardsSet[i]);
                            dynamicList.Add(cardsSet[i + 1]);
                            dynamicList.Add(cardsSet[i + 2]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            break;
                        }
                    }
                    for (int i = 0; i < cardsSet.Count - 1; i++)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum)
                        {
                            dynamicList.Add(cardsSet[i]);
                            dynamicList.Add(cardsSet[i + 1]);
                            cardsSet.Remove(cardsSet[i]);
                            cardsSet.Remove(cardsSet[i]);
                            break;
                        }
                    }
                    break;
                }

                case FIGURE.FLUSH:
                {
                    List <Card>[] cards = new List <Card>[]
                    {
                        new List <Card>(),
                        new List <Card>(),
                        new List <Card>(),
                        new List <Card>()
                    };

                    for (int i = 0; i < cardsSet.Count; i++)
                    {
                        switch (cardsSet[i].Color)
                        {
                        case CARD.HEARTS: cards[0].Add(cardsSet[i]); break;

                        case CARD.DIAMONDS: cards[1].Add(cardsSet[i]); break;

                        case CARD.SPADES: cards[2].Add(cardsSet[i]); break;

                        case CARD.CLUBS: cards[3].Add(cardsSet[i]); break;
                        }
                    }
                    foreach (var x in cards)
                    {
                        if (x.Count >= 5)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                dynamicList.Add(x[i]);
                            }
                            break;
                        }
                    }
                    break;
                }

                case FIGURE.STRAIGHT:
                {
                    for (int i = 0; i < cardsSet.Count - 4; i++)
                    {
                        if (cardsSet.Count >= 5 && IsStraight(cardsSet, out dynamicList))
                        {
                            break;
                        }

                        /*for (int j = i; j < i + 4; j++)
                         * {
                         *  if (cardsSet[j].Value_Enum == cardsSet[j + 1].Value_Enum + 1)
                         *  {
                         *      if (!dynamicList.Contains(cardsSet[j])) dynamicList.Add(cardsSet[j]);
                         *      if (!dynamicList.Contains(cardsSet[j + 1])) dynamicList.Add(cardsSet[j + 1]);
                         *  }
                         *  else if (j == i &&
                         *      (cardsSet[0].Value_Enum == VALUE._A && CollectionContainsCardWithValue(cardsSet.ToArray(), VALUE._5) && cardsSet[cardsSet.Count - 1].Value_Enum == VALUE._2))
                         *  {
                         *      if (!dynamicList.Contains(cardsSet[j])) dynamicList.Add(cardsSet[j]);
                         *      if (!dynamicList.Contains(cardsSet[0])) dynamicList.Add(cardsSet[0]);
                         *  }
                         *
                         *  else dynamicList.Clear();
                         *
                         *
                         * }*/
                        //if (dynamicList.Count == 5) break;
                    }

                    break;
                }

                case FIGURE.POKER:
                {
                    for (int i = 0; i < cardsSet.Count - 4; i++)
                    {
                        List <Card>[] cards = new List <Card>[]
                        {
                            new List <Card>(),
                            new List <Card>(),
                            new List <Card>(),
                            new List <Card>()
                        };
                        for (int x = 0; x < i + 5; x++)
                        {
                            if (cardsSet[x].Color == CARD.HEARTS)
                            {
                                cards[0].Add(cardsSet[x]);
                            }
                            else if (cardsSet[x].Color == CARD.DIAMONDS)
                            {
                                cards[1].Add(cardsSet[x]);
                            }
                            else if (cardsSet[x].Color == CARD.CLUBS)
                            {
                                cards[2].Add(cardsSet[x]);
                            }
                            else if (cardsSet[x].Color == CARD.SPADES)
                            {
                                cards[3].Add(cardsSet[x]);
                            }
                        }


                        foreach (var internalCardSet in cards)
                        {
                            if (internalCardSet.Count >= 5 && IsStraight(internalCardSet, out dynamicList))
                            {
                            }

                            /*for (int x = 0; x < internalCardSet.Count - 4; x++)
                             * {
                             *  for (int j = x; j < x + 4; j++)
                             *  {
                             *      if (internalCardSet[j].Value_Enum == internalCardSet[j + 1].Value_Enum + 1)
                             *      {
                             *          if (!dynamicList.Contains(internalCardSet[j])) dynamicList.Add(internalCardSet[j]);
                             *          if (!dynamicList.Contains(internalCardSet[j + 1])) dynamicList.Add(internalCardSet[j + 1]);
                             *      }
                             *      else if (j == x &&
                             *          (cardsSet[0].Value_Enum == VALUE._A && CollectionContainsCardWithValue(cardsSet.ToArray(), VALUE._5) && cardsSet[cardsSet.Count - 1].Value_Enum == VALUE._2))
                             *      {
                             *          if (!dynamicList.Contains(internalCardSet[j])) dynamicList.Add(internalCardSet[j]);
                             *          if (!dynamicList.Contains(internalCardSet[0])) dynamicList.Add(internalCardSet[0]);
                             *      }
                             *
                             *      else
                             *      {
                             *          dynamicList.Clear();
                             *          break;
                             *      }
                             *  }
                             * }*/
                        }
                        if (dynamicList.Count == 5)
                        {
                            break;
                        }
                    }


                    break;
                }

                case FIGURE.ROYAL_POKER:
                {
                    List <Card>[] cards = new List <Card>[]
                    {
                        new List <Card>(),
                        new List <Card>(),
                        new List <Card>(),
                        new List <Card>()
                    };

                    for (int x = 0; x < cardsSet.Count; x++)
                    {
                        if (cardsSet[x].Color == CARD.HEARTS)
                        {
                            cards[0].Add(cardsSet[x]);
                        }
                        else if (cardsSet[x].Color == CARD.DIAMONDS)
                        {
                            cards[0].Add(cardsSet[x]);
                        }
                        else if (cardsSet[x].Color == CARD.CLUBS)
                        {
                            cards[0].Add(cardsSet[x]);
                        }
                        else if (cardsSet[x].Color == CARD.SPADES)
                        {
                            cards[0].Add(cardsSet[x]);
                        }
                    }

                    foreach (var a in cards)
                    {
                        if (a.Count >= 5)
                        {
                            for (int b = 0; b < 5; b++)
                            {
                                dynamicList.Add(a[b]);
                            }
                        }
                    }
                    break;
                }
                }

                try
                {
                    if ((Figure == FIGURE.STRAIGHT ||
                         Figure == FIGURE.POKER)
                        &&
                        (dynamicList[0].Value_Enum == VALUE._A &&
                         dynamicList[4].Value_Enum == VALUE._2))
                    {
                        var templist = new List <Card>(dynamicList);
                        for (int a = 0; a < 4; a++)
                        {
                            dynamicList[a] = templist[a + 1];
                        }
                        dynamicList[4] = templist[0];
                    }
                }
                catch (ArgumentOutOfRangeException aoorex)
                {
                    Console.WriteLine(aoorex.Message);
                }

                cardsSet = new List <Card>(dynamicList);
            }
        }
Пример #7
0
        private void CalculateFigure()
        {
            List <FIGURE> detectedFigures = new List <FIGURE>()
            {
                FIGURE.HIGH_CARD
            };

            for (int i = 0; i < cardsSet.Count - 1; i++)
            {
                if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum)
                {
                    detectedFigures.Add(FIGURE.PAIR);
                    break;
                }
            }
            if (detectedFigures.Contains(FIGURE.PAIR))
            {
                VALUE pairValue         = VALUE._2;
                bool  firstPairDetected = false;
                for (int i = 0; i < cardsSet.Count - 1; i++)
                {
                    if (firstPairDetected)
                    {
                        if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum && cardsSet[i + 1].Value_Enum == pairValue)
                        {
                            if (detectedFigures.Contains(FIGURE.THREE_OF_A_KIND))
                            {
                                detectedFigures.Add(FIGURE.FOUR_OF_A_KIND);
                            }
                            detectedFigures.Add(FIGURE.THREE_OF_A_KIND);
                        }
                        else if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum && cardsSet[i + 1].Value_Enum != pairValue)
                        {
                            detectedFigures.Add(FIGURE.TWO_PAIRS);
                            pairValue = cardsSet[i].Value_Enum;
                        }
                    }
                    else if (cardsSet[i].Value_Enum == cardsSet[i + 1].Value_Enum && !firstPairDetected)
                    {
                        pairValue         = cardsSet[i].Value_Enum;
                        firstPairDetected = true;
                    }
                }
                if (detectedFigures.Contains(FIGURE.THREE_OF_A_KIND) &&
                    detectedFigures.Contains(FIGURE.TWO_PAIRS))
                {
                    detectedFigures.Add(FIGURE.FULL);
                }
                else if (detectedFigures.Contains(FIGURE.TWO_PAIRS))
                {
                    detectedFigures.Add(FIGURE.TWO_PAIRS);
                }
            }


            bool straight = false;

            for (int i = 0; i < cardsSet.Count - 4; i++)
            {
                for (int j = i; j < i + 4; j++)
                {
                    if (cardsSet[j].Value_Enum == cardsSet[j + 1].Value_Enum + 1)
                    {
                        straight = true;
                    }
                    else if (j == i &&
                             (cardsSet[0].Value_Enum == VALUE._A && CollectionContainsCardWithValue(cardsSet.ToArray(), VALUE._5) && cardsSet[cardsSet.Count - 1].Value_Enum == VALUE._2))
                    {
                        straight = true;
                    }
                    else
                    {
                        straight = false;
                        break;
                    }
                }
                if (straight)
                {
                    detectedFigures.Add(FIGURE.STRAIGHT);
                    break;
                }
            }
            if (straight)
            {
                List <Card>[] cards = new List <Card>[]
                {
                    new List <Card>(),
                    new List <Card>(),
                    new List <Card>(),
                    new List <Card>()
                };

                for (int x = 0; x < cardsSet.Count; x++)
                {
                    if (cardsSet[x].Color == CARD.HEARTS)
                    {
                        cards[0].Add(cardsSet[x]);
                    }
                    else if (cardsSet[x].Color == CARD.DIAMONDS)
                    {
                        cards[1].Add(cardsSet[x]);
                    }
                    else if (cardsSet[x].Color == CARD.CLUBS)
                    {
                        cards[2].Add(cardsSet[x]);
                    }
                    else if (cardsSet[x].Color == CARD.SPADES)
                    {
                        cards[3].Add(cardsSet[x]);
                    }
                }


                foreach (var l in cards)
                {
                    if (l.Count >= 5)
                    {
                        for (int e = 0; e < l.Count - 4; e++)
                        {
                            for (int j = e; j < e + 4; j++)
                            {
                                if (l[j].Value_Enum == l[j + 1].Value_Enum + 1)
                                {
                                    straight = true;
                                }
                                else if (j == e &&
                                         (l[0].Value_Enum == VALUE._A && CollectionContainsCardWithValue(l.ToArray(), VALUE._5) && l[l.Count - 1].Value_Enum == VALUE._2))
                                {
                                    straight = true;
                                }
                                else
                                {
                                    straight = false;
                                    break;
                                }
                            }
                            if (straight)
                            {
                                detectedFigures.Add(FIGURE.POKER);
                                break;
                            }
                        }
                        straight = false;
                        if (l[0].Value_Enum == VALUE._A)
                        {
                            for (int e = 0; e < 4; e++)
                            {
                                if (l[e].Value_Enum == l[e + 1].Value_Enum + 1)
                                {
                                    straight = true;
                                }
                                else
                                {
                                    straight = false;
                                    break;
                                }
                            }
                            if (straight)
                            {
                                detectedFigures.Add(FIGURE.ROYAL_POKER);
                            }
                        }
                    }
                }
            }
            List <Card>[] flushCards = new List <Card>[]
            {
                new List <Card>(),
                new List <Card>(),
                new List <Card>(),
                new List <Card>()
            };

            for (int x = 0; x < cardsSet.Count; x++)
            {
                if (cardsSet[x].Color == CARD.HEARTS)
                {
                    flushCards[0].Add(cardsSet[x]);
                }
                else if (cardsSet[x].Color == CARD.DIAMONDS)
                {
                    flushCards[1].Add(cardsSet[x]);
                }
                else if (cardsSet[x].Color == CARD.CLUBS)
                {
                    flushCards[2].Add(cardsSet[x]);
                }
                else if (cardsSet[x].Color == CARD.SPADES)
                {
                    flushCards[3].Add(cardsSet[x]);
                }
            }

            for (int x = 0; x < flushCards.Length; x++)
            {
                if (flushCards[x].Count >= 5)
                {
                    detectedFigures.Add(FIGURE.FLUSH);
                    break;
                }
            }

            detectedFigures.Sort((p, q) => q.CompareTo(p));
            Figure = detectedFigures[0];
            InsertBestCardsToList();
            return;
        }
Пример #8
0
        /**
         * @brief Editor/Animation 탭 버튼 핸들러
         * @author 박성식
         * @date 2016-07-20
         * @param sender 이벤트 발생시킨 객체
         * @param e 마우스 이벤트 관련 argument들
         */
        public void RibbonGeneralHandler(object sender, MouseEventArgs e)
        {
            FIGURE f = FIGURE.ARROW;

            if (sender == ribbonButtonArrow)
            {
                f = FIGURE.ARROW;
            }
            else if (sender == ribbonButtonLine)
            {
                f = FIGURE.LINE;
            }
            else if (sender == ribbonButtonFreeLine)
            {
                f = FIGURE.FREELINE;
            }
            else if (sender == ribbonButtonCircle)
            {
                f = FIGURE.OVAL;
            }
            else if (sender == ribbonButtonRect)
            {
                f = FIGURE.RECT;
            }
            //else if (sender == toolStrip2Text)
            //    f = FIGURE.TEXT;
            else if (sender == ribbonButtonErase)
            {
                f = FIGURE.ERASE;
            }
            else if (sender == ribbonButtonBox)
            {
                f = FIGURE.BOX;
            }
            else if (sender == ribbonButtonFill)
            {
                f = FIGURE.FILL;
            }
            else if (sender == ribbonButtonCopy)
            {
                GetActiveDocument().copy();
            }
            else if (sender == ribbonButtonCut)
            {
                GetActiveDocument().cut();
            }
            else if (sender == ribbonButtonPaste)
            {
                GetActiveDocument().paste();
            }
            else if (sender == ribbonButtonMerge)
            {
                GetActiveDocument().mergeFigure();
                GetActiveDocument().UpdateAllViews();
            }
            else if (sender == ribbonButtonUnmerge)
            {
                GetActiveDocument().unmergeFigure();
                GetActiveDocument().UpdateAllViews();
            }
            //새로 추가된 4 버튼 핸들러입니다. 수정하시면 됩니다.
            else if (sender == ribbonButtonZoomIn)
            {
                MessageBox.Show("줌인");
            }
            else if (sender == ribbonButtonZoomOut)
            {
                MessageBox.Show("줌아웃");
            }
            else if (sender == ribbonButtonOriginal)
            {
                MessageBox.Show("원래대로");
            }
            else if (sender == ribbonButtonHand)
            {
                MessageBox.Show("손");
            }
            GetActiveDocument().deselectAll();
            GetActiveDocument().setCurrentTool(f);
        }