コード例 #1
0
        public List <Tuple <int, char> > GetExclusionTuples()
        {
            List <Tuple <int, char> > returnList = new List <Tuple <int, char> >();

            string subWordDirection = "";

            if (_placement.IsHorizontal())
            {
                subWordDirection = "vertical";
            }
            else if (_placement.IsVertical())
            {
                subWordDirection = "horizontal";
            }

            for (int i = 0; i < PrimaryWordSpaces.Count; i++)
            {
                //check to see if this letter is an anchor, if so skip
                if (PrimaryWordSpaces[i].IsOccupied())
                {
                    continue;
                }

                foreach (char letter in _tray)
                {
                    bool blankChecked = false;
                    if (letter == '?' && !blankChecked)
                    {
                        blankChecked = true;
                        for (int c = 0; c < 26; c++)
                        {
                            char   newChar = (char)('A' + c);
                            string word    = Game.SingleSubWord(Tuple.Create(PrimaryWordSpaces[i], new Tile(newChar)), subWordDirection).Word;

                            if (!Game.GetDictionary().Contains(word))
                            {
                                returnList.Add(Tuple.Create(i, newChar));
                            }
                        }
                    }
                    else
                    {
                        string word = Game.SingleSubWord(Tuple.Create(PrimaryWordSpaces[i], new Tile(letter)), subWordDirection).Word;
                        if (!Game.GetDictionary().Contains(word))
                        {
                            returnList.Add(Tuple.Create(i, letter));
                        }
                    }
                }
            }

            return(returnList);
        }
コード例 #2
0
ファイル: Play.cs プロジェクト: dmdiehr/Scrabble
        //METHODS

        public List <SubWord> GetSubWords()
        {
            SubWord[] subwords = new SubWord[_playList.Count + 1];

            //Single tile placements are a special case
            //Essentially, single tile placements have no primary SubWord
            //And instead have two secondary words. Or at least that's how I'll approach them.
            if (_placement.IsSingle())
            {
                //Get Horizontal SubWord
                SubWord horizontal = _game.SingleSubWord(_playList[0], "horizontal");

                //Get Vertical SubWord
                SubWord vertical = _game.SingleSubWord(_playList[0], "vertical");

                //return subwords
                if (vertical == null)
                {
                    subwords[0] = horizontal;
                    subwords[1] = vertical;
                }
                else if (horizontal == null)
                {
                    subwords[0] = vertical;
                    subwords[1] = horizontal;
                }
                else if (horizontal.ExtractWord().Length >= vertical.ExtractWord().Length)
                {
                    subwords[0] = horizontal;
                    subwords[1] = vertical;
                }
                else
                {
                    subwords[0] = vertical;
                    subwords[1] = horizontal;
                }

                return(subwords.Where(x => x.ExtractWord().Length > 1).ToList());
            }
            List <Tuple <Space, Tile> > mainWord = _playList.ToList();
            List <Space> anchors = _placement.Anchors;

            foreach (Space anchor in anchors)
            {
                mainWord.Add(Tuple.Create(anchor, anchor.GetTile()));
            }
            SubWord primaryWord = new SubWord(mainWord, _game);

            subwords[0] = primaryWord;

            List <Space> playSpaces = _placement.GetSpaceList();

            if (_placement.IsHorizontal())
            {
                //Build a vertical subword for each space in the Play
                for (int i = 1; i < subwords.Length; i++)
                {
                    subwords[i] = _game.SingleSubWord(_playList[i - 1], "vertical");
                }
            }
            if (_placement.IsVertical())
            {
                //Build a horizontal subword for each space in the Play
                for (int i = 1; i < subwords.Length; i++)
                {
                    subwords[i] = _game.SingleSubWord(_playList[i - 1], "horizontal");
                }
            }
            return(subwords.Where(x => x.ExtractWord().Length > 1).ToList());
        }