Splitable blackjack (#21)

* Blackjack

* changed blackjack randomness to use player bound randomness.

* blackjack splitting. auto standing on 21. fixed duplicate bust message.

* vibecoded transactions fix

* update to match proper balance modification
This commit is contained in:
CrackmaticSoftware
2026-01-05 16:22:34 +01:00
committed by GitHub
parent a288f3f4eb
commit 3992ff3119
2 changed files with 303 additions and 133 deletions

View File

@@ -1,11 +1,14 @@
namespace KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
using Money = KfChatDotNetBot.Services.Money;
namespace KfChatDotNetBot.Models;
public class BlackjackGameMetaModel
{
/// <summary>
/// Player's hand
/// Player's hands (multiple if split)
/// </summary>
public required List<Card> PlayerHand { get; set; }
public required List<List<Card>> PlayerHands { get; set; }
/// <summary>
/// Dealer's hand
@@ -18,9 +21,19 @@ public class BlackjackGameMetaModel
public required List<Card> Deck { get; set; }
/// <summary>
/// Whether player has doubled down (can only hit once more)
/// Whether each hand has doubled down (can only hit once more)
/// </summary>
public bool HasDoubledDown { get; set; } = false;
public required List<bool> HasDoubledDown { get; set; }
/// <summary>
/// Current hand being played (for split hands)
/// </summary>
public int CurrentHandIndex { get; set; } = 0;
/// <summary>
/// Original wager amount (per hand)
/// </summary>
public decimal OriginalWagerAmount { get; set; }
}
public class Card
@@ -65,7 +78,7 @@ public static class BlackjackHelper
/// <summary>
/// Create a new shuffled deck
/// </summary>
public static List<Card> CreateDeck(Random random)
public static List<Card> CreateDeck(GamblerDbModel gambler)
{
var deck = new List<Card>();
foreach (var suit in Suits)
@@ -79,7 +92,7 @@ public static class BlackjackHelper
// Shuffle using Fisher-Yates
for (int i = deck.Count - 1; i > 0; i--)
{
int j = random.Next(0, i + 1);
int j = Money.GetRandomNumber(gambler, 0, i + 1);
(deck[i], deck[j]) = (deck[j], deck[i]);
}
@@ -125,6 +138,18 @@ public static class BlackjackHelper
return hand.Count == 2 && CalculateHandValue(hand) == 21;
}
/// <summary>
/// Check if a hand can be split (two cards of same rank)
/// </summary>
public static bool CanSplit(List<Card> hand)
{
if (hand.Count != 2)
return false;
// Check if both cards have the same value (not rank, to allow 10/J/Q/K splits)
return hand[0].GetValue() == hand[1].GetValue();
}
/// <summary>
/// Format hand for display
/// </summary>