public TurnContext Reroll(BoardContext board, IList <int> dicesToReroll) { var newDices = Dices.ToList(); //copy foreach (int diceToReroll in dicesToReroll) { if (newDices.Contains(diceToReroll)) { newDices.RemoveAt(newDices.LastIndexOf(diceToReroll)); } else { throw new System.FormatException(); } } newDices.AddRange(Enumerable.Range(0, 4 - newDices.Count).Select(_ => RollDice)); var newDicesArray = newDices.ToArray(); return(new TurnContext( currentPlayer: CurrentPlayer, dices: newDicesArray, remainReroll: dicesToReroll.Count - 1, remainMove: dicesToReroll.Count, isStuckInThisTurn: board.IsStuck(CurrentPlayer, newDicesArray) )); }
public TurnContext Reroll(IList <int> dicesToReroll) { var newDices = Dices.ToList(); //copy foreach (int diceToReroll in dicesToReroll) { if (newDices.Contains(diceToReroll)) { newDices.RemoveAt(newDices.LastIndexOf(diceToReroll)); } else { throw new System.FormatException(); } } newDices.AddRange(Enumerable.Range(0, 2 - newDices.Count).Select(_ => RollDice)); return(new TurnContext( currentPlayer: CurrentPlayer, dices: newDices.ToArray(), remainReroll: newDices[0] == newDices[1] ? dicesToReroll.Count : dicesToReroll.Count - 1 )); }