Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CSharp/Blackbaud.Interview.Cards/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ public static Deck NewDeck()
/// Returns true if there are no remaining cards in the deck
/// </summary>
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);
}
Comment on lines +42 to +57
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.

/// <summary>
/// Removes the next card from the deck.
/// </summary>
Expand Down