Exemple #1
0
            public CtorHelper(WordGraph graph, Board board, Rack rack)
            {
                this.graph = graph;
                this.board = board;
                var validMap = new Dictionary <WordPart, PlayPath>();
                var cells    = board.GetStartCells();
                var done     = new HashSet <WordPart>();

                foreach (Cell cell in cells)
                {
                    foreach (Direction direction in new[] { Direction.Down, Direction.Right })
                    {
                        var          otherDirection = direction == Direction.Down ? Direction.Right : Direction.Down;
                        var          playable       = new PlayableLetters(rack.Letters);
                        WordPartPair extraPair      = GetBeforeAfter(board, cell, otherDirection, graph, playable);
                        WordPartPair mainPair       = GetBeforeAfter(board, cell, direction, graph, playable);
                        if (playable.Count == 0)
                        {
                            continue;
                        }
                        foreach (char letter in playable)
                        {
                            WordPart mainPart  = mainPair.Play(cell, letter) ?? new WordPart(letter.ToString(), cell, direction);
                            WordPart extraPart = extraPair.Play(cell, letter);
                            if (extraPart != null && !graph.IsValid(extraPart.Word))
                            {
                                continue;
                            }
                            var played  = new LetterPlay(cell, letter);
                            var pending = new List <char>(rack.Letters);
                            pending.Remove(letter);
                            bool valid = mainPart.Word.Length == 1 || graph.IsValid(mainPart.Word);
                            var  path  = GetPath(mainPart, extraPart, played, pending.ToConstant());
                            if (valid && !validMap.ContainsKey(mainPart))
                            {
                                validMap.Add(mainPart, path);
                            }

                            var min = new Dictionary <Direction, HashSet <int> >();
                            min.Add(Direction.Down, new HashSet <int>());
                            min.Add(Direction.Right, new HashSet <int>());
                            var max = new Dictionary <Direction, HashSet <int> >();
                            max.Add(Direction.Down, new HashSet <int>());
                            max.Add(Direction.Right, new HashSet <int>());

                            GetNewPaths(graph, board, path, path, done, validMap, true, min, max);
                        }
                    }
                }
                valids = new ConstantList <PlayPath>(validMap.Values.ToList());
            }
Exemple #2
0
            public Choices(WordGraph graph, Board board, PlayPath path, Fix fix, Cell cell)
            {
                this.fix  = fix;
                this.cell = cell;
                Direction direction      = path.Main.Direction;
                var       otherDirection = direction == Direction.Down ? Direction.Right : Direction.Down;
                var       playable       = new PlayableLetters(path.Pending);
                WordPart  before         = fix == Fix.Suffix ? path.Main : null;
                WordPart  after          = fix == Fix.Prefix ? path.Main : null;

                main    = GetBeforeAfter(board, cell, direction, graph, playable, before, after);
                extra   = GetBeforeAfter(board, cell, otherDirection, graph, playable);
                letters = playable.Choices.ToConstant();
            }
Exemple #3
0
 private static WordPartPair GetBeforeAfter(Board board, Cell cell, Direction direction, WordGraph graph, PlayableLetters choices, WordPart before = null, WordPart after = null)
 {
     before = before ?? board.GetBeforePart(cell, direction);
     after  = after ?? board.GetAfterPart(cell, direction);
     if (before != null && graph.Contains(before.Word))
     {
         choices.IntersectWith(graph.GetLetters(before.Word, Fix.Suffix));
     }
     if (after != null && graph.Contains(after.Word))
     {
         choices.IntersectWith(graph.GetLetters(after.Word, Fix.Prefix));
     }
     return(new WordPartPair(before, after));
 }