private bool AutoPlay()
        {
            var lastPlay          = m_Game.GetLastPlay();
            var lastPlayerName    = m_Game.GetLastPlayerName();
            var currentPlayerName = m_Game.GetCurrentTurnPlayerName();

            if (string.IsNullOrEmpty(currentPlayerName) || currentPlayerName == "You")
            {
                return(false);
            }

            var currentPlayer = m_Game.FindPlayer(currentPlayerName);

            if (currentPlayer == null)
            {
                return(false);
            }

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

                return(m_Game.AcceptPlay(currentPlayerName, play));
            }
            else
            {
                if (lastPlayerName == currentPlayerName)
                {
                    var play = BigTwoLogic.TryToGiveOutBest(currentPlayer.CurrentHand.GetCards(), 0);
                    return(m_Game.AcceptPlay(currentPlayerName, play));
                }
                else
                {
                    var play = BigTwoLogic.TryToGiveOutBest(currentPlayer.CurrentHand.GetCards(), lastPlay.Count);
                    if (play == null || play.Count <= 0)
                    {
                        return(m_Game.AcceptPlay(currentPlayerName, new List <int>()));
                    }
                    else
                    {
                        var playCards = currentPlayer.CurrentHand.GetCards(play);
                        if (BigTwoLogic.CheckBetterCards(playCards, lastPlay))
                        {
                            return(m_Game.AcceptPlay(currentPlayerName, play));
                        }
                        else
                        {
                            return(m_Game.AcceptPlay(currentPlayerName, new List <int>()));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public dynamic AcceptPlay(dynamic play)
        {
            string     playerName  = play.player;
            List <int> cardIndexes = play.cards;
            var        player      = m_Game.FindPlayer(m_Game.GetCurrentTurnPlayerName());
            var        okay        = m_Game.AcceptPlay(playerName, cardIndexes);

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