Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created June 17, 2021 19:23
Show Gist options
  • Save khalidabuhakmeh/2e91cd77ed8aa4cb00cfaf21411d121b to your computer and use it in GitHub Desktop.
Save khalidabuhakmeh/2e91cd77ed8aa4cb00cfaf21411d121b to your computer and use it in GitHub Desktop.
Implement Deck
public interface IDeck<T>
{
/// <summary>
/// Draw as many T as the count
/// will draw the most it possibly can, which may be 0
/// </summary>
/// <param name="count"></param>
/// <returns></returns>
IEnumerable<T> Draw(int count);
/// <summary>
/// Draw items until the deck is empty
/// Remaining is 0
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
bool TryDraw(out T item);
/// <summary>
/// Get one item, and mark it as dealt
/// </summary>
/// <returns></returns>
T Draw();
/// <summary>
/// Shuffles Remaining Items In Deck
/// </summary>
void Shuffle();
/// <summary>
/// If item was an existing item
/// then it gets returned. If its
/// a never before seen item then
/// it gets added to the original collection
/// </summary>
/// <param name="item"></param>
/// <param name="index"></param>
void InsertAt(T item, Index? index);
/// <summary>
/// Remove item from the deck
/// this means the card can't be dealt
/// </summary>
/// <param name="item"></param>
void Remove(T item);
/// <summary>
/// Reset items to original state
/// including inserted items.
/// No dealt cards
/// </summary>
void Reset();
// original deck including items that
// have been added after initialization
public IEnumerable<T> All { get; }
// cards that have been dealt
public IEnumerable<T> Outstanding { get; }
// cards that have not been dealt
public IEnumerable<T> Remaining { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment