public static bool canChi(IEnumerable<Pai> tehai, Pai pai) { if (pai.Suit == Suit.Jihai) return false; tehai = tehai.Select(p => p.RemoveRed()); pai = pai.RemoveRed(); if (pai.Num >= 3 && tehai.Contains(pai - 2) && tehai.Contains(pai - 1)) return true; if (pai.Num >= 2 && pai.Num <= 8 && tehai.Contains(pai - 1) && tehai.Contains(pai + 1)) return true; if (pai.Num <= 7 && tehai.Contains(pai + 1) && tehai.Contains(pai + 2)) return true; return false; }
public static bool canKan(IEnumerable<Pai> tehai, Pai pai) { tehai = tehai.Select(p => p.RemoveRed()); pai = pai.RemoveRed(); return tehai.Count(p => p == pai) >= 3; }
public object onDahai(int actor, Pai pai, bool tsumogiri) { foreach (var component in components) component.onDahai(actor, pai, tsumogiri); if (actor == id) { tehai.Remove(pai); return Protocol.none(); } else { List<SelectionType> alternatives = new List<SelectionType>(); if ((actor + 1) % 4 == id && Algorithm.canChi(tehai, pai)) alternatives.Add(SelectionType.Chi); if (Algorithm.canPon(tehai, pai)) { Console.WriteLine(string.Join(", ", tehai.Select(p => p.ToString()).ToArray())); alternatives.Add(SelectionType.Pon); } if (Algorithm.canKan(tehai, pai)) alternatives.Add(SelectionType.Kan); if (Algorithm.canRon(tehai, pai)) alternatives.Add(SelectionType.Ron); if (!alternatives.Any()) { return Protocol.none(); } else { alternatives.Add(SelectionType.Pass); return window.Select2(alternatives).match<object>( (pai1, pai2) => Protocol.chi(id, actor, pai, new List<Pai> { pai1, pai2 }) , (pai1, pai2) => Protocol.pon(id, actor, pai, new List<Pai> { pai1, pai2 }) , () => Protocol.kan(id, actor, pai, tehai.FindAll(p => p.RemoveRed() == pai.RemoveRed())) , () => Protocol.hora(id, actor, pai) , () => Protocol.none() ); } } }