public Point CulcStartPoint(PlacedWord placedWord, CrossPointInfo info, PlaceDirection direction, Word word)
        {
            Point pointToPlace = new Point();

            Point crossPoint = new Point();

            switch (placedWord.PlaceDirection)
            {
                case PlaceDirection.Horisontal:
                    {
                        crossPoint.X = placedWord.StartPoint.X + info.GetThisCross(placedWord.Word.Number);
                        crossPoint.Y = placedWord.StartPoint.Y;
                        break;
                    }
                case PlaceDirection.Vertiacal:
                    {
                        crossPoint.X = placedWord.StartPoint.X;
                        crossPoint.Y = placedWord.StartPoint.Y + info.GetThisCross(placedWord.Word.Number);
                        break;
                    }
            }

            switch (direction)
            {
                case PlaceDirection.Horisontal:
                    {
                        pointToPlace.X = crossPoint.X - info.GetThisCross(word.Number);
                        pointToPlace.Y = crossPoint.Y;
                        break;
                    }
                case PlaceDirection.Vertiacal:
                    {
                        pointToPlace.X = crossPoint.X;
                        pointToPlace.Y = crossPoint.Y - info.GetThisCross(word.Number);
                        break;
                    }
            }
            return pointToPlace;
        }
Beispiel #2
0
        public static List<Word> Swap(int keya, int keyb, List<Word> words)
        {
            var t = new Word(words.FirstOrDefault(x => x.Number == keya).Number, words.FirstOrDefault(x => x.Number == keya).Text) ;
            Word b = words.FirstOrDefault(x => x.Number == keyb);

            var a = words.FirstOrDefault(x => x.Number == keya);

            a.Text = b.Text;
            a.Number = b.Number;

            b.Text = t.Text;
            b.Number = t.Number;

            return words;
        }
Beispiel #3
0
 public static List<CrossPointInfo> GetCrossInfo(Word word1, Word word2)
 {
     var result = new List<CrossPointInfo>();
     for (int i = 0; i < word1.Text.Length; i++)
     {
         var w1 = word1.Text[i];
         for (int index = 0; index < word2.Text.Length; index++)
         {
             char w2 = word2.Text[index];
             if (w1 == w2)
             {
                 var info = new CrossPointInfo()
                 {
                     Letter = w1,
                     W1Pos = i,
                     W2Pos = index,
                     Word1Number = word1.Number,
                     Word2Number = word2.Number,
                 };
                 result.Add(info);
             }
         }
     }
     return result;
 }
        public void InsertWord(Word word, PlaceDirection direction, Point startPoint)
        {
            var item = new PlacedWord
            {
                Word = word,
                StartPoint = startPoint,
                PlaceDirection = direction
            };

            switch (item.PlaceDirection)
            {

                case PlaceDirection.Horisontal:
                    {
                        InsertWordHorisontal(word, item.StartPoint);
                        break;
                    }
                case PlaceDirection.Vertiacal:
                    {
                        InsertWordVertical(word, item.StartPoint);
                        break;
                    }
            }

            PlacedWords.Push(item);
        }
 private void InsertWordVertical(Word word, Point point)
 {
     for (int index = 0; index < word.Text.Length; index++)
     {
         var c = word.Text[index];
         InternalMatrix[point.X, point.Y + index].Symbol = c;
         InternalMatrix[point.X, point.Y + index].PlacedCount++;
     }
 }
        public List<Cross> CrossPositions(Word word)
        {
            bool result = false;

            bool pointToInsertExist = false;

            var avalible = new List< Cross>();

            for (int i = 0; i < DimX; i++)
            {
                for (int j = 0; j < DimY; j++)
                {

                    foreach (var c in word.Text)
                    {
                        if (c == InternalMatrix[i, j].Symbol && InternalMatrix[i, j].PlacedCount <= 1)
                        {
                            pointToInsertExist = true;
                            avalible.Add(new Cross()
                            {
                                Point = new Point(i, j) ,
                                Symbol = c
                            });
                        }
                    }
                }
            }
            
            return avalible;
        }
        public CanPlace CanPlaceToCrossPos(Cross crossPos, Word word)
        {
            Point shitTop = new Point(crossPos.Point.X, crossPos.Point.Y - word.Text.IndexOf(crossPos.Symbol));
            Point shitLeft = new Point(crossPos.Point.X- word.Text.IndexOf(crossPos.Symbol), crossPos.Point.Y );

            var canTop = true;
            var canLeft = true;

            var topCrossingCount = 0;
            var leftCrossingCount = 0;

            // try top
            for (int index = 0; index < word.Text.Length; index++)
            {
                var c = word.Text[index];
                var internalChar = InternalMatrix[shitTop.X , shitTop.Y + index];

                if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c))
                {
                    if (internalChar.Symbol == c)
                    {
                        topCrossingCount++;
                    }
                    if (topCrossingCount > 1)
                    {
                        canTop = false;
                        break;
                    }

                    continue;
                }
                else
                {
                    canTop = false;
                    break;
                }
            }

            for (int index = 0; index < word.Text.Length; index++)
            {
                var c = word.Text[index];
                var internalChar = InternalMatrix[shitLeft.X + index, shitLeft.Y];

                if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c))
                {
                    if (internalChar.Symbol == c)
                    {
                        leftCrossingCount++;
                    }
                    if (leftCrossingCount > 1)
                    {
                        canLeft = false;
                        break;
                    }
                    continue;
                }
                else
                {
                    canLeft = false;
                    break;
                }
            }
            return new CanPlace() {CanLeft = canLeft, CanTop = canTop, LeftStart = shitLeft,TopStart = shitTop};
        }
 public void InsertWord(CanPlace place, Word word)
 {
     if (place.CanTop)
     {
         InsertWord(word, PlaceDirection.Vertiacal, place.TopStart);
     }
     if (place.CanLeft)
     {
         InsertWord(word, PlaceDirection.Horisontal, place.LeftStart);
     }
 }
        public bool CanPlaceWord(PlacedWord placedWord, CrossPointInfo info, PlaceDirection direction, Word word)
        {
            var pointToPlace = CulcStartPoint(placedWord, info, direction, word);


            var result = true;
            switch (direction)
            {
                case PlaceDirection.Horisontal:
                    {
                        for (int index = 0; index < word.Text.Length; index++)
                        {
                            var c = word.Text[index];
                            var internalChar = InternalMatrix[pointToPlace.X + index, pointToPlace.Y];

                            if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c))
                            {
                                continue;
                            }
                            else
                            {
                                result = false;
                            }
                        }
                        break;
                    }

                case PlaceDirection.Vertiacal:
                    {
                        for (int index = 0; index < word.Text.Length; index++)
                        {
                            var c = word.Text[index];
                            var internalChar = InternalMatrix[pointToPlace.X, pointToPlace.Y + index];

                            if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c))
                            {
                                continue;
                            }
                            else
                            {
                                result = false;
                            }
                        }
                        break;

                    }
            }

            return result;
        }