Ejemplo n.º 1
0
        /// <summary>
        ///     Consider new dices rolled.
        /// </summary>
        /// <param name="dices">List of dices values.</param>
        /// <returns>Indices of dices to keep, empty if intending to score.</returns>
        private List <int> ConsiderDices(List <int> dices)
        {
            var diceIndices     = new List <int>();
            var lastRolledDices = new List <Dice>();

            currentTurnState.Attempt++;
            for (var i = 0; i < dices.Count; i++)
            {
                currentTurnState.Dices[i].Value = dices[i];
                // this dice is not kept yet
                if (!currentTurnState.Dices[i].Kept)
                {
                    lastRolledDices.Add(currentTurnState.Dices[i]);
                }
            }

            var currentTotalScore = currentTurnState.Score;
            var split             = Scoring.SplitDicesByValue(lastRolledDices);

            foreach (var diceValue in split.Keys)
            {
                // keep all ones and fives
                if (diceValue == 1 || diceValue == 5)
                {
                    diceIndices.AddRange(FindDiceByValueSendableIndices(diceValue));
                }
                else
                {
                    if (Scoring.ComputeSameDicesScore(diceValue, split[diceValue]) > 0)
                    {
                        diceIndices.AddRange(FindDiceByValueSendableIndices(diceValue));
                    }
                }

                currentTotalScore += Scoring.ComputeSameDicesScore(diceValue, split[diceValue]);
            }

            lastKeptDices = new List <Dice>();
            foreach (var diceIndex in diceIndices)
            {
                lastKeptDices.Add(currentTurnState.Dices[diceIndex - 1]);
            }
            currentAction =
                currentTotalScore < 350 ||
                lastKeptDices.Count + currentTurnState.Dices.FindAll(dice => dice.Kept).Count == 6
                    ? PlayerAction.Keep
                    : PlayerAction.Score;

            return(diceIndices);
        }