예제 #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>()));
                        }
                    }
                }
            }
        }
예제 #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);
        }
예제 #3
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() : ""
                });
            }
        }
예제 #4
0
        private void btnGive_Click(object sender, EventArgs e)
        {
            List <PictureBox> cardBoxes = new List <PictureBox>()
            {
                pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5,
                pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10,
                pictureBox11, pictureBox12, pictureBox13
            };

            if (m_Game.GetGameState() != "PlayingCards")
            {
                return;
            }

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

            if (currentPlayerName != "You")
            {
                return;
            }

            var player = m_Game.FindPlayer("You");

            if (string.IsNullOrEmpty(lastPlayerName) || lastPlay == null || lastPlay.Count <= 0)
            {
                var items = BigTwoLogic.TryToGiveOutBest(player.CurrentHand.GetCards(), 0, "3D");
                if (items == null || items.Count <= 0)
                {
                    LogMsg("No tips found");
                    return;
                }
                else
                {
                    for (var i = 0; i < cardBoxes.Count; i++)
                    {
                        if (items.IndexOf(i) >= 0)
                        {
                            cardBoxes[i].Top = POP_POS_Y;
                        }
                        else
                        {
                            cardBoxes[i].Top = BASE_POS_Y;
                        }
                    }
                }
            }
            else
            {
                var items = BigTwoLogic.TryToGiveOutBest(player.CurrentHand.GetCards(),
                                                         lastPlayerName == "You" ? 0 : lastPlay.Count);

                if (items == null || items.Count <= 0)
                {
                    LogMsg("You have to pass");
                    return;
                }
                else
                {
                    if (lastPlayerName == "You")
                    {
                        for (var i = 0; i < cardBoxes.Count; i++)
                        {
                            if (items.IndexOf(i) >= 0)
                            {
                                cardBoxes[i].Top = POP_POS_Y;
                            }
                            else
                            {
                                cardBoxes[i].Top = BASE_POS_Y;
                            }
                        }
                    }
                    else
                    {
                        var playCards = player.CurrentHand.GetCards(items);
                        if (BigTwoLogic.CheckBetterCards(playCards, lastPlay))
                        {
                            for (var i = 0; i < cardBoxes.Count; i++)
                            {
                                if (items.IndexOf(i) >= 0)
                                {
                                    cardBoxes[i].Top = POP_POS_Y;
                                }
                                else
                                {
                                    cardBoxes[i].Top = BASE_POS_Y;
                                }
                            }
                        }
                        else
                        {
                            LogMsg("You have to pass");
                            return;
                        }
                    }
                }
            }
        }