Exemplo n.º 1
0
        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>()));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public dynamic GetCurrentGameData(bool detailed = false)
        {
            var currentPlay = m_Game.GetLastPlay();

            var lastTurnPlay       = m_Game.GetLastTurnPlay();
            var lastTurnPlayerName = m_Game.GetLastTurnPlayerName();

            var simpleHistory = lastTurnPlayerName + "=";

            if (lastTurnPlay != null && lastTurnPlay.Count > 0)
            {
                simpleHistory += BigTwoLogic.ToString(lastTurnPlay);
            }

            var data = new
            {
                play    = currentPlay != null && currentPlay.Count > 0 ? BigTwoLogic.ToString(currentPlay) : "",
                history = simpleHistory,
                last    = m_Game.GetLastPlayerName(),
                current = m_Game.GetCurrentTurnPlayerName(),
                state   = m_Game.GetGameState(),
                turns   = m_Game.GetCurrentTurns(),
                players = new List <string>(),
                scores  = new List <int>(),
                cards   = new List <string>(),
            };

            var gamePlayers = m_Game.GetPlayers();

            foreach (var gamePlayer in gamePlayers)
            {
                data.players.Add(gamePlayer.PlayerName);
                data.scores.Add(gamePlayer.GameScore);

                if (detailed)
                {
                    data.cards.Add(BigTwoLogic.EncodeCards(gamePlayer.CurrentHand.GetCards()));
                }
                else
                {
                    data.cards.Add(gamePlayer.CurrentHand.GetNumberOfCards().ToString());
                }
            }

            return(data);
        }