示例#1
0
        private double GetHeuristicHandStrength(Player currentPlayer, Suits trump)
        {
            double predictionOfTricks = 0;

            foreach(Card card in currentPlayer.hand.Cards)
            {
                predictionOfTricks += (int)card.Number - 1;//2 is card rank 1, 3 is card rank 2, ..., king is card rank 12, ace is card rank 13
                if(card.Suit == trump)
                {
                    predictionOfTricks += 39;//trump is stronger than all other suits(13 * 3 = 39)
                }
            }
            //return predictionOfTricks / 52;//divide by total amount of cards(chance of card winning a trick)      this works better for worse cards
            return predictionOfTricks / 598 * 13;//all trumpvalues added equals 598(max value of cards in hand)     this works better for better cards

            //double heuristicHandStrength = 0;
            //for (int i = 0; i < 13; i++)
            //{
            //    heuristicHandStrength += (int)currentPlayer.hand.Cards[i].Number;
            //    if (currentPlayer.hand.Cards[i].Suit == trump)
            //    {
            //        heuristicHandStrength += 13;
            //    }
            //}
            //sum of all cardStrengths = (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14) * 3 + (15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27) = 585
            //your handStrength / sum of all cardStrengths * #tricks = statistical average number of tricks you will make in unlimited # games
            //return heuristicHandStrength / 273 * 13; 273 is sum of all trump values
        }
示例#2
0
文件: MemoryAI.cs 项目: Bawaw/Whist
 public override void ProcessOtherPlayerAction(Player otherPlayer, Action action)
 {
     if (Round.GameCase == Case.UNDECIDED)
         switch (action)
         {
             case Action.PASS:
                 {
                     memory[otherPlayer].minInitialHandStrength = 0;
                     memory[otherPlayer].maxInitialHandStrength = 4;
                     break;
                 }
             case Action.ASK:
                 {
                     memory[otherPlayer].minInitialHandStrength = 5;
                     memory[otherPlayer].maxInitialHandStrength = 9;
                     break;
                 }
             case Action.JOIN:
                 {
                     memory[otherPlayer].minInitialHandStrength = 3;
                     memory[otherPlayer].maxInitialHandStrength = 9;
                     break;
                 }
             case Action.ABONDANCE:
                 {
                     memory[otherPlayer].minInitialHandStrength = 10;
                     memory[otherPlayer].maxInitialHandStrength = 13;
                     break;
                 }
         }
 }
示例#3
0
 public GameController(Player[] players, IReferee referee)
 {
     this.players = players;
     this.PlayersLeft = players.ToList();
     this.referee = referee;
     pile = new ObservableCollection<Card>();
 }
示例#4
0
        private GameManager InitialiseTest()
        {
            var players = new Player[]
            {
                new Player("C1", 0),
                new Player("C2", 1),
                new Player("C3", 2),
                new Player("C4", 3)
            };

            var gameManager = new GameManager(players, 13, new AIBidType[]
            {
                AIBidType.BASIC,
                AIBidType.BASIC,
                AIBidType.BASIC,
                AIBidType.BASIC
            }, new AIGameType[]
            {
                AIGameType.MEMORY,
                AIGameType.MEMORY,
                AIGameType.MEMORY,
                AIGameType.MEMORY,
            });

            return gameManager;
        }
示例#5
0
文件: GameCase.cs 项目: Bawaw/Whist
 public override bool AfterDealCheck(Player[] players)
 {
     //What about Trump? Need some way to give Trump, or decide troel doesn't change Trump.
     foreach (Player player in players)
         if (player.hand.Cards.Where(c => c.Number == Numbers.ACE).Count() >= 3)
             return true;
     return false;
 }
示例#6
0
文件: IDealCards.cs 项目: Bawaw/Whist
 public void DealCards(Player[] players)
 {
     DeckCollection cardCollection = new DeckCollection();
     cardCollection.initialise();
     cardCollection.shuffle();
     int nCards = cardCollection.Count / players.Length;
     foreach (var player in players)
         player.hand.AddCards(cardCollection.Draw(nCards));
 }
示例#7
0
文件: Round.cs 项目: Bawaw/Whist
        public Round(Player[] players)
        {
            Players = players;
            foreach (Player player in Players)
                player.clearTricks();
            phase1 = new DealAndBidNormal(Players);
            RoundInProgress = true;

            //LetAIHandleFirstPhase();
        }
示例#8
0
        private static int GetHandStrength(Player player, Suits trump)
        {
            int handStrength = 0;

            var cards = player.hand.Cards;
            var kingsAndAces = cards.Where(c => c.Number == Numbers.ACE || c.Number == Numbers.KING);
            handStrength += kingsAndAces.Count();
            var trumps = cards.Where(c => c.Suit == trump);
            handStrength += trumps.Except(kingsAndAces).Count();

            return handStrength;
        }
示例#9
0
        public GameManager(Player[] players, int roundsToPlay, AIBidType[] bidAITypes, AIGameType[] gameAITypes)
        {
            Players = players;

            aiPlayers = new Dictionary<Player, AI>();
            for (int i = 0; i < 4; i++)
            {
                aiPlayers.Add(players[i], AIFactory.CreateAI(players[i], this, bidAITypes[i], gameAITypes[i]));
            }
            RoundsToPlay = roundsToPlay;
            RoundNumber = 1;
            IsGameInProgress = true;
            Round = new Round(players);
        }
示例#10
0
文件: AIFactory.cs 项目: Bawaw/Whist
 public static IBidAI CreateBidAI(Player player, GameManager game, AIBidType type)
 {
     switch (type)
     {
         case AIBidType.BASIC:
             return new BaseBidAI(player, game);
         case AIBidType.CAUTIOUS:
             return new CautiousBidAI(player, game);
         case AIBidType.SIMGAME:
             return new SimulateGameBidAI(player, game);
         case AIBidType.OMNISCIENT:
             return new BidSearchAI(game);
     }
     throw new ApplicationException();
 }
示例#11
0
 public override void ProcessOtherPlayerCard(Player otherPlayer, Card card)
 {
     if (otherPlayer != player)
     {
         if (Round.Pile.Count > 0)
         {
             var leadCard = Round.Pile[0];
             if (leadCard.Suit != card.Suit)
                 memory[otherPlayer].NoCardsOfSuitLeft(leadCard.Suit);
         }
         if (card.Suit == Round.Trump)
             trumpsPlayed++;
     }
     playedCards.Add(card);
     playedCardsByPlayer[otherPlayer].Add(card);
 }
