Ejemplo n.º 1
0
        public dynamic AutoPlay()
        {
            if (m_Game.GetGameState() != "PlayingCards")
            {
                return(null);
            }

            var lastPlayerName    = m_Game.GetLastPlayerName();
            var currentPlayerName = m_Game.GetCurrentTurnPlayerName();

            if (string.IsNullOrEmpty(currentPlayerName))
            {
                return(null);
            }
            var currentPlayer = m_Game.FindPlayer(currentPlayerName);

            var okay = false;

            if (string.IsNullOrEmpty(lastPlayerName))
            {
                var play = BigTwoLogic.TryToGiveOutBest(currentPlayer.CurrentHand.GetCards(), 0, "3D");
                if (play == null || play.Count <= 0)
                {
                    return(null);
                }

                okay = m_Game.AcceptPlay(currentPlayerName, play);
            }
            else
            {
                if (m_Game.CanPass(currentPlayerName))
                {
                    okay = m_Game.AcceptPlay(currentPlayerName, new List <int>());
                }
                else
                {
                    if (lastPlayerName == currentPlayerName)
                    {
                        var play = BigTwoLogic.TryToGiveOutBest(currentPlayer.CurrentHand.GetCards(), 0);
                        okay = m_Game.AcceptPlay(currentPlayerName, play);
                    }
                    else
                    {
                        var lastPlay = m_Game.GetLastPlay();
                        var play     = BigTwoLogic.TryToGiveOutBest(currentPlayer.CurrentHand.GetCards(), lastPlay.Count);
                        if (play == null || play.Count <= 0)
                        {
                            okay = m_Game.AcceptPlay(currentPlayerName, new List <int>());
                        }
                        else
                        {
                            okay = m_Game.AcceptPlay(currentPlayerName, play);
                        }
                    }
                }
            }

            if (okay == false)
            {
                return(null);
            }
            else
            {
                return(new
                {
                    okay = okay,
                    turns = okay ? m_Game.GetCurrentTurns() : 0,
                    player = okay && currentPlayer != null?m_Game.GetCurrentTurnPlayerName() : "",
                                 cards = okay && currentPlayer != null?currentPlayer.CurrentHand.ToString() : ""
                });
            }
        }