Exemple #1
0
 public void RemoveWord(string word, WordSpace ws)
 {
     wordToSpaceMap.Remove(word);
     spaceToWordMap.Remove(ws.ToString());
     wordsByLength[word.Length].Add(word);
     remainingSpaces[word.Length].Add(ws);
 }
Exemple #2
0
            public bool PlaceWord(string word, WordSpace ws)
            {
                if (IsConflict(word, ws))
                {
                    return(false);
                }

                wordToSpaceMap[word]          = ws;
                spaceToWordMap[ws.ToString()] = word;
                wordsByLength[word.Length].Remove(word);
                remainingSpaces[word.Length].Remove(ws);
                return(true);
            }
Exemple #3
0
        private static Dictionary <int, List <WordSpace> > GetSpaces(string[] rows)
        {
            Dictionary <int, List <WordSpace> > wsbl            = new Dictionary <int, List <WordSpace> >();
            Dictionary <int, HashSet <int> >    remainingPoints = GetAllPoints(rows);

            while (remainingPoints.Count > 0)
            {
                WordSpace firstWordSpace = GetStartWordSpace(rows, remainingPoints);
                if (firstWordSpace == null)
                {
                    break;
                }

                HashSet <string> discovered = new HashSet <string>();
                discovered.Add(firstWordSpace.ToString());
                Queue <WordSpace> toExplore = new Queue <WordSpace>();
                toExplore.Enqueue(firstWordSpace);
                while (toExplore.Count > 0)
                {
                    WordSpace cws = toExplore.Dequeue();
                    RemoveFromRemainingPoints(remainingPoints, cws);

                    if (!wsbl.ContainsKey(cws.length))
                    {
                        wsbl[cws.length] = new List <WordSpace>();
                    }
                    wsbl[cws.length].Add(cws);

                    foreach (WordSpaceIntersection wsi in GetIntersectingWordSpaces(cws, rows))
                    {
                        string wsKey = wsi.ws.ToString();
                        if (!discovered.Contains(wsKey))
                        {
                            discovered.Add(wsKey);
                            toExplore.Enqueue(wsi.ws);
                        }
                    }
                }
            }

            return(wsbl);
        }