public bool CheckHaiTypeOver9(Tehai tehai, Hai addHai) { if (!_game.isChiHou) { return(false); } if (tehai.getJyunTehaiCount() < Tehai.JYUN_TEHAI_LENGTH_MAX - 1) { return(false); } int[] checkId = { Hai.ID_WAN_1, Hai.ID_WAN_9, Hai.ID_PIN_1, Hai.ID_PIN_9, Hai.ID_SOU_1, Hai.ID_SOU_9, Hai.ID_TON, Hai.ID_NAN, Hai.ID_SYA, Hai.ID_PE, Hai.ID_HAKU, Hai.ID_HATSU, Hai.ID_CHUN }; int[] countNumber = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //length = 13 //手牌をコピーする Hai[] checkHais = tehai.getJyunTehai(); for (int i = 0; i < checkHais.Length; i++) { for (int j = 0; j < checkId.Length; j++) { if (checkHais[i].ID == checkId[j]) { countNumber[j]++; } } } for (int j = 0; j < checkId.Length; j++) { if (addHai.ID == checkId[j]) { countNumber[j]++; } } int totalHaiType = 0; for (int c = 0; c < countNumber.Length; c++) { if (countNumber[c] > 0) { totalHaiType++; } } return(totalHaiType >= 9); }
/// <summary> /// Calculate all hai's count in tehai. the 'tehai' should be sorted. /// </summary> public void setCounterFormat(Tehai tehai, Hai addHai) { _counterArr.Clear(); int addHaiNumKind = 0; bool set = true; if (addHai != null) { addHaiNumKind = addHai.NumKind; set = false; } Hai[] jyunTehais = tehai.getJyunTehai(); for (int i = 0; i < jyunTehais.Length;) { int jyunTehaiNumKind = jyunTehais[i].NumKind; // if the first one hai's NK is bigger than the addHai's, // add the addHai to _counterArr firstly, then re-check the first one(as no i++). if (set == false && jyunTehaiNumKind > addHaiNumKind) { _counterArr.Add(new HaiCounterInfo(addHaiNumKind, 1)); set = true; continue; } // in middle range of tehai there exsits one as the same to addHai _counterArr.Add(new HaiCounterInfo(jyunTehaiNumKind, 1)); if (set == false && jyunTehaiNumKind == addHaiNumKind) { _counterArr[_counterArr.Count - 1].count++; set = true; } // check if the after one(at i+1) is the same to current one at 'i' while (++i < jyunTehais.Length) { if (jyunTehaiNumKind == jyunTehais[i].NumKind) { _counterArr[_counterArr.Count - 1].count++; } else { break; } } } // the addHai is the biggest one. if (set == false) { _counterArr.Add(new HaiCounterInfo(addHaiNumKind, 1)); } for (int i = 0; i < _counterArr.Count; i++) { if (_counterArr[i].count > MENTSU_LENGTH_MAX) { _counterArr[i].count = MENTSU_LENGTH_MAX; } } }
// 打哪些牌可以立直. public bool tryGetReachHaiIndex(Tehai a_tehai, Hai tsumoHai, out List <int> haiIndexList) { haiIndexList = new List <int>(); // 鳴いている場合は、リーチできない。x //if( a_tehai.isNaki() ) // return false; /// find all reach-enabled hais in a_tehai, also the tsumoHai. _reachHaiList.Clear(); // As _jyunTehais won't sort automatically on new hais added, // so we can add tsumo hai directly to simplify the checks. Tehai tehai_copy = new Tehai(a_tehai); tehai_copy.addJyunTehai(tsumoHai); tehai_copy.Sort(); Hai[] jyunTehai = tehai_copy.getJyunTehai(); for (int i = 0; i < jyunTehai.Length; i++) { Hai haiTemp = tehai_copy.removeJyunTehaiAt(i); for (int id = Hai.ID_MIN; id <= Hai.ID_MAX; id++) { countFormat.setCounterFormat(tehai_copy, new Hai(id)); if (countFormat.calculateCombisCount(combis) > 0) { _reachHaiList.Add(new Hai(haiTemp)); break; } } tehai_copy.insertJyunTehai(i, haiTemp); } /// transfer to index list. if (_reachHaiList.Count > 0) { jyunTehai = a_tehai.getJyunTehai(); for (int i = 0; i < _reachHaiList.Count; i++) { for (int j = 0; j < jyunTehai.Length; j++) { if (jyunTehai[j].ID == _reachHaiList[i].ID && !haiIndexList.Contains(j)) { haiIndexList.Add(j); } } if (tsumoHai.ID == _reachHaiList[i].ID && !haiIndexList.Contains(jyunTehai.Length)) { haiIndexList.Add(jyunTehai.Length); } } haiIndexList.Sort(); return(true); } return(false); }