Exemple #1
0
        private Object[] pickupWord(List <String> remainingWords)
        {
            KoordinateKata maxCoordinate = null;
            String         theWord       = null;

            foreach (String word in remainingWords)
            {
                List <KoordinateKata> coordinates = getPossibleCoordinates(word);

                if (coordinates.Capacity == 0)
                {
                    continue;
                }

                coordinates.Sort(new WordCoordinateComparator());

                if (maxCoordinate == null || (maxCoordinate.getScore() < coordinates.ElementAt(0).getScore()))
                {
                    maxCoordinate = coordinates.ElementAt(0);
                    theWord       = word;
                }
            }

            return(new Object[] { theWord, maxCoordinate });
        }
Exemple #2
0
        public int generate()
        {
            List <String> remainingWords = new List <String>();

            foreach (String w in kata)
            {
                remainingWords.Add(w);
            }

            String         word = remainingWords.ElementAt(0);
            KoordinateKata koor = new KoordinateKata(0, 0, random.Next(2), 0);

            while (word != null)
            {
                writeWordToGrid(word, koor);
                remainingWords.Remove(word);

                //addToPertanyaan(word, koor);

                Object[] result = pickupWord(remainingWords);
                word = (String)result[0];
                koor = (KoordinateKata)result[1];
            }

            return(kata.Count() - remainingWords.Count());
        }
Exemple #3
0
        private void writeWordToGrid(String word, KoordinateKata coordinate)
        {
            int k = 0;

            for (int i = (coordinate.getDirection() == 0) ? coordinate.getY() : coordinate.getX();
                 i < word.Length + ((coordinate.getDirection() == 0) ? coordinate.getY() : coordinate.getX());
                 i++)
            {
                grid.setValue(coordinate.getDirection() == 0 ? coordinate.getX() : i,
                              coordinate.getDirection() == 0 ? i : coordinate.getY(), word.ElementAt(k++));
            }
        }
Exemple #4
0
 private void addToPertanyaan(String word, KoordinateKata coordinate)
 {
     if (coordinate.getDirection() == 0)
     {
         //List<String> l = (List<String>)Horizontal[coordinate.getX()];
         //if (l == null) l = new List<String>();
         //l.Add(word);
         Horizontal.Add(coordinate.getX(), word);
     }
     else
     {
         //List<String> l = (List<String>)Vertical[coordinate.getY()];
         //if (l == null) l = new List<String>();
         //l.Add(word);
         Vertical.Add(coordinate.getY(), word);
     }
 }
Exemple #5
0
        private int checkScore(String word, KoordinateKata coordinate)
        {
            int row = coordinate.getX();
            int col = coordinate.getY();

            if (col < 0 || row < 0)
            {
                return(0);
            }

            int count = 1;
            int score = 1;

            foreach (char letter in word.ToCharArray())
            {
                if (!isEmpty(row, col) && grid.getValue(row, col) != letter)
                {
                    return(0);
                }

                if (grid.getValue(row, col) == letter)
                {
                    score++;
                }

                if (coordinate.getDirection() == 1)
                {
                    //vertical
                    if (grid.getValue(row, col) != letter && (!isEmpty(row, col + 1) || !isEmpty(row, col - 1)))
                    {
                        return(0);
                    }

                    if (count == 1 && !isEmpty(row - 1, col))
                    {
                        return(0);
                    }

                    if (count == word.Length && !isEmpty(row + 1, col))
                    {
                        return(0);
                    }

                    row++;
                }
                else
                {
                    //Horizontal

                    if (grid.getValue(row, col) != letter && (!isEmpty(row - 1, col) || !isEmpty(row + 1, col)))
                    {
                        return(0);
                    }

                    if (count == 1 && !isEmpty(row, col - 1))
                    {
                        return(0);
                    }

                    if (count == word.Length && !isEmpty(row, col + 1))
                    {
                        return(0);
                    }

                    col++;
                }

                count++;
            }

            return(score);
        }