コード例 #1
0
ファイル: Program.cs プロジェクト: dedale/wordox
        private PlayPath FindMove(Rack rack)
        {
            PlayGraph play       = new PlayGraph(graph, board, rack);
            var       moveFinder = new MoveFinder(graph, board, play);

            return(moveFinder.GetBestMove().Item2);
        }
コード例 #2
0
        [Test] public void TestFixes1()
        {
            var graph = WordGraph.French;
            var board = new Board();
            var rack  = new Rack("ASSDHS");

            var part1 = new WordPart("DAHS", new Cell(4, 4), Direction.Down);

            board = board.Play(part1);

            rack = new Rack("SSEEEA");
            PlayGraph play       = new PlayGraph(graph, board, rack);
            var       moveFinder = new MoveFinder(graph, board, play);
            List <Tuple <PlayInfo, PlayPath> > moves = moveFinder.GetAllMoves();

            foreach (Tuple <PlayInfo, PlayPath> move in moves)
            {
                if ("ES" != move.Item2.Main.Word ||
                    new Cell(7, 5) != move.Item2.Main.First ||
                    Direction.Down != move.Item2.Main.Direction)
                {
                    continue;
                }
                Assert.IsTrue(move.Item1.HasFixes);
                Assert.IsTrue(move.Item1.HasTwoMoreFixes);
            }
        }
コード例 #3
0
        [Test] public void TestFixes2()
        {
            var graph = WordGraph.French;
            var board = new Board();
            var rack  = new Rack("DELRIC");

            var part1 = new WordPart("DECRI", new Cell(4, 4), Direction.Right);

            board = board.Play(part1);

            rack = new Rack("LTREIG");
            PlayGraph play       = new PlayGraph(graph, board, rack);
            var       moveFinder = new MoveFinder(graph, board, play);
            List <Tuple <PlayInfo, PlayPath> > moves = moveFinder.GetAllMoves();

            foreach (Tuple <PlayInfo, PlayPath> move in moves)
            {
                if ("GILET" != move.Item2.Main.Word ||
                    new Cell(5, 1) != move.Item2.Main.First ||
                    Direction.Right != move.Item2.Main.Direction)
                {
                    continue;
                }
                Assert.IsTrue(move.Item1.HasFixes);
                Assert.IsFalse(move.Item1.HasTwoMoreFixes);
            }
        }
コード例 #4
0
        private static Board TestPlayIgnoreExtra(IList <Tuple <string, string, Cell, Direction> > plays)
        {
            var graph = WordGraph.French;
            var board = new Board();
            var rack  = new Rack(plays[0].Item1);

            var part1 = new WordPart(plays[0].Item2, plays[0].Item3, plays[0].Item4);

            board = board.Play(part1);

            for (int i = 1; i < plays.Count; i++)
            {
                rack = new Rack(plays[i].Item1);
                PlayGraph play       = new PlayGraph(graph, board, rack);
                var       moveFinder = new MoveFinder(graph, board, play);
                List <Tuple <PlayInfo, PlayPath> > moves = moveFinder.GetAllMoves();
                foreach (Tuple <PlayInfo, PlayPath> move in moves)
                {
                    PlayPath path = move.Item2;
                    if (plays[i].Item2 != path.Main.Word ||
                        plays[i].Item3 != path.Main.First ||
                        plays[i].Item4 != path.Main.Direction)
                    {
                        continue;
                    }
                    board = board.Play(path);
                    if (i != plays.Count - 1)
                    {
                        continue;
                    }
                    Assert.GreaterOrEqual(board.Score.Other.Points, 0);
                    Assert.GreaterOrEqual(board.Score.Current.Points, 0);
                    return(board);
                }
            }
            throw new InvalidOperationException("Move not found");
        }
コード例 #5
0
ファイル: Wordox.cs プロジェクト: dedale/wordox
        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();
                    }
                }
            }
        }