예제 #1
0
        public void AIPlay(int skillLevel = 100)
        {
            int errorMargin = 0;

            if (id == (table.activeDeal.Value.contract.getDeclarer() + 2) % 4)
            {
                table.players[(id + 2) % 4].AIPlay(skillLevel);
                return;
            }
            //Console.WriteLine("Starting AI play from player: " + id);
            //Console.WriteLine("Player on Lead: " + table.activeDeal.Value.playerOnTurn);
            Dictionary <string, int> results = new Dictionary <string, int>();
            Deal myDeal = new Deal(table.activeDeal.Value.id);

            for (int i = 0; i < skillLevel; i++)
            {
                //Console.WriteLine("Predealing...");
                myDeal.predeal(data);
                while (checkEligibility(myDeal))
                {
                    //Console.WriteLine("Deal was not eligible, retrying...");
                    myDeal.predeal(data);
                }
                myDeal.setPlayerOnTurn((myDeal.id + 3) % 4);
                myDeal.contract = table.activeDeal.Value.contract;
                myDeal.playedCards.Clear();
                myDeal.lastTrick.Clear();
                DoubleDummySolver solver = new DoubleDummySolver(myDeal);
                foreach (Card card in table.activeDeal.Value.playedCards)
                {
                    myDeal.playCard(card.ID);
                }
                solver.exec(string.Join(" ", myDeal.playedCards));
                foreach (Card card in myDeal.deck.cards)
                {
                    if (card.isPlayable)
                    {
                        if (!results.ContainsKey(card.ToString()))
                        {
                            results.Add(card.ToString(), solver.getTricksEx(card.ToString()));
                        }
                        else
                        {
                            results[card.ToString()] += solver.getTricksEx(card.ToString());
                        }
                    }
                }
                solver.destroy();
            }
            int    max        = -1;
            string cardToPlay = "";

            foreach (string card in results.Keys)
            {
                if (results[card] >= max)
                {
                    cardToPlay = card;
                    max        = results[card];
                }
            }
            DoubleDummySolver s = new DoubleDummySolver(table.activeDeal.Value);

            errorMargin += s.getTricks() - s.getTricksEx(cardToPlay);
            s.destroy();
            play(Array.IndexOf(BRIDGE.CARDS, cardToPlay));
            //Console.WriteLine("AI plays: " + cardToPlay);
            table.errorMargin += errorMargin;
            //table.activeDeal.Value.print();
        }
예제 #2
0
파일: Deal.cs 프로젝트: CastorMann/Bridge
 public void predeal(Deal deal, string north = "...", string east = "...", string south = "...", string west = "...")
 {
     predeal(deal.playerOnTurn, deal.deck.northHand.Count, deal.deck.eastHand.Count, deal.deck.southHand.Count,
             deal.deck.westHand.Count, deal.playedCards, north, east, south, west);
 }