Ejemplo n.º 1
0
        /// <summary>
        /// Can a meld be added to the current accumulator?
        /// </summary>
        private bool CanAddMeld(int index, Mentsu mentsu)
        {
            if (index > TypesInSuit - mentsu.Stride)
            {
                return(false);
            }
            var max = TilesPerType - mentsu.Amount;

            return(Accumulator.Skip(index).Take(mentsu.Stride).All(i => i <= max));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates all possible combinations of used tiles for a number of melds in a single suit by adding a specific meld.
        /// </summary>
        private IEnumerable <Combination> Create(int remainingMelds, int currentIndex, Mentsu mentsu)
        {
            var indices     = Enumerable.Range(currentIndex, TypesInSuit - currentIndex);
            var freeIndices = indices.Where(i => CanAddMeld(i, mentsu));

            foreach (var index in freeIndices)
            {
                AddToAccumulator(index, mentsu.Stride, mentsu.Amount);
                foreach (var combination in Create(remainingMelds - 1, index))
                {
                    yield return(combination);
                }
                AddToAccumulator(index, mentsu.Stride, -mentsu.Amount);
            }
        }