示例#1
0
文件: Program.cs 项目: dedale/wordox
        internal static PlayPath GetPath(Board board, Rack rack, WordPart part)
        {
            ISet <Cell> excluded             = board.GetExcluded(part);
            ConstantList <LetterPlay> played = part.GetPlayed(excluded);
            var extras         = new List <WordPart>();
            var otherDirection = part.Direction == Direction.Right ? Direction.Down : Direction.Right;
            var pending        = new List <char>(rack.Letters);

            foreach (LetterPlay lp in played)
            {
                var      before = board.GetBeforePart(lp.Cell, otherDirection);
                var      after  = board.GetAfterPart(lp.Cell, otherDirection);
                var      pair   = new WordPartPair(before, after);
                WordPart extra  = pair.Play(lp.Cell, lp.Letter);
                if (extra != null)
                {
                    extras.Add(extra);
                }
                pending.Remove(lp.Letter);
            }
            return(new PlayPath(part, new WordPartCollection(extras.ToConstant()), played, pending.ToConstant()));
        }
示例#2
0
 public Board Play(WordPart part)
 {
     return(Play(part, part.GetPlayed(), new WordPartCollection()));
 }
示例#3
0
 public PlayPath(WordPart main)
     : this(main, new WordPartCollection(), main.GetPlayed(), new ConstantList <char>())
 {
 }
示例#4
0
文件: Program.cs 项目: dedale/wordox
        private PlayPath ReadMove(Board board, Rack rack)
        {
            var regex = new Regex(@"^\s*(?<word>[a-z]+)\s*(?<row>\d),(?<column>\d)\s*(?<direction>(down|right|))\s*$", RegexOptions.IgnoreCase);

            using (DisposableColor.Prompt)
                Console.Write("move? ");
            Console.Write("[word r,c down|right] [play|guess|skip] ");
            while (true)
            {
                try
                {
                    string line = null;
                    using (new DisposableColor(PlayerScore.GetColor(board.Current)))
                        line = ReadLine().Trim();
                    if (line == "skip")
                    {
                        return(null);
                    }
                    if (line == "play" || line == "guess")
                    {
                        if (board.IsEmpty)
                        {
                            var      game = new Game(random, graph);
                            WordPart part = game.GetFirstWord(rack);
                            Console.WriteLine(part);
                            Console.WriteLine();

                            var played  = part.GetPlayed();
                            var pending = new List <char>(rack.Letters);
                            foreach (LetterPlay lp in played)
                            {
                                pending.Remove(lp.Letter);
                            }
                            var path = new PlayPath(part, new WordPartCollection(), part.GetPlayed(), pending.ToConstant());
                            if (line == "play")
                            {
                                return(path);
                            }
                        }
                        else
                        {
                            PlayPath path = FindMove(rack);
                            if (line == "play")
                            {
                                return(path);
                            }
                        }
                    }
                    Match m = regex.Match(line);
                    if (m.Success)
                    {
                        string    word      = m.Groups["word"].Value;
                        int       row       = int.Parse(m.Groups["row"].Value, CultureInfo.InvariantCulture);
                        int       column    = int.Parse(m.Groups["column"].Value, CultureInfo.InvariantCulture);
                        Direction?direction = Parse(m.Groups["direction"].Value);
                        PlayPath  path      = GetPath(board, rack, word, row, column, direction);
                        if (path != null)
                        {
                            Console.WriteLine();
                            return(path);
                        }
                    }
                    Console.Write("? ");
                }
                catch (FormatException e)
                {
                    var color = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("{0} : {1}", e.GetType().Name, e.Message);
                    Console.ForegroundColor = color;
                    Console.Write("? ");
                }
            }
        }