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
}