コード例 #1
0
        public void Append_EmptyAddsCharAtEnd_ReturnsNewValue()
        {
            Word empty = new Word(string.Empty);

            Word b = empty.Append('b');

            Assert.Equal("B", b.ToString());
        }
コード例 #2
0
        public void Append_AddsCharAtEnd_ReturnsNewValue()
        {
            Word a = new Word("a");

            Word ab = a.Append('b');

            Assert.Equal("AB", ab.ToString());
        }
コード例 #3
0
ファイル: Scrabble.cs プロジェクト: jaysilk84/dawg
        private CrossCheck GetDownWord(Square[,] board, Square currentSquare)
        {
            var word    = new Word("");
            var squares = new List <Square>();

            // get upper bound of the potential downword
            var r = currentSquare.Position.Y - 1;
            var c = currentSquare.Position.X;

            while (r < MAX_ROW && r >= MIN_ROW && board[r, c].IsOccupied)
            {
                r--;
            }

            for (r = r + 1; r < MAX_ROW; r++)
            {
                var s = board[r, c];
                if (currentSquare.Position.Y == r)
                {
                    word = word.Append('?', s.HasBlank);
                    var sc = new Square(s);
                    sc.Tile = '?';
                    squares.Add(sc);
                }
                else if (s.IsOccupied)
                {
                    word = word.Append(s.Tile.Value, s.HasBlank);
                    squares.Add(s);
                }
                else
                {
                    break;
                }

                // shady because this is dependant on the break above. Essentially add
                // the square to the squares list if it's an occupied square
            }

            return(new CrossCheck(word, squares));
        }
コード例 #4
0
ファイル: Scrabble.cs プロジェクト: jaysilk84/dawg
 private void LeftPart(Word partialWord, Lib.Node root, int limit, Rack rack, Square[,] board, Square anchor)
 {
     ExtendRight(partialWord, root, board, anchor, rack, anchor);
     if (limit > 0)
     {
         foreach (var e in root.Children)
         {
             if (rack.HasLetter(e.Key))
             {
                 rack.Remove(e.Key);
                 LeftPart(partialWord.Append(e.Key, false), e.Value, limit - 1, rack, board, anchor);
                 rack.Add(e.Key);
             }
             else if (rack.HasBlank)
             {
                 rack.Remove('?');
                 LeftPart(partialWord.Append(e.Key, true), e.Value, limit - 1, rack, board, anchor);
                 rack.Add('?');
             }
         }
     }
 }
コード例 #5
0
ファイル: Scrabble.cs プロジェクト: jaysilk84/dawg
        // TODO: Anchor shouldnt need to be known if we know the board is transposed or not. Find another way to
        // figure out if we placed a tile?
        private void ExtendRight(Word partialWord, Node root, Square[,] board, Square square, Rack rack, Square anchor)
        {
            if (!square.IsOccupied)
            {
                if (root.EndOfWord && square.Position != anchor.Position)
                {
                    // square is off one position to the right of the word, we calc start by the end of the word minus the letter count
                    // start is offset by 1 because it should be partialWord.Length - 1, leaving it just .Length accomplishes the same
                    LegalMove(partialWord, square.Offset(0, -(partialWord.Length)), square.Offset(0, -1), board, rack);
                }

                foreach (var e in root.Children)
                {
                    if (rack.HasLetter(e.Key) && square.CrossChecks.ContainsKey(e.Key))
                    {
                        rack.Remove(e.Key);
                        ExtendRight(partialWord.Append(e.Key, false), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                        rack.Add(e.Key);
                    }
                    else if (rack.HasBlank && square.CrossChecks.ContainsKey(e.Key))
                    {
                        rack.Remove('?');
                        ExtendRight(partialWord.Append(e.Key, true), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                        rack.Add('?');
                    }
                }
            }
            else
            {
                var key = square.Tile.Value;
                if (root.Children.ContainsKey(square.Tile.Value))
                {
                    ExtendRight(partialWord.Append(key, square.HasBlank), root.Children[key], board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                }
            }
        }