Exemplo n.º 1
0
        public void GetWinnerSingleTrump()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                40
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
                12
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p2", actual);
        }
Exemplo n.º 2
0
        public void GetWinnerDumpTractor2()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                12, 3, 3, 4, 4
            };
            trickState.ShowedCards["p2"] = new List <int> {
                40, 40, 45, 45, 13
            };
            trickState.ShowedCards["p3"] = new List <int> {
                19, 19, 20, 20, 21
            };
            trickState.ShowedCards["p4"] = new List <int> {
                12, 9, 9, 11, 11
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p1", actual);
        }
Exemplo n.º 3
0
        public void GetWinnerDumpPair3()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                1, 3, 3, 5, 5
            };
            trickState.ShowedCards["p2"] = new List <int> {
                40, 40, 53, 53, 50
            };
            trickState.ShowedCards["p3"] = new List <int> {
                18, 18, 20, 20, 21
            };
            trickState.ShowedCards["p4"] = new List <int> {
                49, 49, 39, 39, 50
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p2", actual);
        }
Exemplo n.º 4
0
        public void GetWinnerDumpSingle3()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                14, 15, 16, 17
            };
            trickState.ShowedCards["p2"] = new List <int> {
                40, 41, 42, 13
            };
            trickState.ShowedCards["p3"] = new List <int> {
                40, 41, 42, 39
            };
            trickState.ShowedCards["p4"] = new List <int> {
                44, 45, 46, 47
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p3", actual);
        }
Exemplo n.º 5
0
        public void GetWinnerDumpSingle2()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                52, 53
            };
            trickState.ShowedCards["p2"] = new List <int> {
                26, 39
            };
            trickState.ShowedCards["p3"] = new List <int> {
                51, 39
            };
            trickState.ShowedCards["p4"] = new List <int> {
                25, 1
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p1", actual);
        }
Exemplo n.º 6
0
        public void GetWinnerTractor3()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
                1, 1, 2, 2, 3, 3
            };
            trickState.ShowedCards["p2"] = new List <int> {
                40, 40, 45, 45, 48, 48
            };
            trickState.ShowedCards["p3"] = new List <int> {
                8, 8, 10, 10, 11, 11
            };
            trickState.ShowedCards["p4"] = new List <int> {
                53, 53, 52, 52, 25, 25
            };

            string actual = TractorRules.GetWinner(trickState);

            Assert.AreEqual("p1", actual);
        }
Exemplo n.º 7
0
        public void PlayerShowCards(CurrentTrickState currentTrickState)
        {
            string lastestPlayer = currentTrickState.LatestPlayerShowedCard();

            if (PlayersProxy[lastestPlayer] != null)
            {
                this.CurrentTrickState.ShowedCards[lastestPlayer] = currentTrickState.ShowedCards[lastestPlayer];
                string cardsString = "";
                foreach (var card in this.CurrentTrickState.ShowedCards[lastestPlayer])
                {
                    cardsString += card.ToString() + " ";
                }
                log.Debug("Player " + lastestPlayer + " showed cards: " + cardsString);
                //更新每个用户手中的牌在SERVER
                foreach (int card in this.CurrentTrickState.ShowedCards[lastestPlayer])
                {
                    this.CurrentHandState.PlayerHoldingCards[lastestPlayer].RemoveCard(card);
                }
                //回合结束
                if (this.CurrentTrickState.AllPlayedShowedCards())
                {
                    this.CurrentTrickState.Winner = TractorRules.GetWinner(this.CurrentTrickState);
                    if (!string.IsNullOrEmpty(this.CurrentTrickState.Winner))
                    {
                        if (
                            !this.CurrentGameState.ArePlayersInSameTeam(CurrentHandState.Starter,
                                                                        this.CurrentTrickState.Winner))
                        {
                            CurrentHandState.Score += currentTrickState.Points;
                            UpdatePlayersCurrentHandState();
                        }


                        log.Debug("Winner: " + this.CurrentTrickState.Winner);
                    }

                    UpdatePlayerCurrentTrickState();

                    CurrentHandState.LeftCardsCount -= currentTrickState.ShowedCards[lastestPlayer].Count;

                    //开始新的回合
                    if (this.CurrentHandState.LeftCardsCount > 0)
                    {
                        BeginNewTrick(this.CurrentTrickState.Winner);
                    }
                    else //所有牌都出完了
                    {
                        //扣底
                        CalculatePointsFromDiscarded8Cards();
                        Thread.Sleep(2000);
                        this.CurrentHandState.CurrentHandStep = HandStep.Ending;
                        UpdatePlayersCurrentHandState();

                        Thread.Sleep(5000);
                        var starter = this.CurrentGameState.NextRank(this.CurrentHandState, this.CurrentTrickState);

                        Thread.Sleep(5000);
                        StartNextHand(starter);
                    }
                }
                else
                {
                    UpdatePlayerCurrentTrickState();
                }
            }
        }