Exemple #1
0
        public void Unit_YamaTsumoTest()
        {
            Yama testYama = new Yama();

            Assert.AreEqual(testYama.GetRestYamaNum(), FIRST_YAMA_LENGTH);
            foreach (var omote in testYama.GetDoraMarkerStrings())
            {
                Debug.WriteLine("Dora = " + omote);
            }

            while (testYama.GetRestYamaNum() > 0)
            {
                var tsumoObj = testYama.DoTsumo();
                Debug.WriteLine(tsumoObj.PaiString);
            }
        }
Exemple #2
0
        private string CalcMinShantenPai(int mypositionId, List<Tehai> tehais, List<Kawa> kawas, Field field, Yama yama)
        {
            int fordebug = -1;
            int[] fordebug2 = new int[0];
            try
            {
                var restNum = Enumerable.Repeat(4, MJUtil.LENGTH_SYU_ALL).ToArray();
                tehais[mypositionId].tehai.ForEach(pai => restNum[pai.PaiNumber]--);
                tehais.ForEach(player => player.furos.ForEach(furo => furo.consumed.ForEach(pai => restNum[pai.PaiNumber]--)));
                kawas.ForEach(player => player.discards.ForEach(pai => restNum[pai.PaiNumber]--));
                yama.GetDoraMarkerStrings().ForEach(paiStr => restNum[PaiConverter.STRING_TO_ID[paiStr]]--);

                var kokushiShanten = shantenCalclator.CalcKokushiShanten(tehais[mypositionId].tehaiString);
                if (kokushiShanten > 3)
                {
                    shantenCalclator.SetUseKokushi(false);
                }

                var chitoitsuShanten = shantenCalclator.CalcChitoitsuShanten(tehais[mypositionId].tehaiString);
                if (chitoitsuShanten <= 1)
                {
                    shantenCalclator.SetUseChitoitsu(true);
                }
                else
                {
                    shantenCalclator.SetUseChitoitsu(false);
                }

                var nowShanten = shantenCalclator.CalcShanten(tehais[mypositionId]);

                var validateMap = new Dictionary<int, int>();

                var dahaiCandidate = tehais[mypositionId].tehai;

                foreach (var pai in dahaiCandidate)
                {
                    if (validateMap.ContainsKey(pai.PaiNumber))
                    {
                        continue;
                    }

                    var tehaiIds = tehais[mypositionId].tehai.Select(e => e.PaiNumber).ToList();
                    var furoCount = tehais[mypositionId].furos.Count;
                    tehaiIds.Remove(pai.PaiNumber);

                    var validPai = 0;
                    var syuArray = Enumerable.Repeat(0, MJUtil.LENGTH_SYU_ALL).ToArray();
                    tehaiIds.ForEach(e => syuArray[e]++);

                    for (int i = 0; i < MJUtil.LENGTH_SYU_ALL; i++)
                    {
                        if (restNum[i] <= 0)
                        {
                            continue;
                        }

                        fordebug = i;
                        fordebug2 = syuArray;

                        syuArray[i]++;
                        var tempShanten = shantenCalclator.CalcShantenWithFuro(syuArray, furoCount);
                        if (tempShanten < nowShanten)
                        {
                            validPai += restNum[i];
                        }
                        syuArray[i]--;
                    }
                    validateMap.Add(pai.PaiNumber, validPai);
                }

                shantenCalclator.SetUseKokushi(true);
                shantenCalclator.SetUseChitoitsu(true);

                var bestValidNumber = validateMap.OrderByDescending(e => e.Value).First().Value;
                var dahaiCandidateMap = validateMap.Where(e => e.Value == bestValidNumber);

                var bestNumber = -1;// temp value
                if (dahaiCandidateMap.Any(e => e.Key >= MJUtil.LENGTH_SYU_ONE_NUMBERS * 3))
                {
                    bestNumber = dahaiCandidateMap.Last().Key;
                }
                else if (dahaiCandidateMap.Any(e => e.Key % 9 == 0 || e.Key % 9 == 8))
                {
                    bestNumber = dahaiCandidateMap.Where(e => e.Key % 9 == 0 || e.Key % 9 == 8).Last().Key;
                }
                else if (dahaiCandidateMap.Any(e => e.Key % 9 == 1 || e.Key % 9 == 7))
                {
                    bestNumber = dahaiCandidateMap.Where(e => e.Key % 9 == 1 || e.Key % 9 == 7).Last().Key;
                }
                else if (dahaiCandidateMap.Any(e => e.Key % 9 == 2 || e.Key % 9 == 6))
                {
                    bestNumber = dahaiCandidateMap.Where(e => e.Key % 9 == 2 || e.Key % 9 == 6).Last().Key;
                }
                else if (dahaiCandidateMap.Any(e => e.Key % 9 == 3 || e.Key % 9 == 5))
                {
                    bestNumber = dahaiCandidateMap.Where(e => e.Key % 9 == 3 || e.Key % 9 == 5).Last().Key;
                }
                else
                {
                    bestNumber = dahaiCandidateMap.Last().Key;
                }

                var paiString = tehais[mypositionId].tehai.Where(e => e.PaiNumber == bestNumber).First().PaiString;

                var tehaiString = tehais[mypositionId].ToString();
                return paiString;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                Debug.WriteLine(fordebug);
                fordebug2.ToList().ForEach(v => Debug.Write(v+","));

                return "";
            }
        }