Skip to content

Commit

Permalink
Cards as property on french decks
Browse files Browse the repository at this point in the history
  • Loading branch information
EluciusFTW committed Dec 28, 2023
1 parent 0ed3073 commit a58644e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/CardGames.Core.French/Decks/FrenchDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ namespace CardGames.Core.French.Decks;

public abstract class FrenchDeck : IDeck<Card>
{
private IList<Card> _cardsOut
= new List<Card>();
private List<Card> _cardsOut = [];

private Card this[int index]
=> CardsLeftInternal()
.ToArray()[index];

private IEnumerable<Card> CardsLeftInternal()
=> Cards()
.Except(_cardsOut);
=> Cards.Except(_cardsOut);

public int NumberOfCardsLeft()
=> Cards().Count - _cardsOut.Count;
=> Cards.Count - _cardsOut.Count;

protected abstract IReadOnlyCollection<Card> Cards();
protected abstract IReadOnlyCollection<Card> Cards { get; }

public IReadOnlyCollection<Card> CardsLeft()
=> CardsLeftInternal()
Expand All @@ -41,7 +39,7 @@ public IReadOnlyCollection<Card> CardsLeftWith(Func<Card, bool> predicate)

public Card GetSpecific(Card card)
{
if (!Cards().Contains(card))
if (!Cards.Contains(card))
{
throw new ArgumentException($"The card {card} is not part of the deck at all!");
}
Expand All @@ -62,5 +60,5 @@ public Card GetFromRemaining(int index)
}

public void Reset()
=> _cardsOut = new List<Card>();
=> _cardsOut.Clear();
}
4 changes: 2 additions & 2 deletions src/CardGames.Core.French/Decks/FullFrenchDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CardGames.Core.French.Decks;

public class FullFrenchDeck : FrenchDeck
public sealed class FullFrenchDeck : FrenchDeck
{
private readonly IReadOnlyCollection<Card> _cards
= Enumerable
Expand All @@ -17,5 +17,5 @@ private static IEnumerable<Card> CardsOfValue(int value)
.Range(0, 4)
.Select(suit => new Card((Suit)suit, value));

protected override IReadOnlyCollection<Card> Cards() => _cards;
protected override IReadOnlyCollection<Card> Cards => _cards;
}
4 changes: 2 additions & 2 deletions src/CardGames.Core.French/Decks/ShortFrenchDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CardGames.Core.French.Decks;

public class ShortFrenchDeck : FrenchDeck
public sealed class ShortFrenchDeck : FrenchDeck
{
private readonly IReadOnlyCollection<Card> _cards
= Enumerable
Expand All @@ -17,5 +17,5 @@ private static IEnumerable<Card> CardsOfValue(int value)
.Range(0, 4)
.Select(suit => new Card((Suit)suit, value));

protected override IReadOnlyCollection<Card> Cards() => _cards;
protected override IReadOnlyCollection<Card> Cards => _cards;
}

0 comments on commit a58644e

Please sign in to comment.