/// <summary> /// Executes all parts of a players turn /// 1. Allow the play of a development card before the dice are rolled /// 2. Roll the dice, hand out resources to all players, and move the robber if roll is 7 /// 3. Allow all actions according to the rules /// </summary> /// <param name="player">The player whose turn it is</param> private void TakeTurn(Player player) { var actions = new MainActions(player, this); player.Agent.BeforeDiceRoll(CurrentGamestate(), actions); int roll = RollDice(); actions.DieRoll(); Log(new RollLogEvent(player.Id, roll)); if (roll == 7) { //Discard if over 7 cards foreach (var p in players) { if (p.Resources.Count > 7) { var cards = p.Agent.DiscardCards(CurrentGamestate(p.Id), p.Resources.Count / 2); if (cards.Length != p.Resources.Count / 2) { //Clone, shuffle, take, convert cards = p.Resources.ToList().OrderBy(e => Guid.NewGuid()).Take(p.Resources.Count / 2).ToArray(); } foreach (var c in cards) { PayResource(p, c); } Log(new DiscardCardsLogEvent(p.Id, cards.ToList())); } } MoveRobber(player, CurrentGamestate()); } else { HandOutResources(roll); } var afterResourcesState = CurrentGamestate(); player.Agent.PerformTurn(afterResourcesState, actions); player.NewDevelopmentCards.Clear(); //Reset new development cards }
/// <summary> /// Executes all parts of a players turn /// 1. Allow the play of a development card before the dice are rolled /// 2. Roll the dice, hand out resources to all players, and move the robber if roll is 7 /// 3. Allow all actions according to the rules /// </summary> /// <param name="player">The player whose turn it is</param> private void TakeTurn(Player player) { var actions = new MainActions(player, this); player.Agent.BeforeDiceRoll(CurrentGamestate(), actions); int roll = RollDice(); actions.DieRoll(); Log(new RollLogEvent(player.Id,roll)); if (roll == 7) { //Discard if over 7 cards foreach (var p in players) { if (p.Resources.Count > 7) { var cards = p.Agent.DiscardCards(CurrentGamestate(p.Id), p.Resources.Count / 2); if (cards.Length != p.Resources.Count / 2) { //Clone, shuffle, take, convert cards = p.Resources.ToList().OrderBy(e => Guid.NewGuid()).Take(p.Resources.Count / 2).ToArray(); } foreach (var c in cards) { PayResource(p, c); } Log(new DiscardCardsLogEvent(p.Id,cards.ToList())); } } MoveRobber(player, CurrentGamestate()); } else { HandOutResources(roll); } var afterResourcesState = CurrentGamestate(); player.Agent.PerformTurn(afterResourcesState, actions); player.NewDevelopmentCards.Clear(); //Reset new development cards }