예제 #1
0
        [Test] public void TestCompareWordsNoFixes([Values(false, true)] bool vortex1,
                                                   [Values(false, true)] bool vortex2,
                                                   [Values(Fix.None, Fix.Prefix)] Fix one1,
                                                   [Values(Fix.None, Fix.Prefix)] Fix two1,
                                                   [Values(Fix.None, Fix.Prefix)] Fix one2,
                                                   [Values(Fix.None, Fix.Prefix)] Fix two2)
        {
            var score = new Score(new PlayerScore(10), new PlayerScore(15));

            foreach (ScoreStrategy scoreStrategy in Enum.GetValues(typeof(ScoreStrategy)))
            {
                var comparer = new PlayInfoComparer(scoreStrategy, WordStrategy.NoFixes);
                var first    = new PlayInfo(vortex1, score, one1, two1);
                var second   = new PlayInfo(vortex2, score, one2, two2);
                int expected = GetExpected(vortex1, vortex2, first.HasFixes, second.HasFixes);
                Assert.AreEqual(expected, comparer.Compare(first, second));
                Assert.AreEqual(-expected, comparer.Compare(second, first));
                TestSort(comparer, first, second, expected);
            }
        }
예제 #2
0
파일: Wordox.cs 프로젝트: dedale/wordox
 private static void WriteMoves(IComparer <PlayInfo> comparer, IEnumerable <Tuple <double, PlayInfo, PlayPath> > moves)
 {
     Console.WriteLine(comparer);
     foreach (Tuple <double, PlayInfo, PlayPath> tuple in moves)
     {
         double   weight = tuple.Item1;
         PlayInfo info   = tuple.Item2;
         PlayPath path   = tuple.Item3;
         Console.WriteLine("{0} word: {1} - {2}{3}{4}[{5}] ({6}){7}",
                           weight.ToString("0.###", CultureInfo.InvariantCulture),
                           path.Main,
                           info.HasFixes && !info.HasVortex ? (info.HasOneFixes ? "1" : "") + (info.HasTwoMoreFixes ? "2+" : "") + "fixes " : "",
                           info.HasVortex ? "vortex " : "",
                           info.Points,
                           info.Diff.ToString("+#;-#;0", CultureInfo.InvariantCulture),
                           info.Stars,
                           info.Wins ? " wins" : "");
     }
     Console.WriteLine();
 }
예제 #3
0
 [Test] public void TestCompareWinsEquals([Values(false, true)] bool vortex1,
                                          [Values(false, true)] bool vortex2,
                                          [Values(Fix.None, Fix.Prefix)] Fix one1,
                                          [Values(Fix.None, Fix.Prefix)] Fix two1,
                                          [Values(Fix.None, Fix.Prefix)] Fix one2,
                                          [Values(Fix.None, Fix.Prefix)] Fix two2)
 {
     foreach (ScoreStrategy score in Enum.GetValues(typeof(ScoreStrategy)))
     {
         foreach (WordStrategy word in Enum.GetValues(typeof(WordStrategy)))
         {
             var firstScore  = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints));
             var first       = new PlayInfo(vortex1, firstScore, one1, two1);
             var secondScore = new Score(new PlayerScore(PlayerScore.WinPoints - 6), new PlayerScore(PlayerScore.WinPoints + 1));
             var second      = new PlayInfo(vortex2, secondScore, one2, two2);
             var comparer    = new PlayInfoComparer(score, word);
             Assert.AreEqual(-1, comparer.Compare(first, second));
             Assert.AreEqual(1, comparer.Compare(second, first));
             TestSort(comparer, first, second, -1);
         }
     }
 }
예제 #4
0
 [Test] public void TestCompareWinsFirst([Values(false, true)] bool vortex1,
                                         [Values(false, true)] bool vortex2,
                                         [Values(Fix.None, Fix.Prefix)] Fix one1,
                                         [Values(Fix.None, Fix.Prefix)] Fix two1,
                                         [Values(Fix.None, Fix.Prefix)] Fix one2,
                                         [Values(Fix.None, Fix.Prefix)] Fix two2)
 {
     foreach (ScoreStrategy score in Enum.GetValues(typeof(ScoreStrategy)))
     {
         foreach (WordStrategy word in Enum.GetValues(typeof(WordStrategy)))
         {
             var wonScore   = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints));
             var won        = new PlayInfo(vortex1, wonScore, one1, two1);
             var otherScore = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints - 1));
             var other      = new PlayInfo(vortex2, otherScore, one2, two2);
             var comparer   = new PlayInfoComparer(score, word);
             Assert.Less(0, comparer.Compare(won, other));
             Assert.Greater(0, comparer.Compare(other, won));
             TestSort(comparer, won, other, 1);
         }
     }
 }
예제 #5
0
        [Test] public void TestCompareWordsNone([Values(Fix.None, Fix.Prefix)] Fix one1,
                                                [Values(Fix.None, Fix.Prefix)] Fix two1,
                                                [Values(Fix.None, Fix.Prefix)] Fix one2,
                                                [Values(Fix.None, Fix.Prefix)] Fix two2)
        {
            var score = new Score(new PlayerScore(10), new PlayerScore(15));

            foreach (bool vortex1 in new[] { false, true })
            {
                foreach (bool vortex2 in new[] { false, true })
                {
                    foreach (ScoreStrategy scoreStrategy in Enum.GetValues(typeof(ScoreStrategy)))
                    {
                        var comparer = new PlayInfoComparer(scoreStrategy, WordStrategy.None);
                        var first    = new PlayInfo(vortex1, score, one1, two1);
                        var second   = new PlayInfo(vortex2, score, one2, two2);
                        Assert.AreEqual(0, comparer.Compare(first, second));
                        Assert.AreEqual(0, comparer.Compare(second, first));
                        TestSort(comparer, first, second, 0);
                    }
                }
            }
        }
예제 #6
0
        public void TestCompareScores(int c1, int p1, int c2, int p2, ScoreStrategy strategy, int expected)
        {
            var firstScore  = new Score(new PlayerScore(c1), new PlayerScore(p1));
            var secondScore = new Score(new PlayerScore(c2), new PlayerScore(p2));

            foreach (bool vortex in new[] { false, true })
            {
                foreach (WordStrategy word in Enum.GetValues(typeof(WordStrategy)))
                {
                    foreach (Fix oneFixes in new[] { Fix.None, Fix.All })
                    {
                        foreach (Fix twoMoreFixes in new[] { Fix.None, Fix.All })
                        {
                            var comparer = new PlayInfoComparer(strategy, word);
                            var first    = new PlayInfo(vortex, firstScore, oneFixes, twoMoreFixes);
                            var second   = new PlayInfo(vortex, secondScore, oneFixes, twoMoreFixes);
                            Assert.AreEqual(expected, comparer.Compare(first, second));
                            Assert.AreEqual(-expected, comparer.Compare(second, first));
                            TestSort(comparer, first, second, expected);
                        }
                    }
                }
            }
        }
예제 #7
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();
                    }
                }
            }
        }