Exemple #1
0
        internal static WordContent ParseContent(string content)
        {
            int count = GetCount(content);
            ConstantSet <string> words = GetWords(content);

            return(new WordContent(count, words));
        }
Exemple #2
0
 private Board(char[][] board, Player[][] owner, ConstantSet <Cell> cells, Player player, Score score)
 {
     this.board  = board;
     this.owner  = owner;
     this.cells  = cells;
     this.player = player;
     this.score  = score;
 }
Exemple #3
0
 private static bool Contains(ConstantSet <Cell> start, IEnumerable <Cell> played)
 {
     foreach (Cell cell in played)
     {
         if (start.Contains(cell))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
            public Choices(WordGraph graph, Board board, PlayPath path, Fix fix, Cell cell)
            {
                this.fix  = fix;
                this.cell = cell;
                Direction direction      = path.Main.Direction;
                var       otherDirection = direction == Direction.Down ? Direction.Right : Direction.Down;
                var       playable       = new PlayableLetters(path.Pending);
                WordPart  before         = fix == Fix.Suffix ? path.Main : null;
                WordPart  after          = fix == Fix.Prefix ? path.Main : null;

                main    = GetBeforeAfter(board, cell, direction, graph, playable, before, after);
                extra   = GetBeforeAfter(board, cell, otherDirection, graph, playable);
                letters = playable.Choices.ToConstant();
            }
Exemple #5
0
        public ConstantSet <ValidWord> FindLongest(string word)
        {
            ConstantSet <ValidWord> found = Find(word);

            if (found.Count > 0)
            {
                return(found);
            }
            for (int pending = 1; pending <= word.Length - 2; pending++)
            {
                var set = new HashSet <ValidWord>();
                FindLongest(word, set, pending);
                if (set.Count > 0)
                {
                    return(set.ToConstant());
                }
            }
            return(new ConstantSet <ValidWord>());
        }
Exemple #6
0
        public Board Play(WordPart part, IList <LetterPlay> played, WordPartCollection extras)
        {
            var start = new ConstantSet <Cell>(GetStartCells());
            var list  = new List <Cell>();

            list.Add(part.First);
            var current = part.First;

            for (int i = 1; i < part.Word.Length; i++)
            {
                if (!current.TryGetNext(part.Direction, out current))
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Cannot play {0} at {1}", part.Word, part.First));
                }
                list.Add(current);
            }
            if (!Contains(start, list))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Cannot play {0} at {1}", part.Word, part.First));
            }
            var newBoard = BuildBoard();
            var newOwner = BuildOwner();

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    newBoard[i][j] = board[i][j];
                    newOwner[i][j] = owner[i][j];
                }
            }
            var newPlayer = player == Player.First ? Player.Second : Player.First;
            int taken     = 0;
            var newCells  = new HashSet <Cell>(cells);

            for (int i = 0; i < part.Word.Length; i++)
            {
                Cell c      = list[i];
                char letter = part.Word[i];
                if (newBoard[c.Row][c.Column] == Empty || newOwner[c.Row][c.Column] != player)
                {
                    if (newOwner[c.Row][c.Column] == newPlayer)
                    {
                        taken++;
                    }
                    newBoard[c.Row][c.Column] = letter;
                    newOwner[c.Row][c.Column] = player;
                    newCells.Add(c);
                    if (CellUpdated != null)
                    {
                        CellUpdated(this, new CellUpdatedEventArgs(c, letter));
                    }
                }
            }

            int  points = played.Count;
            int  stars  = 0;
            bool vortex = false;

            foreach (LetterPlay lp in played)
            {
                if (lp.Cell.IsStar)
                {
                    stars++;
                }
                else if (lp.Cell.IsVortex)
                {
                    vortex = true;
                }
            }
            foreach (WordPart extra in extras)
            {
                var cell = extra.First;
                for (int i = 0; i < extra.Word.Length; i++)
                {
                    if (newOwner[cell.Row][cell.Column] != player)
                    {
                        newOwner[cell.Row][cell.Column] = player;
                        taken++;
                    }
                    if (i < extra.Word.Length - 1)
                    {
                        switch (extra.Direction)
                        {
                        case Direction.Down:
                            cell = cell.Down;
                            break;

                        case Direction.Right:
                            cell = cell.Right;
                            break;
                        }
                    }
                }
            }
            var newOther   = new PlayerScore(score.Current.Points + points + taken + (vortex ? score.Current.Stars + stars : 0), vortex ? 0 : score.Current.Stars + stars);
            var newCurrent = new PlayerScore(score.Other.Points - taken, vortex ? 0 : score.Other.Stars);
            var newScore   = new Score(newCurrent, newOther);

            var result = new Board(newBoard, newOwner, newCells.ToConstant(), newPlayer, newScore);

            result.CellUpdated = CellUpdated;
            return(result);
        }
Exemple #7
0
 public WordContent(int count, ConstantSet <string> words)
 {
     this.count = count;
     this.words = words;
 }