private static void DecideWinner(Croupier croupier, IBot bot) { foreach (var hand in bot.Hands) { int handValue = hand.GetHandValue(); if (handValue == 21 && hand.Cards.Count == 2 && (croupier.Hand.Count != 2 || croupier.HandValue != 21)) { bot.Balance += (int)(1.5 * hand.Bet); continue; } if (croupier.HandValue == 21 && croupier.Hand.Count == 2 && (handValue != 21 || hand.Cards.Count != 2)) { bot.Balance -= hand.Bet; continue; } if ((croupier.HandValue > 21 || croupier.HandValue < handValue) && handValue <= 21) { bot.Balance += hand.Bet; continue; } if (handValue < croupier.HandValue || handValue > 21) { bot.Balance -= hand.Bet; } } }
private static void Draw(Shoes shoes, Croupier croupier, IBot bot) { croupier.OpenCard = shoes.GetCard(); croupier.Hand.Add(croupier.OpenCard); croupier.Hand.Add(shoes.GetCard()); bot.Play(croupier.OpenCard, shoes); croupier.Play(shoes); }
private static void DrawEnd(Croupier croupier, IBot bot) { foreach (var hand in bot.Hands) { currentPlayerBet = currentPlayerBet < hand.Bet ? currentPlayerBet : hand.Bet; } bot.Hands = new List <Hand>(); bot.Hands.Add(new Hand(0)); croupier.Hand = new List <Card>(); }
public static void Game(IBot bot, int drawCount, Shoes shoes) { Croupier croupier = new Croupier(); for (int i = 0; i < drawCount; i++) { if (bot.Balance < currentPlayerBet) { return; } Draw(shoes, croupier, bot); DecideWinner(croupier, bot); DrawEnd(croupier, bot); if (shoes.AllCardsCount < 416 / 3) { shoes = new Shoes(); } } }
static void Main(string[] args) { Player p1 = new Player("John", 100.50); Croupier c1 = new Croupier("Best", 1000.00, 5); double bid = 50.00; for (int i = 1; i <= 3; i++) { Console.WriteLine($"Round no.{i}"); int playerResult = p1.RollDice(); Console.WriteLine($"Player {p1.Name} rolled: {playerResult}"); int croupierResult = c1.RollDice(); Console.WriteLine($"Croupier {c1.Name} rolled: {croupierResult}"); if (playerResult == croupierResult) { Console.WriteLine("Draw - no win"); } else if (playerResult > croupierResult) { Console.WriteLine($"Player {p1.Name} wins {bid}"); c1.Loose(p1, bid); } else { Console.WriteLine($"Croupier {c1.Name} wins {bid}"); c1.Win(p1, bid); } Console.WriteLine($"Player {p1.Name} has {p1.Money}"); Console.WriteLine($"Coupier {c1.Name} has {c1.Money}"); Console.WriteLine(); } Console.ReadLine(); }