Пример #1
0
        public void NextPlayerTest()
        {
            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> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
                12
            };

            string actual;

            actual = trickState.NextPlayer("p1");
            Assert.AreEqual("p2", actual);
            Assert.AreEqual("p3", trickState.NextPlayer("p2"));
            Assert.AreEqual("p4", trickState.NextPlayer("p3"));
            Assert.AreEqual("p1", trickState.NextPlayer("p4"));
        }
Пример #2
0
        public void IsValidTest2()
        {
            CurrentTrickState currentTrickState = new CurrentTrickState {
                Trump = Suit.Heart, Rank = 0, Learder = "p1"
            };

            currentTrickState.ShowedCards.Add("p1", new List <int> {
                39, 39, 0, 0
            });
            currentTrickState.ShowedCards.Add("p2", new List <int> {
            });
            currentTrickState.ShowedCards.Add("p3", new List <int> {
            });
            currentTrickState.ShowedCards.Add("p4", new List <int> {
            });
            List <int> selectedCards = new List <int> {
                1, 2, 5, 5
            };
            CurrentPoker currentCards = new CurrentPoker(new int[] { 1, 2, 3, 4, 5, 5 }, Suit.Heart, 0);
            ShowingCardsValidationResultType expected = ShowingCardsValidationResultType.Valid;
            ShowingCardsValidationResultType actual;

            actual = TractorRules.IsValid(currentTrickState, selectedCards, currentCards).ResultType;
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
 public void PlayerShowCards(string playerId, CurrentTrickState currentTrickState)
 {
     if (this.SessionIDGameRoom.ContainsKey(playerId))
     {
         GameRoom gameRoom = this.SessionIDGameRoom[playerId];
         gameRoom.PlayerShowCards(currentTrickState);
     }
 }
Пример #4
0
 //begin new trick
 private void BeginNewTrick(string leader)
 {
     this.CurrentTrickState         = new CurrentTrickState(this.PlayersProxy.Keys.ToList());
     this.CurrentTrickState.Learder = leader;
     this.CurrentTrickState.Trump   = CurrentHandState.Trump;
     this.CurrentTrickState.Rank    = CurrentHandState.Rank;
     UpdatePlayerCurrentTrickState();
 }
Пример #5
0
        public TractorPlayer()
        {
            CurrentPoker      = new CurrentPoker();
            PlayerId          = Guid.NewGuid().ToString();
            CurrentGameState  = new GameState();
            CurrentHandState  = new CurrentHandState(CurrentGameState);
            CurrentTrickState = new CurrentTrickState();

            var instanceContext = new InstanceContext(this);
            var channelFactory  = new DuplexChannelFactory <ITractorHost>(instanceContext, "NetTcpBinding_ITractorHost");

            _tractorHost = channelFactory.CreateChannel();
        }
Пример #6
0
        public void NotifyCurrentTrickState(CurrentTrickState currentTrickState)
        {
            this.CurrentTrickState = currentTrickState;

            if (this.CurrentTrickState.LatestPlayerShowedCard() != "")
            {
                if (PlayerShowedCards != null)
                {
                    PlayerShowedCards();
                }
            }

            if (!string.IsNullOrEmpty(this.CurrentTrickState.Winner))
            {
                if (TrickFinished != null)
                {
                    TrickFinished();
                }
            }
        }
Пример #7
0
        public void NotifyCurrentTrickState(CurrentTrickState currentTrickState)
        {
            this.CurrentTrickState = currentTrickState;
            if (this.IsTryingReenter || this.IsTryingResumeGame)
            {
                return;
            }

            if (this.CurrentHandState.CurrentHandStep == HandStep.Ending || this.CurrentHandState.CurrentHandStep == HandStep.SpecialEnding)
            {
                return;
            }

            if (this.CurrentTrickState.LatestPlayerShowedCard() != "")
            {
                if (PlayerShowedCards != null)
                {
                    PlayerShowedCards();
                }
            }

            if (!string.IsNullOrEmpty(this.CurrentTrickState.Winner))
            {
                if (TrickFinished != null)
                {
                    TrickFinished();
                }
            }

            if (!this.CurrentTrickState.IsStarted())
            {
                if (TrickStarted != null)
                {
                    TrickStarted();
                }
            }
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
        public void LatestPlayerShowedCardTest()
        {
            CurrentTrickState trickState = new CurrentTrickState();

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

            Assert.AreEqual("", trickState.LatestPlayerShowedCard());

            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p1", trickState.LatestPlayerShowedCard());



            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p2", trickState.LatestPlayerShowedCard());


            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p3", trickState.LatestPlayerShowedCard());

            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
                4
            };
            Assert.AreEqual("p4", trickState.LatestPlayerShowedCard());

            trickState.Learder           = "p2";
            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p2", trickState.LatestPlayerShowedCard());
        }
Пример #15
0
        public void PlayerShowCardsWS(string playerId, string content)
        {
            CurrentTrickState currentTrickState = CommonMethods.ReadObjectFromString <CurrentTrickState>(content);

            this.PlayerShowCards(playerId, currentTrickState);
        }
Пример #16
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();
                }
            }
        }
Пример #17
0
        public void NextPlayerTest1()
        {
            CurrentTrickState trickState = new CurrentTrickState();

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

            Assert.AreEqual("p1", trickState.NextPlayer());

            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p2", trickState.NextPlayer());


            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p3", trickState.NextPlayer());


            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p4", trickState.NextPlayer());

            trickState.Learder           = "p2";
            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };

            Assert.AreEqual("p2", trickState.NextPlayer());

            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p3", trickState.NextPlayer());


            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1
            };
            trickState.ShowedCards["p3"] = new List <int> {
                2
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p4", trickState.NextPlayer());

            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1
            };
            trickState.ShowedCards["p3"] = new List <int> {
                2
            };
            trickState.ShowedCards["p4"] = new List <int> {
                3
            };
            Assert.AreEqual("p1", trickState.NextPlayer());

            trickState.Learder           = "p2";
            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };

            Assert.AreEqual("p2", trickState.NextPlayer());

            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1, 1, 5, 12
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p3", trickState.NextPlayer());


            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1, 1, 5, 12
            };
            trickState.ShowedCards["p3"] = new List <int> {
                1, 1, 5, 12
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p4", trickState.NextPlayer());

            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1, 1, 5, 12
            };
            trickState.ShowedCards["p3"] = new List <int> {
                1, 1, 5, 12
            };
            trickState.ShowedCards["p4"] = new List <int> {
                1, 1, 5, 12
            };
            Assert.AreEqual("p1", trickState.NextPlayer());
        }