Skip to content

Update Deck.cs#10

Open
mayurikene wants to merge 1 commit intoblackbaud:mainfrom
mayurikene:patch-1
Open

Update Deck.cs#10
mayurikene wants to merge 1 commit intoblackbaud:mainfrom
mayurikene:patch-1

Conversation

@mayurikene
Copy link

@mayurikene mayurikene commented Feb 14, 2026

Summary by CodeRabbit

  • New Features
    • Added shuffle functionality to the deck. Players can now shuffle once or multiple times in succession, providing greater control over deck preparation.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

A new public Shuffle method is added to the Deck class that implements Fisher-Yates shuffle algorithm. The method accepts an optional parameter to shuffle the deck multiple times, converting the internal stack to a list, shuffling it, and rebuilding the stack.

Changes

Cohort / File(s) Summary
Deck Shuffle Feature
CSharp/Blackbaud.Interview.Cards/Deck.cs
Added Shuffle(int times = 1) public method implementing Fisher-Yates shuffle algorithm with support for repeated shuffles via stack-to-list conversion and rebuild.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Cards dance and flutter, in perfect array,
A shuffle, a swirl—now they're scrambled to play!
The rabbit's small paws mix them up just right,
Once, twice, or thrice—till chaos feels right! ✨🃏

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Update Deck.cs' is vague and generic, providing no meaningful information about what was actually changed in the file. Use a more descriptive title that captures the main change, such as 'Add Shuffle method to Deck class' or 'Implement deck shuffling functionality with configurable iterations.'
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@CSharp/Blackbaud.Interview.Cards/Deck.cs`:
- Around line 42-57: Indent the Shuffle method and its body to match the class
style (use 4-space indentation for the method signature and every nested block)
and add XML documentation above the method consistent with other public members:
include a <summary> describing what Shuffle does and a <param name="times">
explaining the optional shuffle count and default behavior; reference the
Shuffle method and the _stackOfCards usage so reviewers can find the
implementation to verify formatting and docs.
🧹 Nitpick comments (1)
CSharp/Blackbaud.Interview.Cards/Deck.cs (1)

42-42: Consider validating the times parameter.

If times <= 0 is passed, the method silently does nothing (clears and rebuilds the stack without shuffling). Consider adding validation to either throw an ArgumentOutOfRangeException or use Math.Max(1, times) to ensure at least one shuffle occurs.

🛡️ Proposed validation
     public void Shuffle(int times = 1)
     {
+        if (times < 1)
+            throw new ArgumentOutOfRangeException(nameof(times), "Must shuffle at least once.");
+
         var cards = _stackOfCards.ToList();

Comment on lines +42 to +57
public void Shuffle(int times = 1)
{
var cards = _stackOfCards.ToList();
var rng = new Random();
for (int t = 0; t < times; t++)
{
for (int i = cards.Count - 1; i > 0; i--)
{
int j = rng.Next(i + 1);
(cards[i], cards[j]) = (cards[j], cards[i]);
}
}
_stackOfCards.Clear();
foreach (var card in cards)
_stackOfCards.Push(card);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Fix indentation and add XML documentation.

The Shuffle method and its body are missing proper indentation (should be 4 spaces to match other class members). Additionally, all other public members in this class have XML documentation comments—this method should follow the same convention.

🛠️ Proposed fix
     public bool Empty => RemainingCards == 0;
-public void Shuffle(int times = 1)
-{
-    var cards = _stackOfCards.ToList();
-    var rng = new Random();
-    for (int t = 0; t < times; t++)
-    {
-        for (int i = cards.Count - 1; i > 0; i--)
-        {
-            int j = rng.Next(i + 1);
-            (cards[i], cards[j]) = (cards[j], cards[i]);
-        }
-    }
-    _stackOfCards.Clear();
-    foreach (var card in cards)
-        _stackOfCards.Push(card);
-}
+
+    /// <summary>
+    /// Shuffles the deck using the Fisher-Yates algorithm.
+    /// </summary>
+    /// <param name="times">Number of times to shuffle the deck.</param>
+    public void Shuffle(int times = 1)
+    {
+        var cards = _stackOfCards.ToList();
+        var rng = new Random();
+        for (int t = 0; t < times; t++)
+        {
+            for (int i = cards.Count - 1; i > 0; i--)
+            {
+                int j = rng.Next(i + 1);
+                (cards[i], cards[j]) = (cards[j], cards[i]);
+            }
+        }
+        _stackOfCards.Clear();
+        foreach (var card in cards)
+            _stackOfCards.Push(card);
+    }
🤖 Prompt for AI Agents
In `@CSharp/Blackbaud.Interview.Cards/Deck.cs` around lines 42 - 57, Indent the
Shuffle method and its body to match the class style (use 4-space indentation
for the method signature and every nested block) and add XML documentation above
the method consistent with other public members: include a <summary> describing
what Shuffle does and a <param name="times"> explaining the optional shuffle
count and default behavior; reference the Shuffle method and the _stackOfCards
usage so reviewers can find the implementation to verify formatting and docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant