Blackjack
Loading...
Searching...
No Matches
Enumerations | Functions
rank.h File Reference

Defines CardRank. More...

#include <cstddef>
#include <iostream>

Go to the source code of this file.

Enumerations

enum class  CardRank {
  rank_2 , rank_3 , rank_4 , rank_5 ,
  rank_6 , rank_7 , rank_8 , rank_9 ,
  rank_10 , rank_jack , rank_queen , rank_king ,
  rank_ace , max_ranks
}
 The rank of a card. More...
 

Functions

char getName (const CardRank rank)
 Get a character representation of a card's rank.
 
CardRank getRank (std::size_t rank)
 Given an integer, get the corresponding rank enum.
 
int getValue (const CardRank rank)
 Get the numeric value of a card's rank.
 
std::size_t getNumRanks ()
 An auxiliary function that defines an upper bound on the number of ranks a deck of cards can have.
 
std::ostream & operator<< (std::ostream &out, const CardRank &rank)
 Overloads << to print the rank of a card.
 

Detailed Description

Defines CardRank.

Author
DSN
Version
0.3
Date
2023-08-19

Enumeration Type Documentation

◆ CardRank

enum class CardRank
strong

The rank of a card.

Enumerator
rank_2 
rank_3 
rank_4 
rank_5 
rank_6 
rank_7 
rank_8 
rank_9 
rank_10 
rank_jack 
rank_queen 
rank_king 
rank_ace 
max_ranks 

Function Documentation

◆ getName()

char getName ( const CardRank  rank)

Get a character representation of a card's rank.

Parameters
rank
Returns
char
  • The character representations of ranks 2 to 9 are the number itself in quotes.
    • Eg: A card with rank rank_5 has the character representation: '5'.
  • The representations of the remaining ranks are listed below:
    • rank_10: 'T'
    • rank_jack: 'J'
    • rank_king: 'K'
    • rank_queen: 'Q'
    • rank_ace: 'A'
  • The default representation is '?'.

◆ getRank()

CardRank getRank ( std::size_t  rank)

Given an integer, get the corresponding rank enum.

Parameters
rank
Returns
CardRank

Type-cast rank to CardRank

◆ getValue()

int getValue ( const CardRank  rank)

Get the numeric value of a card's rank.

Parameters
rank
Returns
int
  • The numeric value of ranks 2 to 9 are their straightforward numeric equivalents.
    • Eg: value of a card with rank 3 is 3.
  • The value of cards with the remaining ranks are listed below:
    • Ranks 10, J, K, Q: 10
    • Rank A: 11

◆ getNumRanks()

std::size_t getNumRanks ( )

An auxiliary function that defines an upper bound on the number of ranks a deck of cards can have.

Returns
std::size_t: max_ranks
  • max_ranks is of type CardRank; You've to typecast it to std::size_t.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const CardRank rank 
)

Overloads << to print the rank of a card.

Parameters
out
obj
Returns
std::ostream&