Inheritance: RoleGame
        private void InitGame()
        {
            if (NetworkClient != null)
            {
                var pkt = NetworkClient.Receive();
                Trace.Assert(pkt is ConnectionResponse);
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.Pk1v1) _game = new Pk1v1Game();
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.RoleGame) _game = new RoleGame();
                
                if (pkt is ConnectionResponse)
                {
                    _game.Settings = ((ConnectionResponse)pkt).Settings;
                    NetworkClient.SelfId = ((ConnectionResponse)pkt).SelfId;
                }
                else
                {
                    return;
                }
            }
            if (hasSeed != null)
            {
                _game.RandomGenerator = new Random((int)hasSeed);
                _game.IsPanorama = true;
            }
            Game.CurrentGameOverride = _game;
            if (_networkClient == null)
            {
                _game.Settings = new GameSettings();
                _game.Settings.Accounts = new List<Account>();
                _game.Settings.NumberOfDefectors = 1;
                _game.Settings.NumHeroPicks = 3;
                _game.Settings.DualHeroMode = false;
                _game.Settings.TotalPlayers = 8;
                _game.Settings.TimeOutSeconds = 15;
                for (int i = 0; i < 8; i++)
                {
                    _game.Settings.Accounts.Add(new Account() { UserName = "******" + i });
                }

            }

            ClientNetworkProxy activeClientProxy = null;
            if (NetworkClient != null)
            {
                for (int i = 0; i < _game.Settings.TotalPlayers; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }

            if (NetworkClient != null)
            {
                _game.GameClient = NetworkClient;
            }
            else
            {
                _game.GlobalProxy = new GlobalDummyProxy();
            }
            GameViewModel gameModel = new GameViewModel();
            gameModel.Game = _game;
            if (NetworkClient != null)
            {
                gameModel.MainPlayerSeatNumber = NetworkClient.SelfId >= _game.Players.Count ? 0 : NetworkClient.SelfId;
            }
            else
            {
                gameModel.MainPlayerSeatNumber = 0;
            }

            _game.NotificationProxy = gameView;
            List<ClientNetworkProxy> inactive = new List<ClientNetworkProxy>();
            for (int i = 0; i < _game.Players.Count; i++)
            {
                var player = gameModel.PlayerModels[i].Player;
                if (NetworkClient != null)
                {
                    var proxy = new ClientNetworkProxy(
                                new AsyncProxyAdapter(gameModel.PlayerModels[i]), NetworkClient);
                    proxy.HostPlayer = player;
                    proxy.TimeOutSeconds = _game.Settings.TimeOutSeconds;
                    if (i == 0)
                    {
                        activeClientProxy = proxy;
                    }
                    else
                    {
                        inactive.Add(proxy);
                    }
                    _game.UiProxies.Add(player, proxy);
                }
                else
                {
                    var proxy = new AsyncProxyAdapter(gameModel.PlayerModels[i]);
                    _game.UiProxies.Add(player, proxy);
                }
            }
            if (NetworkClient != null)
            {
                _game.ActiveClientProxy = activeClientProxy;
                _game.GlobalProxy = new GlobalClientProxy(_game, activeClientProxy, inactive);
                _game.UpdateUiAttachStatus();
            }
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                gameView.DataContext = gameModel;
                if (BackwardNavigationService != null && !ViewModelBase.IsDetached)
                {
                    BackwardNavigationService.Navigate(this);
                    BackwardNavigationService = null;
                }
            });
            _game.Run();
        }
            public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
            {
                Pk1v1Game game = Game.CurrentGame as Pk1v1Game;

                foreach (Player pp in game.Players)
                {
                    game.HandCardVisibility.Add(pp, new List <Player>()
                    {
                        pp
                    });
                }

                // Put the whole deck in the dealing deck

                foreach (Card card in game.CardSet)
                {
                    // We don't want hero cards
                    if (card.Type is HeroCardHandler)
                    {
                        game.Decks[DeckType.Heroes].Add(card);
                        card.Place = new DeckPlace(null, DeckType.Heroes);
                    }
                    else if (card.Type is RoleCardHandler)
                    {
                        card.Place = new DeckPlace(null, RoleDeckType);
                    }
                    else
                    {
                        game.Decks[DeckType.Dealing].Add(card);
                        card.Place = new DeckPlace(null, DeckType.Dealing);
                    }
                }
                if (game.Players.Count == 0)
                {
                    return;
                }
                // Await role decision
                int seed = DateTime.Now.Millisecond;

                game.Seed = seed;
                Trace.TraceError("Seed is {0}", seed);
                if (game.RandomGenerator == null)
                {
                    game.RandomGenerator = new Random(seed);
                    Random random = game.RandomGenerator;
                }
                int  selectorId  = game.RandomGenerator.Next(2);
                int  rulerId     = 0;
                bool selectorIs0 = selectorId == 0;

                game.SyncConfirmationStatus(ref selectorIs0);
                if (selectorIs0)
                {
                    selectorId = 0;
                }
                else
                {
                    selectorId = 1;
                }
                int wantToBeRuler = 0;

                game.Players[selectorId].AskForMultipleChoice(new MultipleChoicePrompt("BeRuler"), OptionPrompt.YesNoChoices, out wantToBeRuler);
                rulerId = 1 - (wantToBeRuler ^ selectorId);
                Trace.Assert(rulerId >= 0 && rulerId <= 1);
                Trace.Assert(game.Players.Count == 2);
                if (rulerId == 0)
                {
                    game.AvailableRoles.Add(Role.Ruler);
                    game.AvailableRoles.Add(Role.Defector);
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Ruler));
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Defector));
                }
                else
                {
                    game.AvailableRoles.Add(Role.Defector);
                    game.AvailableRoles.Add(Role.Ruler);
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Defector));
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Ruler));
                }

                List <CardsMovement> moves = new List <CardsMovement>();
                int i = 0;

                foreach (Player p in game.Players)
                {
                    CardsMovement move = new CardsMovement();
                    move.Cards = new List <Card>()
                    {
                        game.Decks[null, RoleDeckType][i]
                    };
                    move.To = new DeckPlace(p, RoleDeckType);
                    moves.Add(move);
                    i++;
                }
                game.MoveCards(moves, null, GameDelays.GameStart);
                GameDelays.Delay(GameDelays.RoleDistribute);
                //hero allocation
                game.Shuffle(game.Decks[DeckType.Heroes]);

                List <Card> heroPool = new List <Card>();
                int         toDraw   = 12;

                for (int rc = 0; rc < toDraw; rc++)
                {
                    game.SyncImmutableCardAll(game.Decks[DeckType.Heroes][rc]);
                    heroPool.Add(game.Decks[DeckType.Heroes][rc]);
                }
                game.SyncImmutableCards(game.Players[rulerId], heroPool);
                DeckType tempHero = DeckType.Register("TempHero");

                game.Decks[null, tempHero].AddRange(heroPool);
                Trace.TraceInformation("Ruler is {0}", rulerId);
                game.Players[rulerId].Role     = Role.Ruler;
                game.Players[1 - rulerId].Role = Role.Defector;

                List <int> heroSelectCount = new List <int>()
                {
                    1, 2, 2, 2, 2, 2, 1
                };
                int seq  = 0;
                int turn = rulerId;
                Dictionary <int, int> map = new Dictionary <int, int>();

                map.Add(0, 0);
                map.Add(1, 1);
                var deckPlace = new DeckPlace(null, tempHero);

                game.NotificationProxy.NotifyTwoSidesCardPickStart(new CardChoicePrompt("Pk1v1.InitHeroPick.Init"), deckPlace, map, 6, 6);
                while (heroSelectCount.Count > seq)
                {
                    List <DeckPlace> sourceDecks = new List <DeckPlace>();
                    sourceDecks.Add(new DeckPlace(null, tempHero));
                    List <string> resultDeckNames = new List <string>();
                    resultDeckNames.Add("HeroChoice");
                    List <int> resultDeckMaximums = new List <int>();
                    int        numHeroes          = heroSelectCount[seq];
                    resultDeckMaximums.Add(numHeroes);
                    List <List <Card> > answer;
                    var newVer = new Pk1v1HeroChoiceVerifier(1, seq + 1 == heroSelectCount.Count ? -(Game.CurrentGame.Settings.TimeOutSeconds - 2) : 0);
                    for (int j = 0; j < numHeroes; j++)
                    {
                        var option = new AdditionalCardChoiceOptions();
                        option.IsTwoSidesCardChoice = true;
                        if (!game.UiProxies[game.Players[turn]].AskForCardChoice(new CardChoicePrompt("Pk1v1.InitHeroPick", numHeroes), sourceDecks, resultDeckNames, resultDeckMaximums, newVer, out answer, option))
                        {
                            answer = new List <List <Card> >();
                            answer.Add(new List <Card>());
                            answer[0].Add(game.Decks[null, tempHero].First(h => !answer[0].Contains(h) && !game.Decks[game.Players[turn], SelectedHero].Contains(h) && !game.Decks[game.Players[1 - turn], SelectedHero].Contains(h)));
                        }
                        game.Decks[game.Players[turn], SelectedHero].AddRange(answer[0]);
                        game.NotificationProxy.NotifyTwoSidesCardPicked(turn == 0, game.Decks[deckPlace].IndexOf(answer[0][0]));
                    }
                    seq++;
                    turn = 1 - turn;
                }
                GameDelays.Delay(GameDelays.Pk1v1EndOfSelection);
                game.NotificationProxy.NotifyTwoSidesCardPickEnd();
                game.Shuffle(game.Decks[null, DeckType.Dealing]);

                Player current = game.CurrentPlayer = game.Players[1 - rulerId];

                Dictionary <Player, List <Card> > restDraw = new Dictionary <Player, List <Card> >();
                List <Player> players = new List <Player>(game.Players);

                foreach (Player p in players)
                {
                    restDraw.Add(p, new List <Card>(game.Decks[p, SelectedHero]));
                }

                var heroSelection  = new Dictionary <Player, List <Card> >();
                int numberOfHeroes = Game.CurrentGame.Settings.DualHeroMode ? 2 : 1;

                game.GlobalProxy.AskForHeroChoice(restDraw, heroSelection, numberOfHeroes, new RequireCardsChoiceVerifier(numberOfHeroes, false, true));

                bool notUsed = true;

                game.SyncConfirmationStatus(ref notUsed);

                foreach (var pxy in game.UiProxies)
                {
                    pxy.Value.Freeze();
                }

                for (int repeat = 0; repeat < numberOfHeroes; repeat++)
                {
                    foreach (Player p in players)
                    {
                        Card c;
                        int  idx;
                        //only server has the result
                        if (!game.IsClient)
                        {
                            idx = repeat;
                            if (heroSelection.ContainsKey(p))
                            {
                                c   = heroSelection[p][repeat];
                                idx = restDraw[p].IndexOf(c);
                            }
                            else
                            {
                                c = restDraw[p][idx];
                            }
                            if (game.GameServer != null)
                            {
                                foreach (Player player in game.Players)
                                {
                                    game.GameServer.SendPacket(player.Id, new StatusSync()
                                    {
                                        Status = idx
                                    });
                                }
                                game.GameServer.SendPacket(game.Players.Count, new StatusSync()
                                {
                                    Status = idx
                                });
                            }
                        }
                        // you are client
                        else
                        {
                            idx = (int)game.GameClient.Receive();
                            c   = restDraw[p][idx];
                        }
                        game.Decks[p, SelectedHero].Remove(c);
                        var h = (HeroCardHandler)c.Type;
                        Trace.TraceInformation("Assign {0} to player {1}", h.Hero.Name, p.Id);
                        var hero = h.Hero.Clone() as Hero;
                        foreach (var skill in new List <ISkill>(hero.Skills))
                        {
                            if (skill.IsRulerOnly)
                            {
                                hero.Skills.Remove(skill);
                            }
                        }

                        if (repeat == 0)
                        {
                            p.Hero       = hero;
                            p.Allegiance = hero.Allegiance;
                            p.IsMale     = hero.IsMale;
                            p.IsFemale   = !hero.IsMale;
                            if (numberOfHeroes == 1)
                            {
                                p.MaxHealth = hero.MaxHealth;
                                p.Health    = hero.MaxHealth;
                            }
                        }
                        else if (repeat == 1)
                        {
                            p.Hero2 = hero;
                            int aveHp = (p.Hero2.MaxHealth + p.Hero.MaxHealth) / 2;
                            p.MaxHealth = aveHp;
                            p.Health    = aveHp;
                        }
                    }
                }

                foreach (var rm in heroPool)
                {
                    game.Decks[DeckType.Heroes].Remove(rm);
                }
                foreach (var st in game.Decks[game.Players[0], SelectedHero])
                {
                    st.Place = new DeckPlace(game.Players[0], SelectedHero);
                }
                foreach (var st in game.Decks[game.Players[1], SelectedHero])
                {
                    st.Place = new DeckPlace(game.Players[1], SelectedHero);
                }
                game.Shuffle(game.Decks[DeckType.Heroes]);
                if (game.IsClient)
                {
                    foreach (var card in game.Decks[DeckType.Heroes])
                    {
                        card.Type = new UnknownHeroCardHandler();
                        card.Id   = Card.UnknownHeroId;
                    }
                }

                GameDelays.Delay(GameDelays.GameBeforeStart);

                Game.CurrentGame.NotificationProxy.NotifyGameStart();
                GameDelays.Delay(GameDelays.GameStart);
                GameDelays.Delay(GameDelays.GameStart);

                foreach (var pl in game.Players)
                {
                    StartGameDeal(game, pl);
                }
                foreach (var pl in game.Players)
                {
                    try
                    {
                        game.Emit(GameEvent.HeroDebut, new GameEventArgs()
                        {
                            Source = pl
                        });
                    }
                    catch (EndOfTurnException)
                    {
                        game.CurrentPlayer = game.Players[1 - game.CurrentPlayer.Id];
                    }
                }


                foreach (var act in game.AlivePlayers)
                {
                    game.Emit(GameEvent.PlayerGameStartAction, new GameEventArgs()
                    {
                        Source = act
                    });
                }

                //redo this: current player might change
                current = game.CurrentPlayer;
                while (true)
                {
                    GameEventArgs args = new GameEventArgs();
                    args.Source = current;
                    game.CurrentPhaseEventIndex = 0;
                    game.CurrentPhase           = TurnPhase.BeforeStart;
                    game.CurrentPlayer          = current;
                    game.Emit(GameEvent.DoPlayer, args);
                    current = game.NextAlivePlayer(current);
                }
            }