public BoardController(BoardLettersModel boardModel, Letters letterGridControl)
        {
            BoardModel        = boardModel;
            LetterGridControl = letterGridControl;

            letterControls = new CustomTextBox[boardModel.GridSizeX, boardModel.GridSizeY];

            LetterGridControl.SetTableSize(boardModel.GridSizeX, boardModel.GridSizeY);

            //Set up textboxes and letter array
            for (int r = 0; r < boardModel.GridSizeX; r++)
            {
                for (int c = 0; c < boardModel.GridSizeY; c++)
                {
                    CustomTextBox newTextBox = new CustomTextBox();
                    letterControls[r, c] = newTextBox;
                    LetterGridControl.Add(newTextBox, c, r);
                    newTextBox.Dock            = DockStyle.Fill;
                    newTextBox.MaxLength       = 1;
                    newTextBox.TextAlign       = HorizontalAlignment.Center;
                    newTextBox.TextChanged    += NewTextBox_TextChanged;
                    newTextBox.Enter          += NewTextBox_Enter;
                    newTextBox.PreviewKeyDown += NewTextBox_PreviewKeyDown;
                    newTextBox.Changed        += NewTextBox_Changed;
                }
            }
        }
Exemple #2
0
 public RightDownSubstituteDirectionStrategy(BoardLettersModel substitutionLetterBoard)
 {
     Directions = new List <Direction>();
     Directions.Add(new Direction(1, 0));   //E
     Directions.Add(new Direction(0, 1));   //S
     this.substitutionLetterBoard = substitutionLetterBoard;
 }
Exemple #3
0
        public Form3()
        {
            InitializeComponent();

            wordList = new WordList()
            {
                MinWordLength = minWordLength, MaxWordLength = maxWordLength
            };

            boardModel      = new BoardLettersModel(gridSizeX, gridSizeY);
            boardController = new BoardController(boardModel, lettersGrid);

            subBoardModel      = new BoardLettersModel(3, 3);
            subBoardController = new BoardController(subBoardModel, letters1);

            boardSaver = new BoardSaver(new BoardLettersModel[] { boardModel, subBoardModel });

            wordFinder = new WordFinder(boardModel, wordList,
                                        new RightDownSubstituteDirectionStrategy(subBoardModel),
                                        new IntersectingNeighborValidationStrategy(wordList))
            {
                WordMustEndWithSpace      = true,
                WordMustHaveSubstitutions = true,
            };

            lettersGrid.TextChanged += LettersGrid_TextChanged;

            SetBonusTiles();
        }
        public WordFinder(BoardLettersModel boardModel, WordList wordList, WordFindDirectionStrategy directionStrategy, StepValidationStrategy stepValidationStrategy = null)
        {
            this.boardModel             = boardModel;
            this.wordList               = wordList;
            this.directionStrategy      = directionStrategy;
            this.stepValidationStrategy = stepValidationStrategy;

            foundWords     = new List <Word>();
            foundWordsDict = new Dictionary <String, Word>();
        }
Exemple #5
0
        public Form2()
        {
            InitializeComponent();

            wordList = new WordList()
            {
                MinWordLength = minWordLength, MaxWordLength = maxWordLength
            };
            boardModel      = new BoardLettersModel(gridSizeX, gridSizeY);
            boardController = new BoardController(boardModel, lettersGrid);
            wordFinder      = new WordFinder(boardModel, wordList, new AllOtherTilesDirectionStrategy());

            lettersGrid.TextChanged += LettersGrid_TextChanged;
        }
Exemple #6
0
        public override bool Validate(BoardLettersModel boardModel, string prefix, int r, int c, object directionData)
        {
            //Get Intersecting word
            var       data               = (RightDownSubstituteDirectionStrategy.DirectionData)directionData;
            Direction wordDirection      = data.WordDirection;
            Direction intersectDirection = new Direction(wordDirection.ColOffset, wordDirection.RowOffset);
            var       word               = boardModel.ReadWord(r, c, intersectDirection);

            //return true if no intersection with another word.
            if (word.Length <= 1)
            {
                return(true);
            }

            //Validate intersecting word
            return(wordList.Find(word, wholeWord: true));
        }
Exemple #7
0
        private int GetIntersects(BoardLettersModel boardModel, string prefix, int r, int c, Direction wordDirection)
        {
            Direction intersectDirection = new Direction(wordDirection.ColOffset, wordDirection.RowOffset);

            var intersects = 0;

            for (var i = 0; i < prefix.Length; i++)
            {
                var word = boardModel.ReadWord(r, c, intersectDirection);
                if (word.Length > 1)
                {
                    intersects++;
                }
                r -= wordDirection.RowOffset;
                c -= wordDirection.ColOffset;
            }
            return(intersects);
        }
Exemple #8
0
        public override bool ValidateWordEnd(BoardLettersModel boardModel, string prefix, int r, int c, object directionData, bool substitionsMade, bool lettersWithoutSubstitions)
        {
            //next letter must be whitespace or end of board
            //must intersect or neighbor tiles on board somewhere

            //Validate last letter
            var validateResult = Validate(boardModel, prefix, r, c, directionData);

            if (!validateResult)
            {
                return(false);
            }

            //Get direction data
            var       data          = (RightDownSubstituteDirectionStrategy.DirectionData)directionData;
            Direction wordDirection = data.WordDirection;

            //Walk back through word and get intersecting words
            int intersects = GetIntersects(boardModel, prefix, r, c, wordDirection);

            //Count letters in line with word as intersects
            if (lettersWithoutSubstitions)
            {
                intersects += 1;
            }

            //Get next letter after wrod end if any
            r += wordDirection.RowOffset;
            c += wordDirection.ColOffset;
            var wordEndOk = true;

            if (r < boardModel.GridSizeX && c < boardModel.GridSizeY && !char.IsWhiteSpace(boardModel.Letters[r, c]))
            {
                wordEndOk = false;
            }

            return(intersects > 0 && wordEndOk);
        }
 public abstract IEnumerable <WordFindDirectionStrategyResult> GetStartingDirections(BoardLettersModel board);
 public abstract IEnumerable <WordFindDirectionStrategyResult> GetNextDirections(int r, int c, BoardLettersModel board, History history, object directionData);
