예제 #1
0
 public GameSettings(int boardSize, Player firstPlayer,
                     IPlayerStrategy playerStrategy, IPlayerStrategy opponentStrategy)
 {
     BoardSize        = boardSize;
     FirstPlayer      = firstPlayer;
     PlayerStrategy   = playerStrategy;
     OpponentStrategy = opponentStrategy;
 }
예제 #2
0
 protected PlayerBase(string name, int teamNumber, IPlayerStrategy playerStrategy, bool isHuman)
 {
     TeamNumber     = teamNumber;
     Cards          = new List <ICard>();
     PlayerStrategy = playerStrategy;
     IsHuman        = isHuman;
     Name           = name;
 }
예제 #3
0
 public Player(decimal startingCash, IPlayerStrategy playerStrategy)
 {
     StartingCash            = CurrentTotalCash = startingCash;
     _playerStrategy         = playerStrategy;
     CurrentHands            = new List <IPlayerHand>();
     HandHistory             = new List <IPlayerHand>();
     _currentInPlayHandIndex = 0;
     DoesNeedCard            = false;
 }
예제 #4
0
        public IPlayerStrategy GetPlayerStrategy()
        {
            if (!IsComputerControlled)
            {
                throw new InvalidOperationException("Player strategy is not valid for human controlled player.");
            }

            if (playerStrategy == null)
            {
                playerStrategy = new BasicPlayerStrategyV1();
            }

            return(playerStrategy);
        }
예제 #5
0
        public BlackjackGameResult PlayGame(Queue <Card> shoe, int bet, IPlayerStrategy playerStrategy)
        {
            Card firstPlayerCard  = shoe.Dequeue();
            Card dealerUpCard     = shoe.Dequeue();
            Card secondPlayerCard = shoe.Dequeue();

            Console.WriteLine($"Dealer up card: {dealerUpCard}");
            Console.WriteLine($"Player has: {firstPlayerCard} {secondPlayerCard}");

            List <Card> playerHand = new List <Card> {
                firstPlayerCard, secondPlayerCard
            };

            if (Utilities.HandIsBlackjack(playerHand))
            {
                int winnings = Convert.ToInt32(bet * Configuration.BLACKJACK_PAYOUT_RATIO);
                Console.WriteLine($"Blackjack! Player wins: {winnings}");
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.PlayerWins, EarningsAfterGame = winnings
                });
            }

            PlayerStrategyUtils.RecommendedPlayerAction thingToDo = playerStrategy.WhatDo(playerHand, dealerUpCard);

            if (thingToDo == PlayerStrategyUtils.RecommendedPlayerAction.Double)
            {
                bet *= 2;
                Card nextCard = shoe.Dequeue();
                playerHand.Add(nextCard);
                // That's it
            }
            else
            {
                while (thingToDo == PlayerStrategyUtils.RecommendedPlayerAction.Hit)
                {
                    Card nextCard = shoe.Dequeue();
                    playerHand.Add(nextCard);
                    thingToDo = playerStrategy.WhatDo(playerHand, dealerUpCard);
                }
            }

            if (Utilities.HandBusted(playerHand))
            {
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.DealerWins, EarningsAfterGame = -bet
                });
            }

            Card dealerDownCard = shoe.Dequeue();

            List <Card> dealerHand = new List <Card> {
                dealerUpCard, dealerDownCard
            };

            bool dealerShouldStopHitting = HandUtils.HandHigherThanSoft17(dealerHand);

            while (!dealerShouldStopHitting)
            {
                dealerHand.Add(shoe.Dequeue());
                dealerShouldStopHitting = HandUtils.HandHigherThanSoft17(dealerHand);
            }

            if (Utilities.HandBusted(dealerHand))
            {
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.PlayerWins, EarningsAfterGame = bet
                });
            }

            int playerValue = HandUtils.CalculateHandValue(playerHand).value;
            int dealerValue = HandUtils.CalculateHandValue(dealerHand).value;

            if (playerValue == dealerValue)
            {
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.Push, EarningsAfterGame = 0
                });
            }
            else if (dealerValue > playerValue)
            {
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.DealerWins, EarningsAfterGame = -bet
                });
            }
            else
            {
                return(new BlackjackGameResult {
                    Winner = BlackjackResultWinner.PlayerWins, EarningsAfterGame = bet
                });
            }
        }
예제 #6
0
 public Player(string name, IPlayerStrategy strategy)
 {
     Name = name;
     _strategy = strategy;
 }
예제 #7
0
        private void UpdateScores(int id)
        {
            IPlayerStrategy player = GameController.GetPlayerById(id);

            ScoresGrid.Rows[id].Cells["ScoreColumn"].Value = player.GetScore();
        }
예제 #8
0
 public PrintStrategyDecorator(string player, IPlayerStrategy strategy)
 {
     _player   = player;
     _strategy = strategy;
 }
예제 #9
0
 public Player(string name, IPlayerStrategy strategy)
 {
     Name      = name;
     _strategy = strategy;
 }
예제 #10
0
파일: Player.cs 프로젝트: maximgridin/game
 public Player(PlayerType playerType, string name)
 {
     Name     = name;
     strategy = new PlayerStrategyResolver().Resolve(playerType);
 }
예제 #11
0
 public void AddPlayer(string name, IPlayerStrategy strategy)
 {
     var index = Array.FindIndex(_players, x => x == null);
     AddPlayer(new Player(name, strategy), index);
 }
예제 #12
0
 public Player(IPlayerStrategy strategy, int playerId)
 {
     this.strategy = strategy;
     id            = playerId;
 }
예제 #13
0
 public Player(string name, int teamNumber, IPlayerStrategy playerStrategy, bool isHuman)
     : base(name, teamNumber, playerStrategy, isHuman)
 {
 }
예제 #14
0
 public WinningStrategy()
 {
     _random        = new RandomStrategy();
     _minimax       = new MinimaxStrategy();
     _centerHunting = new CenterHuntingStrategy();
 }
예제 #15
0
        public void AddPlayer(string name, IPlayerStrategy strategy)
        {
            var index = Array.FindIndex(_players, x => x == null);

            AddPlayer(new Player(name, strategy), index);
        }