Ejemplo n.º 1
0
        private void ExtendRight(DawgNode node, BoardTile boardTile)
        {
            string partialWord = node.Word;

            if (boardTile == null)
            {
                AddWordToValidWordsIfValid(partialWord);
            }
            else if (boardTile.CharTile == null)
            {
                if (boardTile != StartingBoardTile)
                {
                    AddWordToValidWordsIfValid(partialWord);
                }
                foreach (char edge in node.Edges)
                {
                    HashSet <char> boardTileCrossChecks = GetBoardTileCrossChecks(boardTile);
                    if (!PlayerRack.ContainsCharTile(edge) || (boardTileCrossChecks != null && !boardTileCrossChecks.Contains(edge)))
                    {
                        continue;
                    }

                    char      rackChar            = PlayerRack.TakeCharTile(edge);
                    string    partialWordPlusEdge = partialWord + rackChar.ToString();
                    DawgNode  nextNode            = GetDawgNode(partialWordPlusEdge);
                    BoardTile nextBoardTile       = Board.GetBoardTileAtCoordinates(boardTile.X, boardTile.Y + 1);
                    SetBoardTileCrossChecks(nextBoardTile);
                    ExtendRight(nextNode, nextBoardTile);
                    PlayerRack.AddCharTile(rackChar);
                }
            }
            else
            {
                char charOnBoardTile = boardTile.CharTile.Letter;
                if (!node.Edges.Contains(charOnBoardTile))
                {
                    return;
                }

                string    partialWordPlusEdge = partialWord + charOnBoardTile.ToString();
                DawgNode  nextNode            = GetDawgNode(partialWordPlusEdge);
                BoardTile nextBoardTile       = Board.GetBoardTileAtCoordinates(boardTile.X, boardTile.Y + 1);
                SetBoardTileCrossChecks(nextBoardTile);
                ExtendRight(nextNode, nextBoardTile);
            }
        }
Ejemplo n.º 2
0
        private void LeftPart(DawgNode node, int limit, BoardTile anchor)
        {
            ExtendRight(node, anchor);
            if (LeftPartIsAlreadyProvided || limit <= 0)
            {
                return;
            }
            foreach (char edge in node.Edges)
            {
                if (!PlayerRack.ContainsCharTile(edge))
                {
                    continue;
                }

                char     rackChar            = PlayerRack.TakeCharTile(edge);
                string   partialWord         = node.Word;
                string   partialWordPlusEdge = partialWord + rackChar.ToString();
                DawgNode nextNode            = GetDawgNode(partialWordPlusEdge);
                LeftPart(nextNode, limit - 1, anchor);
                PlayerRack.AddCharTile(rackChar);
            }
        }
Ejemplo n.º 3
0
        public List <BoardWord> GetPossibleMoves(BoardTile anchor, IPlayerRack playerRack)
        {
            ValidWords                    = new List <BoardWord>();
            PlayerRack                    = playerRack;
            StartingBoardTile             = anchor;
            BoardTilesAndTheirCrossChecks = new Dictionary <BoardTile, HashSet <char> >();

            HorizontalBoardWord wordToTheLeftOfAnchor = BoardWordRetriever.GetHorizontalWordTilesAtCoordinates(StartingBoardTile.X, StartingBoardTile.Y - 1);
            string partialWord = wordToTheLeftOfAnchor?.GetWord() ?? "";

            LeftPartIsAlreadyProvided = partialWord.Length > 0;

            BoardTilesAndTheirCrossChecks.Add(StartingBoardTile, BoardCrossCheckCollector.GetCrossChecksForBoardTile(StartingBoardTile));

            BoardAnchorCollector boardAnchorCollector = new();
            BoardTileCollection  boardAnchors         = boardAnchorCollector.GetAnchors(Board);

            DawgNode node = GetDawgNode(partialWord);
            BoardNonAnchorTileCounter boardNonAnchorTileCounter = new(Board);
            int limit = boardNonAnchorTileCounter.GetNumberOfNonAnchorTilesToTheLeftOfABoardTile(StartingBoardTile, boardAnchors);

            LeftPart(node, limit, anchor);
            return(ValidWords);
        }