예제 #1
0
        public static BridgeGame Replay(string pbn, Action <BridgeGame, PlayerPosition, string> onCardPaying = null, Action <int> onTrickPlayed = null)
        {
            var parseResult = PbnParser.ParseGame(pbn);
            var game        = BridgeHelper.GetGameFromPbn(parseResult.Deal, parseResult.Contract, parseResult.Declarer);
            var player      = PlayerPosition.Players.Find(x => x.FirstLetter == parseResult.FirstPlayer);

            if (!string.IsNullOrEmpty(parseResult.Play))
            {
                var play   = PbnParser.ParsePlay(parseResult.Play);
                var number = 0;
                foreach (var trick in play)
                {
                    number++;
                    for (int i = 0; i < trick.Length; i++)
                    {
                        var card = trick[trick.Length == 4 ? player.PbnIndex: i];
                        if (onCardPaying != null)
                        {
                            onCardPaying(game, player, card);
                        }
                        player = game.PlayCard(BridgeHelper.GetCard(card), player);
                    }
                    if (onTrickPlayed != null)
                    {
                        onTrickPlayed(number);
                    }
                }
            }
            return(game);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var dds     = new DoubleDummyModule();
            var pbnCode = "E:K9742.763.Q.K764 AT6.AJ98.A5.QT53 853.QT.KT742.J92 QJ.K542.J9863.A8";

            Console.WriteLine("Board: " + pbnCode);


            var res = DoubleDummyModule.CalculateMakeableContracts(pbnCode);

            Console.WriteLine("Best results:");
            foreach (var contract in res)
            {
                Console.WriteLine(contract);
            }

            var game = BridgeHelper.GetGameFromPbn(pbnCode, "4S", "W");

            Console.WriteLine("------------- Game Starts ----------------");
            Console.WriteLine("Trump: " + game.Contract.Trump);
            //var player = game.Declarer;
            var player = PlayerPosition.North;

            while (game.CardsRemaning > 0)
            {
                var result = dds.SolveBoardPbnBestCard(game);
                Console.WriteLine(player + ": " + result.Card + ". Score: " + result.Score);
                player = game.PlayCard(result.Card, player);

                if (game.CurrentTrick.Deck.Count == 0)
                {
                    Console.WriteLine("Trick Winner: " + game.Tricks.Last().TrickWinner);
                }
            }

            Console.WriteLine("-----------Results----------");
            Console.WriteLine("South/North: " + game.NorthSouthTricksMade + " tricks");
            Console.WriteLine("East/West: " + game.EastWestTricksMade + " tricks");

            Console.ReadKey();
        }
예제 #3
0
        static void Main(string[] args)
        {
            var dds     = new DdsConnect();
            var pbnCode = "E:AT5.AJT.A632.KJ7 Q763.KQ9.KQJ94.T 942.87653..98653 KJ8.42.T875.AQ42";

            Console.WriteLine("Board: " + pbnCode);

            var game = BridgeHelper.GetGameFromPbn(pbnCode);
            var res  = dds.CalculateMakeableContracts(pbnCode);

            Console.WriteLine("Best results:");
            foreach (var contract in res)
            {
                Console.WriteLine(contract);
            }
            Console.WriteLine("------------- Game Starts ----------------");
            Console.WriteLine("Trump: " + game.Contract.Trump);
            var player = game.Declarer;

            while (game.CardsRemaning > 0)
            {
                var result = dds.SolveBoardPbnBestCard(game);
                Console.WriteLine(player + ": " + result.Card + ". Score: " + result.Score);
                player = game.PlayCard(result.Card, player);

                if (game.CurrentTrick.Deck.Count == 0)
                {
                    Console.WriteLine("Trick Winner: " + game.Tricks.Last().TrickWinner);
                }
            }

            Console.WriteLine("-----------Results----------");
            Console.WriteLine("South/North: " + game.NorthSouthTricksMade + " tricks");
            Console.WriteLine("East/West: " + game.EastWestTricksMade + " tricks");

            Console.ReadKey();
        }