Exemplo n.º 1
0
        private PlayPath FindMove(Rack rack)
        {
            PlayGraph play       = new PlayGraph(graph, board, rack);
            var       moveFinder = new MoveFinder(graph, board, play);

            return(moveFinder.GetBestMove().Item2);
        }
Exemplo n.º 2
0
        public void Play()
        {
            var board = new Board();
            var rack  = new Rack(graph.GetRandom());

            Console.WriteLine("rack: " + rack.Value);
            WordPart part = GetFirstWord(rack);

            Console.WriteLine("word: {0}", part);
            board = board.Play(part);
            var letters = new List <char>(rack.Letters);

            foreach (char c in part.Word)
            {
                letters.Remove(c);
            }
            board.Write();

            while (!board.Score.Other.Wins)
            {
                var time = new Chrono();

                Console.Write("------------------------------\n");
                rack = new Rack(graph.GetRandom(new string(letters.ToArray())));
                Console.WriteLine("rack: " + rack.Value);

                if (board.IsEmpty)
                {
                    part = GetFirstWord(rack);
                    Console.WriteLine("word: {0}", part);
                    board   = board.Play(part);
                    letters = new List <char>(rack.Letters);
                    foreach (char c in part.Word)
                    {
                        letters.Remove(c);
                    }
                    board.Write();
                }
                else
                {
                    var       chrono  = new Chrono();
                    PlayGraph play    = GetPlayGraph(board, rack);
                    double    seconds = .1 * Convert.ToInt32(chrono.Elapsed.TotalSeconds * 10);
                    Console.WriteLine("{0} moves in {1} s", play.Valids.Count, seconds);
                    chrono = new Chrono();
                    var moveFinder = new MoveFinder(graph, board, play);
                    Tuple <PlayInfo, PlayPath> best = moveFinder.GetBestMove();
                    seconds = .1 * Convert.ToInt32(chrono.Elapsed.TotalSeconds * 10);
                    Console.WriteLine("Analyzed {0} moves in {1} s", play.Valids.Count, seconds);
                    Console.WriteLine();
                    {
                        PlayInfo info = best.Item1;
                        PlayPath path = best.Item2;
                        path.Write();
                        board = board.Play(path);
                        board.Write();
                        if (info.HasVortex)
                        {
                            board = board.Clear();
                            letters.Clear();
                        }
                        else
                        {
                            letters = new List <char>(rack.Letters);
                            foreach (LetterPlay lp in path.Played)
                            {
                                letters.Remove(lp.Letter);
                            }
                        }
                    }
                    if (time.Elapsed.TotalSeconds > 40)
                    {
                        throw new TimeoutException();
                    }
                }
            }
        }