示例#12
0
文件: GameCase.cs 项目: Bawaw/Whist
        public override Team[] Teams(Player[] players)
        {
            foreach (Player player in players)
            {
                int aces = player.hand.Cards.Where(c => c.Number == Numbers.ACE).Count();
                if (aces >= 3)
                {
                    selectedPlayers.Add(player);
                    if (aces == 3)
                    {
                        foreach (Player playerTwo in players.Except(selectedPlayers))
                        {
                            if (playerTwo.hand.Cards.Where(c => c.Number == Numbers.ACE).Count() > 0)
                            {
                                selectedPlayers.Add(playerTwo);
                                break;
                            }
                        }
                    }
                    else if (aces == 4)
                    {
                        var playerOneHearts = player.hand.Cards.Where(c => c.Suit == Suits.HEARTS);
                        Numbers highestHeart = Numbers.KING;
                        while (playerOneHearts.Any(c => c.Number == highestHeart))
                        {
                            highestHeart--;
                        }
                        foreach (Player p in players.Except(selectedPlayers))
                        {
                            if (p.hand.Cards.Any(c => c.Suit == Suits.HEARTS && c.Number == highestHeart))
                            {
                                selectedPlayers.Add(p);
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            return new Team[]
            {
                new Team(selectedPlayers.ToArray(), 8),
                new Team(players.Except(selectedPlayers).ToArray(), 6)
            };
        }
示例#13
0
文件: AIFactory.cs 项目: Bawaw/Whist
 public static IGameAI CreateGameAI(Player player, GameManager game, AIGameType type)
 {
     switch (type)
     {
         case AIGameType.BASIC:
             return new BaseGameAI(player, game);
         case AIGameType.MEMORY:
             return new MemoryAI(player, game);
         case AIGameType.PERFECTMEMORY:
             return new PerfectMemoryAI(player, game);
         case AIGameType.BRUTEFORCE:
             return new BruteForceAI(player, game);
         case AIGameType.OMNISCIENT:
             return new OmniscentSearchAI(game, new StandardReferee());
     }
     throw new ApplicationException();
 }
示例#14
0
        public static Action GetAction(Player player, IEnumerable<Action> possibleActions, Suits trump)
        {
            int handStrength = GetHandStrength(player, trump);

            if (!possibleActions.Contains(Action.PASS))
            {
                switch (trump)
                {
                    case Suits.HEARTS:
                        return Action.HEARTS;
                    case Suits.DIAMONDS:
                        return Action.DIAMONDS;
                    case Suits.SPADES:
                        return Action.SPADES;
                    case Suits.CLUBS:
                        return Action.CLUBS;
                    default:
                        return 0;
                }
            }

            if (handStrength >= 9)
            {
                if (possibleActions.Contains(Action.ABONDANCE))
                    return Action.ABONDANCE;
            }
            if (handStrength >= 5)
            {
                if (possibleActions.Contains(Action.ASK))
                    return Action.ASK;
                if (possibleActions.Contains(Action.ALONE))
                    return Action.ALONE;
            }
            if (handStrength >= 3)
            {
                if (possibleActions.Contains(Action.JOIN))
                    return Action.JOIN;
            }

            return Action.PASS;
        }
示例#15
0
        private void init()
        {
            playerA = null;
            playerB = null;
            askForTrump = false;
            GameCase = Case.UNDECIDED;
            currentSpecial = 0;


            specialGameCases = SpecialGameCaseFactory.GetDictionary();
            CurrentPlayer = players[0];
            actionsDone = 0;
            passedPlayers = new Dictionary<Player, bool>();
            foreach (var player in players)
            {
                passedPlayers.Add(player, false);
                player.hand.Cards.Clear();
            }
 
            DealCards();
        }
示例#16
0
        private void SetHandsToTestConfiguration(Player[] players)
        {
            players[0].hand.Cards.Clear();
            players[1].hand.Cards.Clear();
            players[2].hand.Cards.Clear();
            players[3].hand.Cards.Clear();

            players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.KING));
            players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.JACK));
            players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.THREE));
            players[0].hand.Cards.Add(new Card(Suits.SPADES, Numbers.THREE));
            players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.FOUR));
            players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.NINE));
            players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.SEVEN));
            players[1].hand.Cards.Add(new Card(Suits.SPADES, Numbers.FOUR));
            players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.ACE));
            players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.FIVE));
            players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.QUEEN));
            players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.TWO));
            players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.TEN));
            players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.EIGHT));
            players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.SIX));
            players[3].hand.Cards.Add(new Card(Suits.SPADES, Numbers.FIVE));
        }
示例#17
0
文件: Player.cs 项目: Bawaw/Whist
 public Team(Player[] players, int objective) {
     this.players = players;
     this.objective = objective;
 }
示例#18
0
 public WhistController(Player[] players, Player FirstPlayer, Suits trump, IReferee referee)
     : base(players, referee)
 {
     this.trump = trump;
     for (int i = 0; i < players.Length; i++)
         if (players[i] == FirstPlayer)
         {
             currentPlayer = i;
             break;
         }
     CardPlayedByPlayer = new Dictionary<Player, Card>();
     foreach (Player player in players)
         CardPlayedByPlayer.Add(player, null);
 }
示例#19
0
 public ObservableCollection<Card> GetPlayerCards(Player player)
 {
     return player.hand.Cards;
 }
