public GameSettings(int boardSize, Player firstPlayer, IPlayerStrategy playerStrategy, IPlayerStrategy opponentStrategy) { BoardSize = boardSize; FirstPlayer = firstPlayer; PlayerStrategy = playerStrategy; OpponentStrategy = opponentStrategy; }
protected PlayerBase(string name, int teamNumber, IPlayerStrategy playerStrategy, bool isHuman) { TeamNumber = teamNumber; Cards = new List <ICard>(); PlayerStrategy = playerStrategy; IsHuman = isHuman; Name = name; }
public Player(decimal startingCash, IPlayerStrategy playerStrategy) { StartingCash = CurrentTotalCash = startingCash; _playerStrategy = playerStrategy; CurrentHands = new List <IPlayerHand>(); HandHistory = new List <IPlayerHand>(); _currentInPlayHandIndex = 0; DoesNeedCard = false; }
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); }
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 }); } }
public Player(string name, IPlayerStrategy strategy) { Name = name; _strategy = strategy; }
private void UpdateScores(int id) { IPlayerStrategy player = GameController.GetPlayerById(id); ScoresGrid.Rows[id].Cells["ScoreColumn"].Value = player.GetScore(); }
public PrintStrategyDecorator(string player, IPlayerStrategy strategy) { _player = player; _strategy = strategy; }
public Player(PlayerType playerType, string name) { Name = name; strategy = new PlayerStrategyResolver().Resolve(playerType); }
public void AddPlayer(string name, IPlayerStrategy strategy) { var index = Array.FindIndex(_players, x => x == null); AddPlayer(new Player(name, strategy), index); }
public Player(IPlayerStrategy strategy, int playerId) { this.strategy = strategy; id = playerId; }
public Player(string name, int teamNumber, IPlayerStrategy playerStrategy, bool isHuman) : base(name, teamNumber, playerStrategy, isHuman) { }
public WinningStrategy() { _random = new RandomStrategy(); _minimax = new MinimaxStrategy(); _centerHunting = new CenterHuntingStrategy(); }