Esempio n. 1
0
        public static string PrintBoard(Board board)
        {
            BoardAnchorCollector boardAnchorCollector = new();
            BoardTileCollection  anchors = boardAnchorCollector.GetAnchors(board);
            StringBuilder        sb      = new(PrintBoard_Delimiter);

            foreach (BoardTile[] rows in board.Tiles)
            {
                if (sb.Length != 0)
                {
                    sb.Append('\n');
                }
                foreach (BoardTile tile in rows)
                {
                    sb.Append(anchors.Contains(tile) ? "[=]" : $"[{tile.PrintChar()}]");
                }
            }
            sb.Append('\n');
            sb.Append(PrintBoard_Delimiter);
            return(sb.ToString());
        }
        public Dictionary <BoardTile, HashSet <char> > GetCrossChecksForBoardTiles(BoardTileCollection boardTileCollection)
        {
            BoardWordRetriever boardWordRetriever = new(Board);

            char[]         charsFromAlphabet        = DawgWithAlphabet.GetAlphabet();
            HashSet <char> charsFromAlphabetHashSet = charsFromAlphabet.ToHashSet();

            Dictionary <BoardTile, HashSet <char> > tilesAndTheirCrossChecks = new();

            foreach (BoardTile boardTile in boardTileCollection)
            {
                if (boardTile.CharTile != null)
                {
                    continue;
                }

                tilesAndTheirCrossChecks.Add(boardTile, new HashSet <char>());

                BoardTileVerticalWordConnectionChecker verticallityChecker = new(Board);
                if (!verticallityChecker.BoardTileIsVerticallyPartOfAWord(boardTile.X, boardTile.Y))
                {
                    tilesAndTheirCrossChecks[boardTile] = charsFromAlphabetHashSet;
                    continue;
                }

                foreach (char ch in charsFromAlphabet)
                {
                    Board.PlaceCharTile(boardTile.X, boardTile.Y, ch);
                    VerticalBoardWord verticalWord = boardWordRetriever.GetVerticalWordTilesAtCoordinates(boardTile.X, boardTile.Y);
                    if (DawgWithAlphabet.IsWordValid(verticalWord.GetWord()))
                    {
                        tilesAndTheirCrossChecks[boardTile].Add(ch);
                    }
                    Board.RemoveCharTile(boardTile.X, boardTile.Y);
                }
            }
            return(tilesAndTheirCrossChecks);
        }
Esempio 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);
        }
        public int GetNumberOfNonAnchorTilesToTheLeftOfABoardTile(BoardTile boardTile, BoardTileCollection boardAnchors)
        {
            int count      = 0;
            int boardTileY = boardTile.Y;

            while (boardTileY > 0)
            {
                BoardTile boardTileToTheLeft = Board.GetBoardTileAtCoordinates(boardTile.X, boardTileY - 1);
                if (boardTileToTheLeft == null || boardAnchors.Contains(boardTileToTheLeft))
                {
                    break;
                }
                count++;
                boardTileY--;
            }
            return(count);
        }