public void TestCompareNoOneFixes(string w1, Fix f1, string w2, Fix f2, int expected) { foreach (Fix two1 in Enum.GetValues(typeof(Fix))) { foreach (Fix two2 in Enum.GetValues(typeof(Fix))) { var comparer = new ValidWordComparer(WordStrategy.NoOneFixes); var x = new ValidWord(w1, f1, two1); var y = new ValidWord(w2, f2, two2); Assert.AreEqual(expected, comparer.Compare(x, y)); Assert.AreEqual(-expected, comparer.Compare(y, x)); TestSort(comparer, x, y, expected); } } }
internal WordPart GetFirstWord(Rack rack) { var ai = new AI(graph); List <ValidWord> words = ai.FindLongest(rack.Value).ToList(); var validWordComparer = new ValidWordComparer(WordStrategy.NoOneFixes); words.Sort(validWordComparer); words.Reverse(); Console.WriteLine("{0} word{1}", words.Count, words.Count > 1 ? "s" : ""); for (int i = 0; i < words.Count; i++) { ValidWord word = words[i]; Console.WriteLine("{0}> {1} 1:{2} 2+:{3}", i + 1, word.Word, word.OneFixes, word.TwoMoreFixes); } var weighted = new List <Tuple <double, ValidWord> >(); foreach (ValidWord valid in words) { if (weighted.Count == 0 || validWordComparer.Compare(valid, weighted[weighted.Count - 1].Item2) == 0) { weighted.Add(new Tuple <double, ValidWord>(graph.GetWeight(valid.Word), valid)); } } weighted.Sort((x, y) => x.Item1.CompareTo(y.Item1)); Direction direction = random.Bool ? Direction.Right : Direction.Down; ValidWord selected = weighted[0].Item2; var cellFinder = new CellFinder(random, selected, direction); Cell first = cellFinder.Run(); return(new WordPart(selected.Word, first, direction)); }
public void TestCompareLengthSameFixes(string first, string second, int expected) { foreach (WordStrategy strategy in Enum.GetValues(typeof(WordStrategy))) { foreach (Fix one in Enum.GetValues(typeof(Fix))) { foreach (Fix two in Enum.GetValues(typeof(Fix))) { var comparer = new ValidWordComparer(strategy); var x = new ValidWord(first, one, two); var y = new ValidWord(second, one, two); Assert.AreEqual(expected, comparer.Compare(x, y)); Assert.AreEqual(-expected, comparer.Compare(y, x)); TestSort(comparer, x, y, expected); } } } }