Exemple #11
0
        public override IEnumerable <WordFindDirectionStrategyResult> GetStartingDirections(BoardLettersModel board)
        {
            Substitutions = substitutionLetterBoard.GetAllLetters().ToList();

            //Start words going Right and Down from each position on the board
            for (int r = 0; r < board.GridSizeX; r++)
            {
                for (int c = 0; c < board.GridSizeY; c++)
                {
                    foreach (var direction in Directions)
                    {
                        //check the previous cell is whitespace or edge of board
                        var previousR  = r - direction.RowOffset;
                        var previousC  = c - direction.ColOffset;
                        var previousOK = previousR < 0 || previousC < 0 || Char.IsWhiteSpace(board.Letters[previousR, previousC]);

                        if (previousOK)
                        {
                            if (!Char.IsWhiteSpace(board.Letters[r, c]))
                            {
                                //use the letter on the board
                                yield return(new WordFindDirectionStrategyResult()
                                {
                                    Row = r,
                                    Column = c,
                                    DirectionData = new DirectionData()
                                    {
                                        WordDirection = direction,
                                        SubstitutionLetters = Substitutions.ToList(), //Each new starting point can use all the letters
                                    }
                                });
                            }
                            else
                            {
                                //Nothing on the board. Substitute in all available letters
                                foreach (var subLetter in Substitutions)
                                {
                                    //Create a new dirData with the current substitution letter removed from the candidates
                                    var newDirectionData = new DirectionData()
                                    {
                                        WordDirection       = direction,
                                        SubstitutionLetters = Substitutions.ToList(),
                                    };
                                    newDirectionData.SubstitutionLetters.Remove(subLetter);

                                    yield return(new WordFindDirectionStrategyResult()
                                    {
                                        Row = r,
                                        Column = c,
                                        OverrideLetter = subLetter,
                                        DirectionData = newDirectionData
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #12
0
        public override IEnumerable <WordFindDirectionStrategyResult> GetNextDirections(int r, int c, BoardLettersModel boardModel, History history, object directionData)
        {
            //continue the word in the same direction
            var       dirData = (DirectionData)directionData;
            Direction dir     = dirData.WordDirection;
            int       newRow  = r + dir.RowOffset;
            int       newCol  = c + dir.ColOffset;

            //check we are still on the board
            if (newRow < 0 || newCol < 0 || newRow >= boardModel.GridSizeX || newCol >= boardModel.GridSizeY)
            {
                yield break;
            }

            //Substitute letters if the board has a blank space
            if (!Char.IsWhiteSpace(boardModel.Letters[newRow, newCol]))
            {
                //Use the letter on the board
                yield return(new WordFindDirectionStrategyResult()
                {
                    Row = newRow, Column = newCol, DirectionData = directionData
                });
            }
            else
            {
                //Nothing on the board. Substitute in all available letters
                foreach (var subLetter in dirData.SubstitutionLetters.ToList())
                {
                    //Create a new dirData with the current substitution letter removed from the candidates
                    var newDirectionData = new DirectionData()
                    {
                        WordDirection       = dirData.WordDirection,
                        SubstitutionLetters = dirData.SubstitutionLetters.ToList(),
                    };
                    newDirectionData.SubstitutionLetters.Remove(subLetter);

                    yield return(new WordFindDirectionStrategyResult()
                    {
                        Row = newRow, Column = newCol, OverrideLetter = subLetter, DirectionData = newDirectionData
                    });
                }
            }
        }
        public override IEnumerable <WordFindDirectionStrategyResult> GetNextDirections(int r, int c, BoardLettersModel boardModel, History history, object directionData)
        {
            var results = new List <WordFindDirectionStrategyResult>();

            for (int newRow = 0; newRow < boardModel.GridSizeX; newRow++)
            {
                for (int newCol = 0; newCol < boardModel.GridSizeY; newCol++)
                {
                    if (!history.Contains(newRow, newCol) && boardModel.Letters[newRow, newCol] != ' ')
                    {
                        results.Add(new WordFindDirectionStrategyResult()
                        {
                            Row = newRow, Column = newCol
                        });
                    }
                }
            }
            return(results);
        }
 public override IEnumerable <WordFindDirectionStrategyResult> GetStartingDirections(BoardLettersModel board)
 {
     for (int r = 0; r < board.GridSizeX; r++)
     {
         for (int c = 0; c < board.GridSizeY; c++)
         {
             yield return(new WordFindDirectionStrategyResult()
             {
                 Row = r, Column = c
             });
         }
     }
 }
        public override IEnumerable <WordFindDirectionStrategyResult> GetNextDirections(int r, int c, BoardLettersModel boardModel, History history, object directionData)
        {
            var results = new List <WordFindDirectionStrategyResult>();

            foreach (Direction dir in Directions)
            {
                int newRow = r + dir.RowOffset;
                int newCol = c + dir.ColOffset;
                if (newRow >= 0 && newCol >= 0 && newRow < boardModel.GridSizeX && newCol < boardModel.GridSizeY && !history.Contains(newRow, newCol))
                {
                    results.Add(new WordFindDirectionStrategyResult()
                    {
                        Row = newRow, Column = newCol
                    });
                }
            }
            return(results);
        }