コード例 #1
0
        private PlayerAction EndGameTurn(PlayerTurnContext context, ICardTracker tracker, ICollection <Card> myHand)
        {
            this.root = new Node(null, null, context.IsFirstPlayerTurn);

            if (context.IsFirstPlayerTurn && this.root.Children.Count == 0)
            {
                tracker.SetFinalRoundHands(myHand);
                var myCards = myHand.ToList();

                EndgameAnalyzer.Compute(this.root, null, myCards, tracker.OpponentTookWith, context.SecondPlayerRoundPoints, context.FirstPlayerRoundPoints);
            }
            else if (this.root.Children.Count == 0)
            {
                tracker.SetFinalRoundHands(myHand);
                var myCards = myHand.ToList();

                while (tracker.OpponentTookWith.Count < 6)
                {
                    tracker.OpponentTookWith.Add(null);
                }

                EndgameAnalyzer.Compute(this.root, context.FirstPlayedCard, myCards, tracker.OpponentTookWith, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }

            if (!context.IsFirstPlayerTurn)
            {
                this.root = this.root.Children.First(x => x.Card == context.FirstPlayedCard);
            }

            var card = this.root.Children.OrderByDescending(x => x.Wins / (decimal)x.Total).First().Card;

            return(PlayerAction.PlayCard(card));
        }
コード例 #2
0
        public static void TestAnalyzer()
        {
            var myCards = new List <Card>()
            {
                new Card(CardSuit.Club, CardType.Ace),
                new Card(CardSuit.Heart, CardType.King),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Spade, CardType.Ten),
                new Card(CardSuit.Diamond, CardType.Nine),
                new Card(CardSuit.Heart, CardType.Ten),
            };

            var oppCards = new List <Card>()
            {
                new Card(CardSuit.Club, CardType.Ten),
                new Card(CardSuit.Heart, CardType.Queen),
                new Card(CardSuit.Spade, CardType.Ace),
                new Card(CardSuit.Spade, CardType.Nine),
                new Card(CardSuit.Diamond, CardType.Jack),
                new Card(CardSuit.Heart, CardType.Jack),
            };

            var root = new Node(null, new Card(CardSuit.Diamond, CardType.Ace), true);

            EndgameAnalyzer.Compute(root, null, myCards, oppCards, 40, 40);

            output = new StringBuilder();
            OutInBuilder(root);

            // File.WriteAllText("../../report.txt", output.ToString());

            foreach (var c in root.Children)
            {
                Console.WriteLine(c.Wins + "/" + c.Total + " " + c.Card);
            }

            Console.WriteLine(root.Wins + " " + root.Total);
        }