public void TestArrangementAnalyzer()
        {
            // Randomly picked 2 shanten hand. 34467p 44446s 3447m
              var pinzu = new[] // 001201100 (0,3,5)(1,2,4)(2,0,0)(2,1,2)(2,2,3)
              {
            new Arrangement(0, 3, 5),
            new Arrangement(1, 2, 4), // 2 incomplete mentsu
            new Arrangement(2, 0, 0),
            new Arrangement(2, 1, 2),
            new Arrangement(2, 2, 3)
              };
              var souzu = new[] // 000401000 (0,2,5)(1,1,3)(2,0,0)(2,1,2)
              {
            new Arrangement(0, 2, 5), // 1 incomplete and 1 complete mentsu
            new Arrangement(1, 1, 3),
            new Arrangement(2, 0, 0),
            new Arrangement(2, 1, 2)
              };
              var manzu = new[] // 001200100 (0,3,4)(1,1,2)(1,2,3)(2,0,0)(2,1,1)(2,2,2)
              {
            new Arrangement(0, 3, 4),
            new Arrangement(1, 1, 2),
            new Arrangement(1, 2, 3),
            new Arrangement(2, 0, 0), // 1 complete pair
            new Arrangement(2, 1, 1),
            new Arrangement(2, 2, 2)
              };
              var honor = new Arrangement(0, 0, 0).Yield();

              var analyzer = new ArrangementAnalyzer();
              analyzer.AddSetOfArrangements(pinzu);
              analyzer.AddSetOfArrangements(souzu);
              analyzer.AddSetOfArrangements(manzu);
              analyzer.AddSetOfArrangements(honor);
              var shanten = analyzer.CalculateShanten();
              Assert.AreEqual(2, shanten);
        }
示例#2
0
    private IEnumerable<WordWithValue> CreateWords(IEnumerable<List<Arrangement>> arrangements)
    {
      var arrangementsList = arrangements.ToList();
      var alphabetSize = arrangementsList.Count;
      var language = CreateBaseLanguage(alphabetSize);
      var tilesInArrangements = arrangementsList.Select(a => a.Max(b => b.TotalValue)).ToList();

      var max = alphabetSize * ((long)alphabetSize + 1) * ((long)alphabetSize + 2) * ((long)alphabetSize + 3) / 24;
      long count = 0;
      long current = 0;
      foreach (var word in language)
      {
        var sumOfTiles = word.Sum(c => tilesInArrangements[c]);
        if (sumOfTiles <= 14)
        {
          var analyzer = new ArrangementAnalyzer();
          foreach (var character in word)
          {
            analyzer.AddSetOfArrangements(arrangementsList[character]);
          }
          var shanten = analyzer.CalculateShanten();
          if (shanten < 9)
          {
            yield return new WordWithValue(word, shanten);
          }
        }

        count += 1;
        if (current * (max / 100) < count)
        {
          IncrementProgressBar();
          current += 1;
        }
      }
    }
示例#3
0
    private static bool RemoveRedundantArrangement(string workingDirectory)
    {
      var redundancyLog = Path.Combine(workingDirectory, "RedundanciesLog.txt");
      File.WriteAllLines(redundancyLog, Enumerable.Empty<string>());

      var arrangements = GetAllArrangements(workingDirectory).ToList();
      var alphabetSize = arrangements.Count;
      var tilesInArrangements = arrangements.Select(a => a.Max(b => b.TotalValue)).ToList();

      for (var i = 0; i < arrangements.Count; ++i)
      {
        var arrangement = arrangements[i];
        if (arrangement.Count < 2)
        {
          continue;
        }

        for (var j = 0; j < arrangement.Count; ++j)
        {
          var isRedundant = true;
          var language = CreateBaseLanguage(alphabetSize);
          foreach (var word in language)
          {
            if (word.All(c => c != i))
            {
              continue;
            }

            var sumOfTiles = word.Sum(c => tilesInArrangements[c]);
            if (sumOfTiles > 14)
            {
              continue;
            }
            var analyzer = new ArrangementAnalyzer();
            foreach (var character in word)
            {
              analyzer.AddSetOfArrangements(arrangements[character]);
            }
            var shanten = analyzer.CalculateShanten();
            if (shanten >= 9)
            {
              continue;
            }

            var replacement = arrangement.Where((t, index) => index != j).ToList();
            var analyzer2 = new ArrangementAnalyzer();
            foreach (var character in word)
            {
              analyzer2.AddSetOfArrangements(character == i ? replacement : arrangements[character]);
            }
            var shanten2 = analyzer2.CalculateShanten();
            if (shanten != shanten2)
            {
              isRedundant = false;
              break;
            }
          }
          if (isRedundant)
          {
            File.AppendAllLines(redundancyLog, $"Removing {arrangements[i][j]} from {string.Join("", arrangements[i])}; i = {i}, j = {j}".Yield());
            arrangements[i].RemoveAt(j);
            var newLines = arrangements.Select(GetArrangementsString).Distinct().OrderBy(line => line);
            var targetFile = Path.Combine(workingDirectory, "ArrangementCombinations.txt");
            File.WriteAllLines(targetFile, newLines);
            return true;
          }
        }
      }
      return false;
    }