public void Test_NotAValidHand_2() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Circle, 1), new TilePivot(FamilyPivot.Circle, 1), new TilePivot(FamilyPivot.Circle, 2), new TilePivot(FamilyPivot.Circle, 3), new TilePivot(FamilyPivot.Circle, 7), new TilePivot(FamilyPivot.Circle, 8), new TilePivot(DragonPivot.Red) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.North, new TilePivot(DragonPivot.Red)); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(0, groupsOfYakus.Count); }
public void Test_ChuurenPoutou_Chiihou() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Bamboo, 1), new TilePivot(FamilyPivot.Bamboo, 1), new TilePivot(FamilyPivot.Bamboo, 1), new TilePivot(FamilyPivot.Bamboo, 2), new TilePivot(FamilyPivot.Bamboo, 3), new TilePivot(FamilyPivot.Bamboo, 4), new TilePivot(FamilyPivot.Bamboo, 5), new TilePivot(FamilyPivot.Bamboo, 6), new TilePivot(FamilyPivot.Bamboo, 7), new TilePivot(FamilyPivot.Bamboo, 8), new TilePivot(FamilyPivot.Bamboo, 9), new TilePivot(FamilyPivot.Bamboo, 9), new TilePivot(FamilyPivot.Bamboo, 9) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.North, new TilePivot(FamilyPivot.Bamboo, 3)); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(1, groupsOfYakus[0].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.ChuurenPoutou))); }
public void Test_KokushiMusou_Tenhou() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Circle, 1), new TilePivot(FamilyPivot.Circle, 9), new TilePivot(FamilyPivot.Bamboo, 1), new TilePivot(FamilyPivot.Bamboo, 9), new TilePivot(WindPivot.East), new TilePivot(WindPivot.South), new TilePivot(WindPivot.North), new TilePivot(WindPivot.West), new TilePivot(DragonPivot.Red), new TilePivot(DragonPivot.Green), new TilePivot(DragonPivot.White) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.East, new TilePivot(DragonPivot.White)); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(1, groupsOfYakus[0].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.KokushiMusou))); }
public void Test_Sankantsu_Chankan_Honroutou_Shousangen_Honitsu_Sanankou_Toitoi_Yakuhai() { List <SetPivot> concealedKans = new List <SetPivot> { new SetPivot(new TilePivot(DragonPivot.White), new TilePivot(DragonPivot.White), new TilePivot(DragonPivot.White), new TilePivot(DragonPivot.White)), new SetPivot(new TilePivot(DragonPivot.Green), new TilePivot(DragonPivot.Green), new TilePivot(DragonPivot.Green), new TilePivot(DragonPivot.Green)), new SetPivot(new TilePivot(WindPivot.North), new TilePivot(WindPivot.North), new TilePivot(WindPivot.North), new TilePivot(WindPivot.North)) }; List <TilePivot> tiles = new List <TilePivot> { new TilePivot(DragonPivot.Red), new TilePivot(DragonPivot.Red), new TilePivot(FamilyPivot.Circle, 9), new TilePivot(FamilyPivot.Circle, 9) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); // Note : this is an impossible hand, as Chankan can be made on something else than a chi. FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.North, new TilePivot(FamilyPivot.Circle, 9), concealedKans: concealedKans, isChankan: true, isRon: true); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(10, groupsOfYakus[0].Yakus.Count); Assert.AreEqual(3, groupsOfYakus[0].Yakus.Count(y => y.Name == YakuPivot.Yakuhai)); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Toitoi))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Sanankou))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Honitsu))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Shousangen))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Honroutou))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Chankan))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Sankantsu))); }
private static Tuple <List <SubstitutionGroup>, List <Substitution> > BackgroundHandlerForOneTileAway(WindPivot dominantWind, WindPivot seatWind, List <TilePivot> handTileWithLast, List <TilePivot> availableTiles, List <TilePivot> forbiddenTiles) { var substitutionsAttemps = new List <Substitution>(); var rawResults = new List <SubstitutionGroup>(); foreach (TilePivot subbedTile in handTileWithLast.Distinct()) { foreach (TilePivot subTile in availableTiles.Distinct()) { if (subbedTile.Equals(subTile) || forbiddenTiles.Contains(subTile)) { continue; } substitutionsAttemps.Add(new Substitution(subbedTile, subTile, availableTiles)); List <TilePivot> handTilesWithSub = new List <TilePivot>(handTileWithLast); handTilesWithSub.Remove(subbedTile); var hand1 = new FullHandPivot(handTilesWithSub, dominantWind, seatWind, subTile); HandYakuListPivot tmpResults = hand1.ComputeHandYakus()?.FirstOrDefault(); if (tmpResults != null) { var subSeq = new SubstitutionSequence(); subSeq.AddSubstitution(new Substitution(subbedTile, subTile, availableTiles)); var finded = rawResults.FirstOrDefault(x => x.Yakus.Equals(tmpResults)); if (finded == null) { rawResults.Add(new SubstitutionGroup(tmpResults)); finded = rawResults.Last(); } finded.AddSubstitutionSequence(subSeq); } } } return(new Tuple <List <SubstitutionGroup>, List <Substitution> >(rawResults, substitutionsAttemps)); }
public void Test_Ryanpeikou_Pinfu_Chinitsu_Junchantaiyao() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Character, 7), new TilePivot(FamilyPivot.Character, 7), new TilePivot(FamilyPivot.Character, 8), new TilePivot(FamilyPivot.Character, 8), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Character, 9), }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.North, new TilePivot(FamilyPivot.Character, 1), isRon: true); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(4, groupsOfYakus[0].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Chinitsu))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Ryanpeikou))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Junchantaiyao))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Pinfu))); Assert.IsFalse(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Chiitoitsu))); Assert.IsFalse(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Honitsu))); Assert.IsFalse(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Chantaiyao))); }
public void Test_Chiitoi_Or_Ryanpeikou() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 1), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Character, 3), new TilePivot(FamilyPivot.Character, 7), new TilePivot(FamilyPivot.Character, 7), new TilePivot(FamilyPivot.Character, 8), new TilePivot(FamilyPivot.Character, 8), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Character, 9), new TilePivot(FamilyPivot.Circle, 4), new TilePivot(FamilyPivot.Circle, 4), }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.North, new TilePivot(FamilyPivot.Character, 2), isRon: true, isRiichi: true); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(2, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.IsNotNull(groupsOfYakus[1]); Assert.AreEqual(2, groupsOfYakus[0].Yakus.Count); Assert.AreEqual(2, groupsOfYakus[1].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Ryanpeikou))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Riichi))); Assert.IsTrue(groupsOfYakus[1].Yakus.Contains(YakuPivot.Get(YakuPivot.Chiitoitsu))); Assert.IsTrue(groupsOfYakus[1].Yakus.Contains(YakuPivot.Get(YakuPivot.Riichi))); }
public void Test_Chitoi_TanYao_Tsumo_DoubleRiichi_Ippatsu() { List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 2), new TilePivot(FamilyPivot.Character, 5), new TilePivot(FamilyPivot.Character, 5), new TilePivot(FamilyPivot.Character, 6), new TilePivot(FamilyPivot.Character, 6), new TilePivot(FamilyPivot.Bamboo, 4), new TilePivot(FamilyPivot.Bamboo, 4), new TilePivot(FamilyPivot.Bamboo, 8), new TilePivot(FamilyPivot.Bamboo, 8), new TilePivot(FamilyPivot.Circle, 5), new TilePivot(FamilyPivot.Circle, 5), new TilePivot(FamilyPivot.Circle, 8) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.East, new TilePivot(FamilyPivot.Circle, 8), isRon: false, isDoubleRiichi: true, isIppatsu: true); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(5, groupsOfYakus[0].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Chiitoitsu))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Tanyao))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.MenzenTsumo))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.DoubleRiichi))); Assert.IsTrue(groupsOfYakus[0].Yakus.Contains(YakuPivot.Get(YakuPivot.Ippatsu))); }
public void Test_DoubleYakuPai() { SetPivot openedSets = new SetPivot(new TilePivot(WindPivot.East), new TilePivot(WindPivot.East), new TilePivot(WindPivot.East)); List <TilePivot> tiles = new List <TilePivot> { new TilePivot(FamilyPivot.Bamboo, 4), new TilePivot(FamilyPivot.Bamboo, 5), new TilePivot(FamilyPivot.Bamboo, 6), new TilePivot(FamilyPivot.Bamboo, 5), new TilePivot(FamilyPivot.Bamboo, 6), new TilePivot(FamilyPivot.Bamboo, 7), new TilePivot(FamilyPivot.Circle, 3), new TilePivot(FamilyPivot.Circle, 3), new TilePivot(FamilyPivot.Circle, 1), new TilePivot(FamilyPivot.Circle, 2) }; tiles = tiles.OrderBy(x => _randomizer.Next()).ToList(); FullHandPivot handPivot = new FullHandPivot(tiles, WindPivot.East, WindPivot.East, new TilePivot(FamilyPivot.Circle, 3), openedSets: new List <SetPivot> { openedSets }); List <HandYakuListPivot> groupsOfYakus = handPivot.ComputeHandYakus(); Assert.IsNotNull(groupsOfYakus); Assert.AreEqual(1, groupsOfYakus.Count); Assert.IsNotNull(groupsOfYakus[0]); Assert.AreEqual(2, groupsOfYakus[0].Yakus.Count); Assert.IsTrue(groupsOfYakus[0].Yakus.All(y => y.Name == YakuPivot.Yakuhai)); }
private static void AsyncCompute(object sender, DoWorkEventArgs e) { var arguments = e.Argument as object[]; var handTiles = (List <TilePivot>)arguments[0]; var dominantWind = (WindPivot)arguments[1]; var seatWind = (WindPivot)arguments[2]; var latestTile = (TilePivot)arguments[3]; var draw = (DrawPivot)arguments[4]; Dictionary <int, List <SubstitutionGroup> > subsGroupByAwayIndex = new Dictionary <int, List <SubstitutionGroup> >(); // compute tile0 FullHandPivot hand0 = new FullHandPivot(handTiles, dominantWind, seatWind, latestTile); HandYakuListPivot handYakus = hand0.ComputeHandYakus()?.FirstOrDefault(); subsGroupByAwayIndex.Add(0, new List <SubstitutionGroup> { new SubstitutionGroup(handYakus) }); #region 1 tile away var handTileWithLast = new List <TilePivot>(handTiles) { latestTile }; List <TilePivot> availableTiles = draw.ComputeRemainingTiles(handTileWithLast); // gets yakus for each substitution combination var rawResultsArray = BackgroundHandlerForOneTileAway(dominantWind, seatWind, handTileWithLast, availableTiles, new List <TilePivot>()); var rawResults = rawResultsArray.Item1; subsGroupByAwayIndex.Add(1, rawResults.OrderByDescending(x => x.Probability).ToList()); // per discard solutions var discardprobabilities = new Dictionary <TilePivot, double>(); /* * TilePivot currentDiscard = null; * double probability = 0; * foreach (var r in rawResults.OrderBy(x => x.SubstitutionSequences.First().Substitutions.First().Subbed)) * { * if (currentDiscard != null && !r.Item1.Subbed.Equals(currentDiscard)) * { * discardprobabilities.Add(currentDiscard, Math.Round(probability * 100, 3)); * probability = 0; * } * currentDiscard = r.Item1.Subbed; * probability += availableTiles.Count(_ => _.Equals(currentDiscard)) / (double)availableTiles.Count; * } * if (currentDiscard != null) * { * discardprobabilities.Add(currentDiscard, Math.Round(probability * 100, 3)); * }*/ #endregion 1 tile away #region 2 tiles away // gets yakus for each substitution combination var rawResults2Away = new List <SubstitutionGroup>(); var firstRoundSubstitutionsList = rawResultsArray.Item2; foreach (var firstSubstitution in firstRoundSubstitutionsList) { var usedTiles = new List <TilePivot>(handTiles) { latestTile }; usedTiles.Add(firstSubstitution.Subber); var availableTilesAway2 = draw.ComputeRemainingTiles(usedTiles); usedTiles.Remove(firstSubstitution.Subbed); rawResultsArray = BackgroundHandlerForOneTileAway(dominantWind, seatWind, usedTiles, availableTilesAway2, new List <TilePivot> { firstSubstitution.Subbed }); var subGroupList = rawResultsArray.Item1; foreach (var subGroup in rawResultsArray.Item1) { subGroup.AddSubstitutionToEachSequences(firstSubstitution); rawResults2Away.Add(subGroup); } } var resultsAway2WithoutDuplicates = new List <SubstitutionGroup>(); foreach (var r in rawResults2Away) { var match = resultsAway2WithoutDuplicates.FirstOrDefault(ra => ra.Yakus.Equals(r.Yakus)); if (match == null) { resultsAway2WithoutDuplicates.Add(r); } else { foreach (var seq in r.SubstitutionSequences) { match.AddSubstitutionSequence(seq); } } } subsGroupByAwayIndex.Add(2, resultsAway2WithoutDuplicates.OrderByDescending(x => x.Probability).ToList()); #endregion 2 tiles away e.Result = new object[] { subsGroupByAwayIndex, discardprobabilities }; }