/// <summary>
        /// Routine that changes the owner of a tile based on indices stored in TilesToTurn list.
        /// </summary>
        private void DoTurnTiles()
        {
            PlayerModel player      = null;;
            bool        playerFound = false;

            foreach (KeyValuePair <int, ClientModel> model in CurrentPlayersList)
            {
                ReversiClientModel reversiClientModel = (ReversiClientModel)model.Value;

                if (reversiClientModel.ClientPlayer.IdType == CurrentPlayer)
                {
                    player      = reversiClientModel.ClientPlayer;
                    playerFound = true;
                }
            }

            // If we didnt find the player, return
            if (!playerFound)
            {
                return;
            }

            foreach (int index in TilesToTurn)
            {
                Gameboard.Squares[index].Piece.Owner = player;

                //// TODO: For each tile being flipped...play a sounds
                //ReversiSounds.PlaySounds(GameSounds.SOUND_FLIPTILE);
            }

            // Now clear the tiles to turn array since all the moves have been made
            TilesToTurn.Clear();
        }
        /// <summary>
        /// Make a list of the current player sockets for the game.
        /// </summary>
        /// <returns></returns>
        public List <TcpClient> GetPlayersSocketList()
        {
            List <TcpClient> list = new List <TcpClient>();

            foreach (KeyValuePair <int, ClientModel> item in CurrentPlayersList)
            {
                ReversiClientModel model = (ReversiClientModel)item.Value;
                list.Add(model.ConnectionSocket);
            }

            return(list);
        }
        public ReversiClientModel(ClientModel clientModel, string name) : base(clientModel)
        {
            ReversiClientModel model = (ReversiClientModel)clientModel;

            Game         = null;
            LastMove     = new GameMoveModel();
            ClientPlayer = new PlayerModel(model.ClientPlayer.PlayerId, model.ClientPlayer.IdType, name);

            this.ClientProcess     = clientModel.ClientProcess;
            this.ClientMainThread  = clientModel.ClientMainThread;
            this.TimeConnectedWhen = DateTime.Now;
        }
        /// <summary>
        /// Utility function that displays the info
        /// about the players of the game.
        /// </summary>
        /// <returns></returns>
        public string DisplayGamePlayers()
        {
            string str = string.Empty;

            str += "----- PLAYER INFO -----\n";
            foreach (KeyValuePair <int, ClientModel> item in CurrentPlayersList)
            {
                ReversiClientModel model = (ReversiClientModel)item.Value;
                str += model.ClientPlayer.PlayerId + "   " + model.ClientPlayer.Name + "    " +
                       model.ClientPlayer.IdType + "\n";
            }

            return(str);
        }
        /// <summary>
        /// Primary routine for a player to make a move
        /// </summary>
        /// <param name="index">the index of the move being made</param>
        internal bool MakePlayerMove(int index)
        {
            PlayerModel player      = null;;
            bool        playerFound = false;

            foreach (KeyValuePair <int, ClientModel> model in CurrentPlayersList)
            {
                ReversiClientModel reversiClientModel = (ReversiClientModel)model.Value;

                if (reversiClientModel.ClientPlayer.IdType == CurrentPlayer)
                {
                    player      = reversiClientModel.ClientPlayer;
                    playerFound = true;
                    break;
                }
            }

            if ((player == null) || (playerFound == false))
            {
                return(false);
            }

            bool placementIsValid = ValidateTilePlacement(index, CurrentPlayer);

            if (placementIsValid)
            {
                // Add a new game piece at the location
                GamePieceModel piece = new GamePieceModel(Pieceshapes.Ellipse, player);
                Gameboard.AddPiece(index, piece);

                // Capture the opponents tiles
                DoTurnTiles();

                // Reset the tiles to be turned array
                TilesToTurn.Clear();
                return(true);
            }

            return(false);
            //MessageBox.Show(Gameboard.DrawGameboard() + "\nCurrent Player: " + CurrentPlayer.IDType + " : " + CurrentPlayer.Name);
        }