public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            // If we build a town or a city, make sure the next action (buildroad)
            // has OriginatingTownOrCity set. This is ignored for the third road
            // as required by Tournament Starting Rules.
            BuildTownAction buildTown = inGameAction as BuildTownAction;
            if (buildTown != null)
            {
                BuildRoadAction buildRoad3 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad3.OriginatingTownOrCity = buildTown.Location;
            }
            BuildCityAction buildCity = inGameAction as BuildCityAction;
            if (buildCity != null)
            {
                BuildRoadAction buildRoad2 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad2.OriginatingTownOrCity = buildCity.Location;
            }

            inGameAction.PerformTurnAction(game);

            // If the last road or ship has been built, add new gamephase action on the queue
            BuildRoadAction buildRoad = inGameAction as BuildRoadAction;
            BuildShipAction buildShip = inGameAction as BuildShipAction;
            if (buildRoad != null || buildShip != null)
            {
                if (game.ActionsQueue.Count == 0)
                {
                    game.ActionsQueue.Enqueue(new PlacementDoneAction() { Sender = 0 });
                }
                else
                {
                    // Next player is the player of the first action on the queue
                    game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue.Peek().Sender);
                }

            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            if (AllowedAction(action, game))
            {
                RollDiceAction rollDice = action as RollDiceAction;
                if (rollDice != null)
                {
                    rollDice.PerformTurnAction(game);

                    // When a volcano is rolled, expect player to roll dice for volcano
                    /*
                    if (rollDice.HexesAffected.OfType<VolcanoHex>().Count() > 0)
                    {
                        game.ActionsQueue.Enqueue(new RollVolcanoDiceAction()
                        {
                            GamePlayer = rollDice.GamePlayer,
                            VolcanosRolled = rollDice.HexesAffected.OfType<VolcanoHex>().ToList<VolcanoHex>()
                        });

                        // We expect another action, return current phase
                        return this;
                    }
                     */

                    // When a 7 is rolled, enqueue every player required to loose cards to do so
                    if (rollDice.Dice == 7)
                    {
                        // Add each player required to loose cards to the queue
                        foreach (int i in rollDice.LooserPlayers)
                        {
                            game.ActionsQueue.Enqueue(new LooseCardsAction()
                            {
                                GamePlayer = game.GetPlayer(i)
                            });
                        }

                        // Expect player to place robber/pirate and rob a player
                        game.ActionsQueue.Enqueue(new PlaceRobberPirateAction() { GamePlayer = action.GamePlayer });
                        game.ActionsQueue.Enqueue(new RobPlayerAction() { GamePlayer = action.GamePlayer });

                        // We have actions to be done, we should stay in this phase
                        return this;
                    }

                    // Any other number has been rolled.
                    // Proceed to trading phase
                    if (game.ActionsQueue.Count == 0)
                    {
                        return new TradingTurnPhase();
                    }
                    else
                    {
                        return this;
                    }
                }

                RobPlayerAction robPlayer = action as RobPlayerAction;
                if (robPlayer != null)
                {
                    robPlayer.PerformTurnAction(game);

                    // When finished robbing, advance phase to trading
                    return this;
                }
                // perform the action
                action.PerformTurnAction(game);
                EndTurnAction endTurn = action as EndTurnAction;
                if (endTurn != null)
                {
                    return new BuildTurnPhase(null);
                }

                // Return current state
                return this;
            }
            else
            // Action is not allowed in rollDice phase. Check if it is allowed in subsequent phases,
            // then return that phase
            {
                TradingTurnPhase trading = new TradingTurnPhase();
                BuildTurnPhase building = new BuildTurnPhase(trading);
                if (trading.AllowedAction(action, game))
                {
                    return trading;
                }
                if (building.AllowedAction(action, game))
                {
                    return building;
                }
                return null;
            }
        }
        /// <summary>
        /// Creates gamequeue for each player
        /// </summary>
        /// <param name="inGameAction"></param>
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            inGameAction.PerformTurnAction(game);

            RollDiceAction rollDice = inGameAction as RollDiceAction;
            if (rollDice != null)
            {
                // Check if a phase has ended. If the queue is empty, every player has rolled the dice.
                if (game.ActionsQueue.Count() == 0)
                {
                    // Make a list of rolls in this round
                    List<RollDiceAction> rolledDices = game.GameLog.GetCurrentRoundRolls(game);

                    // highroll dice number
                    int highRoll = (from rd in rolledDices select rd.Dice).Max();

                    // When starting player is not determined yet, repeat dice roll between winners until
                    // winner is detemined
                    if (game.GameLog.FirstPlayerIsDetermined(game))
                    {
                        // We have a starting player
                        int winnerID = rolledDices.Where(rd => rd.Dice == highRoll)
                                                                          .First()
                                                                          .Sender;

                        game.ActionsQueue.Enqueue(new StartingPlayerDeterminedAction()
                        {
                            // The starter of the placement/portplacement/turnactionsgamephase
                            PlayerID = winnerID,
                            // winning dice
                            DiceRoll = highRoll,
                            // Server will send this message
                            Sender = 0
                        });
                        return;
                    }
                    else
                    {
                        // Starting player is not determined. Notify players and update Game object
                        game.ActionsQueue.Enqueue(new RolledSameAction()
                        {
                            // Pass on the highest diceroll
                            HighRoll = highRoll,
                            // Server says dice rolled the same
                            Sender = 0
                        });

                        // Enqueue each highroller
                        foreach (RollDiceAction sameRoll in rolledDices.Where(rd => rd.Dice == highRoll))
                        {
                            game.ActionsQueue.Enqueue(new RollDiceAction() { GamePlayer = sameRoll.GamePlayer });
                        }

                        // First player is on turn
                        game.PlayerOnTurn = game.ActionsQueue.ElementAt(1).GamePlayer;
                        return;
                    }
                }

                // Next player should be the player next on the queue
                game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue
                    .OfType<RollDiceAction>()
                    .First()
                    .Sender);

            }
        }