Beispiel #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());
            }
Beispiel #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();
            }
Beispiel #3
0
        internal static PlayPath GetPath(Board board, Rack rack, WordPart part)
        {
            ISet <Cell> excluded             = board.GetExcluded(part);
            ConstantList <LetterPlay> played = part.GetPlayed(excluded);
            var extras         = new List <WordPart>();
            var otherDirection = part.Direction == Direction.Right ? Direction.Down : Direction.Right;
            var pending        = new List <char>(rack.Letters);

            foreach (LetterPlay lp in played)
            {
                var      before = board.GetBeforePart(lp.Cell, otherDirection);
                var      after  = board.GetAfterPart(lp.Cell, otherDirection);
                var      pair   = new WordPartPair(before, after);
                WordPart extra  = pair.Play(lp.Cell, lp.Letter);
                if (extra != null)
                {
                    extras.Add(extra);
                }
                pending.Remove(lp.Letter);
            }
            return(new PlayPath(part, new WordPartCollection(extras.ToConstant()), played, pending.ToConstant()));
        }