示例#20
0
        protected override int GetHandStrength(Suits trump)
        {
            Player[] CopyPlayers = new Player[]
            {
                new Player("copy0", 0),
                new Player("copy1", 1),
                new Player("copy2", 2),
                new Player("copy3", 3)
            };

            Round simRound;
            do
            {
                simRound = new Round(CopyPlayers);
            } while (simRound.GameCase != Case.UNDECIDED);

            for (int i = 0; i < 4; i++)
            {
                CopyPlayers[i].hand.Cards.Clear();
                foreach (var card in game.Players[i].hand.Cards)
                    CopyPlayers[i].hand.AddCard(card);
            }

            while (simRound.InBiddingPhase)
            {
                if (simRound.CurrentPlayer == CopyPlayers.Where(cp => cp.Number == player.Number).Single())
                {
                    if (simRound.BiddingGetPossibleActions().Contains(Action.ABONDANCE))
                        simRound.BiddingDoAction(Action.ABONDANCE);
                    else
                    {
                        switch (trump)
                        {
                            case Suits.HEARTS:
                                {
                                    simRound.BiddingDoAction(Action.HEARTS);
                                    break;
                                }
                            case Suits.DIAMONDS:
                                {
                                    simRound.BiddingDoAction(Action.DIAMONDS);
                                    break;
                                }
                            case Suits.SPADES:
                                {
                                    simRound.BiddingDoAction(Action.SPADES);
                                    break;
                                }
                            case Suits.CLUBS:
                                {
                                    simRound.BiddingDoAction(Action.CLUBS);
                                    break;
                                }
                            default:
                                break;
                        }
                    }
                    simRound.BiddingDoAction(Action.ASK);
                }
                else
                    simRound.BiddingDoAction(Action.PASS);
            }

            simRound.EndBiddingRound();
            while (simRound.InTrickPhase)
            {
                while (simRound.TrickInProgress)
                    simRound.PlayCard(SimpleGameAI.GetMove(simRound));
                simRound.EndTrick();
            }

            return CopyPlayers.Where(cp => cp.Number == player.Number).Single().Tricks;
        }
示例#21
0
文件: AI.cs 项目: Bawaw/Whist
 /// <summary>
 /// When a player (including this one) plays a card, this function should be called so it is made aware of the other player's move.
 /// </summary>
 public void ProcessOtherPlayerCard(Player otherPlayer, Card card)
 {
     GameAI.ProcessOtherPlayerCard(otherPlayer, card);
 }
示例#22
0
文件: AI.cs 项目: Bawaw/Whist
 /// <summary>
 /// When a player (including this one) submits an action, this function should be called so it is made aware of the other player's action.
 /// </summary>
 public void ProcessOtherPlayerAction(Player otherPlayer, Action action)
 {
     GameAI.ProcessOtherPlayerAction(otherPlayer, action);
 }
示例#23
0
 /// <summary>
 /// Returns the AI corresponding to the given Player.
 /// </summary>
 public AI GetAI(Player player)
 {
     return aiPlayers[player];
 }
示例#24
0
 public void ProcessOtherPlayerCard(Player otherPlayer, Card card) { }
示例#25
0
 public void ProcessOtherPlayerAction(Player otherPlayer, GameLogic.ControlEntities.Action action) { }
示例#26
0
 public CautiousBidAI(Player player, GameManager game) : base(player, game)
 {
 }
示例#27
0
        public SimulateGameBidAI(Player player, GameManager game) : base(player, game)
        {

        }
示例#28
0
文件: Round.cs 项目: Bawaw/Whist
 /// <summary>
 /// In the trick phase, returns which card was played by a certain player.
 /// </summary>
 public Card CardPlayedByPlayer(Player player) { return phase2?.CardPlayedByPlayer[player]; }
示例#29
0
 public BruteForceAI(Player player, GameManager game)
 {
     this.player = player;
     this.game = game;
 }
示例#30
0
文件: AI.cs 项目: Bawaw/Whist
 public AI(Player player, IBidAI bidAI, IGameAI gameAI)
 {
     this.player = player;
     BidAI = bidAI;
     GameAI = gameAI;
 }