Task

Create a data structure and the associated methods to define and manipulate a deck of   playing cards.

The deck should contain 52 unique cards.

The methods must include the ability to:

   make a new deck
   shuffle (randomize) the deck
   deal from the deck
   print the current contents of a deck 
Each card must have a pip value and a suit value which constitute the unique value of the card.

Related tasks:

 Card shuffles
 Deal cards_for_FreeCell
 War Card_Game
 Poker hand_analyser
 Go Fish


const val FACES = "23456789TJQKA"
const val SUITS = "shdc"
 
fun createDeck(): List<String> {
    val cards = mutableListOf<String>()
    FACES.forEach { face -> SUITS.forEach { suit -> cards.add("$face$suit") } }
    return cards
}
 
fun dealTopDeck(deck: List<String>, n: Int) = deck.take(n)
 
fun dealBottomDeck(deck: List<String>, n: Int) = deck.takeLast(n).reversed()
 
fun printDeck(deck: List<String>) {
    for (i in deck.indices) {
        print("${deck[i]}  ")
        if ((i + 1) % 13 == 0 || i == deck.size - 1) println()
    }
}
 
fun main(args: Array<String>) {
    var deck = createDeck()
    println("After creation, deck consists of:")
    printDeck(deck)
    deck = deck.shuffled()
    println("\nAfter shuffling, deck consists of:")
    printDeck(deck)
    val dealtTop = dealTopDeck(deck, 10)
    println("\nThe 10 cards dealt from the top of the deck are:")
    printDeck(dealtTop)
    val dealtBottom = dealBottomDeck(deck, 10)
    println("\nThe 10 cards dealt from the bottom of the deck are:")
    printDeck(dealtBottom)
}