Cards/Card.cs

A small immutable value type representing a runtime card by storing an index into a DeckDefinition's face list. It exposes the FaceIndex, can resolve to the CardFace via a DeckDefinition, and implements equality and hash code based on the index.

namespace CardGames;

/// <summary>
/// A card at runtime: nothing but an index into its <see cref="DeckDefinition"/>'s face list.
/// Tiny and trivially networkable, just this int.
/// </summary>
public readonly struct Card : IEquatable<Card>
{
	public int FaceIndex { get; }

	public Card( int faceIndex ) => FaceIndex = faceIndex;

	public CardFace Resolve( DeckDefinition deck ) => deck.Faces[FaceIndex];

	public bool Equals( Card other ) => FaceIndex == other.FaceIndex;
	public override bool Equals( object obj ) => obj is Card c && Equals( c );
	public override int GetHashCode() => FaceIndex;
}