home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume15 / accordian / part01 / cards.c < prev    next >
C/C++ Source or Header  |  1993-01-27  |  958b  |  87 lines

  1. /*
  2.  * cards.c - generic card utilities
  3.  */
  4.  
  5. #include "cards.h"
  6.  
  7. char *cards[] = {
  8.         "A",
  9.         "2",
  10.         "3",
  11.         "4",
  12.         "5",
  13.         "6",
  14.         "7",
  15.         "8",
  16.         "9",
  17.         "10",
  18.         "J",
  19.         "Q",
  20.         "K"
  21.     };
  22.  
  23. char *cardnames[] = {
  24.         "Ace",
  25.         "Two",
  26.         "Three",
  27.         "Four",
  28.         "Five",
  29.         "Six",
  30.         "Seven",
  31.         "Eight",
  32.         "Nine",
  33.         "Ten",
  34.         "Jack",
  35.         "Queen",
  36.         "King"
  37.     };
  38.  
  39. char *suits[] = {
  40.         "S",
  41.         "H",
  42.         "C",
  43.         "D"
  44.     };
  45.  
  46. char *suitnames[] = {
  47.         "Spades",
  48.         "Hearts",
  49.         "Clubs",
  50.         "Diamonds"
  51.     };
  52.  
  53. shuffle()
  54. {
  55.     int i;
  56.     for (i=0; i<52; i++) {
  57.         swap(i,RANDOM() % 52);
  58.     }
  59. }
  60.  
  61. swap(card1,card2)
  62. int card1, card2;
  63. {
  64.     int face, suit;
  65.  
  66.     face = deck[card1].face;
  67.     deck[card1].face = deck[card2].face;
  68.     deck[card2].face = face;
  69.  
  70.     suit = deck[card1].suit;
  71.     deck[card1].suit = deck[card2].suit;
  72.     deck[card2].suit = suit;
  73. }
  74.  
  75. newdeck()
  76. {
  77.     int face;
  78.     int suit;
  79.  
  80.     for (face = 0; face < 13; face++) {
  81.         for (suit=0; suit<4; suit++) {
  82.             deck[suit*13+face].face = face;
  83.             deck[suit*13+face].suit = suit;
  84.         }
  85.     }
  86. }
  87.