/*Ian Spangler*/
/*FINAL PROJECT*/
/*solitaire.c: an Accordian Solitaire game*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define CARDWIDTH 16  //keep as even number
#define CARDLENGTH 9  //keep as odd number
void evaluate(char suit, char value, char positionset[][2], char cardset[][2], int var, int n);
void evaluate_auto(char suit, char value, char positionset[][2], char cardset[][2], int var, int n);
void drawNCards(int n, char suit, char value, char positionset[][2]);
void drawCard(char suit, char value, int p, int j, char positionset[][2]);
void hdashes(int p);
void vdashes(int p);
void firstline(char suit, int p, int j, char positionset[][2]);
void lastline(char suit, int p, int j, char positionset[][2]);
void centerline(char value, int p, int j, char positionset[][2]);
void putposition(int j, int p);
void showmenu(int n, char suit, char value, char positionset[][2]);
void instructions(int n, char suit, char value, char positionset[][2]);
void contin(int n, char suit, char value, char positionset[][2]);
void options(int n, char suit, char value, char positionset[][2]);

_Bool cont = 1;        //for instructions menu
_Bool quit = 0;        
int mode = 1;         //for options menu
char select1 = '+';       //for options menu
char select2 = ' ';       //for options menu


int main(void) {

  int var = 52;     //keeps track of number of playing cards remaining to be drawn
  int count;      
  int i;
  int k;
  int n = 4;  //number of cards to be displayed

  int num;     //for random number
  //int num1 = 0;
  //int num2 = 1;
  //int num3 = 2;
  //int num4 = 3;

  char suit;  //variable for the suit of the card (either S, H, D, or C) 
  char value;  //variable for a number value or J, Q, K, A

  char cardset[52][2] = {{'A','H'}, {'A','S'}, {'A','C'}, {'A','D'}, {'2','H'}, {'2','S'}, 
			 {'2','C'}, {'2','D'}, {'3','H'}, {'3','S'}, {'3','C'}, {'3','D'}, 
			 {'4','H'}, {'4','S'}, {'4','C'}, {'4','D'}, {'5','H'}, {'5','S'}, 
			 {'5','C'}, {'5','D'}, {'6','H'}, {'6','S'}, {'6','C'}, {'6','D'}, 
			 {'7','H'}, {'7','S'}, {'7','C'}, {'7','D'}, {'8','H'}, {'8','S'}, 
			 {'8','C'}, {'8','D'}, {'9','H'}, {'9','S'}, {'9','C'}, {'9','D'}, 
			 {'0','H'}, {'0','S'}, {'0','C'}, {'0','D'}, {'J','H'}, {'J','S'}, 
			 {'J','C'}, {'J','D'}, {'Q','H'}, {'Q','S'}, {'Q','C'}, {'Q','D'},
			 {'K','H'}, {'K','S'}, {'K','C'}, {'K','D'}};
  //the set of 52 playing cards accessible by their position number in the array

  char positionset[52][2] = {'1', '2', '3', '4'};   //the order of the playing cards when they are layed out 

  // printf("'%c', '%c'\n", cardset[num1][0], cardset[num1][1]);

  //char positionset[52][2] = {{cardset[num1][0], cardset[num1][1]}, {cardset[num2][0], cardset[num2][1]}, 
  //			     {cardset[num3][0], cardset[num3][1]}, {cardset[num4][0], cardset[num4][1]}}; 

  printf("\n\n");
  printf("                       (Please expand window size to at least 100 x 46)                     \n");
  printf("---------------------------------------------------------------------------------------------");
  printf("\n                               WELCOME TO ACCORDIAN SOLITAIRE\n");
 
  showmenu(n, suit, value, positionset);    //show main menu

  while (quit == 0) {
  
    for (i = 0; i < 52; i += 4) {   //goes through the cardset array and resets all values each time a
      cardset[i][1] = 'H';          //new game is played
    }
    for (i = 1; i < 52; i += 4) {
      cardset[i][1] = 'S';
    }
    for (i = 2; i < 52; i += 4) {
      cardset[i][1] = 'C';
    }
    for (i = 3; i < 52; i += 4) {
      cardset[i][1] = 'D';
    }
    for (i = 0; i < 4; i++) {
      cardset[i][0] = 'A';
    }
    for (i = 4; i < 8; i++) {
      cardset[i][0] = '2';
    }
    for (i = 8; i < 12; i++) {
      cardset[i][0] = '3';
    }
    for (i = 12; i < 16; i++) {
      cardset[i][0] = '4';
    }
    for (i = 16; i < 20; i++) {
      cardset[i][0] = '5';
    }
    for (i = 20; i < 24; i++) {
      cardset[i][0] = '6';
    }
    for (i = 24; i < 28; i++) {
      cardset[i][0] = '7';
    }
    for (i = 28; i < 32; i++) {
      cardset[i][0] = '8';
    }
    for (i = 32; i < 36; i++) {
      cardset[i][0] = '9';
    }
    for (i = 36; i < 40; i++) {
      cardset[i][0] = '0';
    }
    for (i = 40; i < 44; i++) {
      cardset[i][0] = 'J';
    }
    for (i = 44; i < 48; i++) {
      cardset[i][0] = 'Q';
    }
    for (i = 48; i < 52; i++) {
      cardset[i][0] = 'K';
    }

    srand((unsigned) time (0));
    for (count = 1; count <= n; count++) {
      num = (rand() % var);  //get random card
      // n++;                                           //increment number of cards to display by 1
      positionset[count - 1][0] = cardset[num][0];     //place card into next position slot
      positionset[count - 1][1] = cardset[num][1];
      for (i = num; i < var; i++) {                      //eliminate card from deck by shifting values in cardset
	cardset[i][0] = cardset[i + 1][0];               
	cardset[i][1] = cardset[i + 1][1];
      }
      var = var - 1;     //decrease number of cards remaining
    }

    printf("\n\n");
    printf("---------------------------------------------------------------------------------------------");
    printf("\n                                         PLAY GAME\n");
    printf("---------------------------------------------------------------------------------------------");
    printf("\n\n");
    //drawNCards(n, suit, value, positionset);

    //printf("%d", n);
    
    if (mode == 2) {                                    //manual card-drawing mode
      drawNCards(n, suit, value, positionset);                 //display n number of cards, initially n=4
      evaluate(suit, value, positionset, cardset, var, n);      //function to evaluate the cards
    }
    else {
      evaluate_auto(suit, value, positionset, cardset, var, n);        //automatic card-drawing mode
      // drawNCards(n, suit, value, positionset);
    }
    //printf("%d", n);
    //printf("%d\n", num);
    //printf("%c\n", cardset[num][0]);
    //printf("%c\n", positionset[4][0]);
    //printf("'%c', '%c'\n", positionset[num][0], positionset[num][1]);

    //drawNCards(n, suit, value, positionset);
    //}
  }
  printf("\n           Thanks for playing Accordian Solitaire.\n\n");
  return 0;
}

//this function is where the heart of the game's logic takes place

void evaluate_auto(char suit, char value, char positionset[][2], char cardset[][2], int var, int n) {

  int num;  //for rand
  int i;
  int count = 0;        
  int newcardcnt = 0;       //number of new cards drawn at one time
  int choice1, choice2;  //user input for position values

  var = 48;

  while (var >= 0) {

    while (count == 0) {
      if (n > 3) {
	for (i = 2; i <= n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 2][1]) && (positionset[i - 1][0] != positionset[i - 2][0])) {
	    count++;
	  }
	}
	for (i = 4; i <=n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 4][1]) && (positionset[i - 1][0] != positionset[i - 4][0])) {
	    count++;
	  }
	}
      }
      else {
	for (i = 2; i <= n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 2][1]) && (positionset[i - 1][0] != positionset[i - 2][0])) {
	    count++;
	  }
	}
      }	
      if (n > 3) {
	if (count == (n - 1) + (n - 3)) {
	  //printf("%d", count);
	  //printf("%d", n - 1);
	  newcardcnt += 1;
	  num = (rand() % var);  //get random card
	  n++;  //increment number of cards to display by 1
	  positionset[n - 1][0] = cardset[num][0];
	  positionset[n - 1][1] = cardset[num][1];
	  for (i = num; i < var; i++) {
	    cardset[i][0] = cardset[i + 1][0];
	    cardset[i][1] = cardset[i + 1][1];
	  }
	  count = 0;
	}
      }
      else {
	if (count == n - 1) {
	  //printf("%d", count);
	  //printf("%d", n - 1);
	  newcardcnt += 1;
	  num = (rand() % var);  //get random card
	  n++;  //increment number of cards to display by 1
	  positionset[n - 1][0] = cardset[num][0];
	  positionset[n - 1][1] = cardset[num][1];
	  for (i = num; i < var; i++) {
	    cardset[i][0] = cardset[i + 1][0];
	    cardset[i][1] = cardset[i + 1][1];
	  }
	  count = 0;
	}
      }
    }
    if (newcardcnt > 0) {
      if (newcardcnt < var) {
	var = var - newcardcnt;
	drawNCards(n, suit, value, positionset);
	printf("\n %d new card(s) drawn", newcardcnt);
	printf("\n %d cards left", var);
      }
      else {
	var = 0;
	drawNCards(n, suit, value, positionset);
        printf("\n %d new card(s) drawn", newcardcnt);
        printf("\n %d cards left", var);
      }
    }
    else {
      drawNCards(n, suit, value, positionset);
    }
    newcardcnt = 0;
    count = 0;
    
    printf("\n Enter position numbers > Put ");
    scanf("%d", &choice1);

    if ((choice1 > 0) && (choice1 <= n + 1)) {
      printf(" \r\b\r ");  //return to beginning of previous line
      printf("Enter position numbers > Put %d on ", choice1);
      scanf("%d", &choice2);
      
      if ((choice2 > 0) && (choice2 < n + 1)) {
	if (((positionset[choice1 - 1][0] == positionset[choice2 - 1][0]) ||
	     (positionset[choice1 - 1][1] == positionset[choice2 - 1][1])) && ((choice1 == choice2 + 1) ||
									       (choice1 == choice2 + 3))) {
	  positionset[choice2 - 1][0] = positionset[choice1 - 1][0];
	  positionset[choice2 - 1][1] = positionset[choice1 - 1][1];
	  for (i = choice1; i < n; i++) {
	    positionset[i - 1][0] = positionset[i][0];
	    positionset[i - 1][1] = positionset[i][1];
	  }
	  n--; //decrement number of cards to be displayed by 1
	  if (var == 0) {
	    drawNCards(n, suit, value, positionset);
	    var = var - 1;
	  }
	}
	else {
	  printf(" You can't place that card there\n");
	}
      }
      else {
	printf(" Value out of range. Please enter a number between 0 and %d\n", n + 1);
      }
      }
    else if (choice1 == 0) {
      printf("\n\n");
      showmenu(n, suit, value, positionset);
      var = -2;     //can be set to any number below 0 to exit from the loop
    }
    else {
      //printf("%d", choice1);
      printf(" Value out of range. Please enter a number between 0 and %d\n", n + 1);
    }
  }
  if (var != -2) {
    if (n == 1) {
      printf("\n\nWow! One pile! You are truly one of a kind!\n");
    }
    else if ((n > 1) && (n < 4)) {
      printf("\n\nYou did great. You are among the elite in this game.\n");
    }
    else if ((n >= 4) && (n < 7)) {
      printf("\n\nNot bad! You had a decent game.\n");
    }
    else if ((n >=7) && (n < 10)) {
      printf("\n\nYou'll have better games.\n");
    }
    else if ((n >= 10) && (n < 13)) {
      printf("\n\nNot too hot.\n");
    }
    else if (n >= 13) {
      printf("\n\nJeez, you really stink at this, don't you?\n");
    }
    printf("\nGame Over.\n\n");
    showmenu(n, suit, value, positionset);
  }
}

//manual card drawing logic

void evaluate(char suit, char value, char positionset[][2], char cardset[][2], int var, int n) {

  int num;  //for rand
  int i;
  int count = 0;
  int choice1, choice2;  //user input

  var = 48;

  while (var >= 0) {

    printf("\n Enter position numbers > Put ");
    scanf("%d", &choice1);

    if ((choice1 == n + 1) && (var == 0)) {
      printf(" You are all out of cards.\n");
    }
    else if (choice1 == n + 1) {
      //printf("\nEnter position numbers > ");
      //scanf("%d", &choice1);
      num = (rand() % var);  //get random card
      n++;  //increment number of cards to display by 1
      positionset[n - 1][0] = cardset[num][0];
      positionset[n - 1][1] = cardset[num][1];
      for (i = num; i < var; i++) {
	cardset[i][0] = cardset[i + 1][0];
	cardset[i][1] = cardset[i + 1][1];
      }
      var = var - 1;
      drawNCards(n, suit, value, positionset);
      printf("\n %d cards left", var);
      //printf("3");
    }
    else if ((choice1 > 0) && (choice1 < n + 1)) {
      printf(" \r\b\r ");  //return to beginning of previous line
      printf("Enter position numbers > Put %d on ", choice1);
      scanf("%d", &choice2);
      
      if ((choice2 > 0) && (choice2 < n + 1)) {
	if (((positionset[choice1 - 1][0] == positionset[choice2 - 1][0]) ||
	     (positionset[choice1 - 1][1] == positionset[choice2 - 1][1])) && ((choice1 == choice2 + 1) ||
									       (choice1 == choice2 + 3))) {
	  positionset[choice2 - 1][0] = positionset[choice1 - 1][0];
	  positionset[choice2 - 1][1] = positionset[choice1 - 1][1];
	  for (i = choice1; i < n; i++) {
	    positionset[i - 1][0] = positionset[i][0];
	    positionset[i - 1][1] = positionset[i][1];
	  }
	  n--; //decrement number of cards to be displayed by 1
	  drawNCards(n, suit, value, positionset);
	 
	}
	else {
	  printf(" You can't place that card there\n");
	}
      }
      else {
	printf(" Value out of range. Please enter a number between 0 and %d\n", n + 1);
      }
    }
    else if (choice1 == 0) {
      printf("\n\n");
      showmenu(n, suit, value, positionset);
      var = -2;
    }
    else {
      //printf("%d", choice1);
      printf(" Value out of range. Please enter a number between 0 and %d\n", n + 1);
      //choice1 = 1;
    }

    if (var == 0) {
      if (n > 3) {
	for (i = 2; i <= n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 2][1]) && (positionset[i - 1][0] != positionset[i - 2][0])) {
	    count++;
	  }
	}
	for (i = 4; i <= n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 4][1]) && (positionset[i - 1][0] != positionset[i - 4][0])) {
	    count++;
	  }
	}
      }
      else {
	for (i = 2; i <= n; i++) {
	  if ((positionset[i - 1][1] != positionset[i - 2][1]) && (positionset[i - 1][0] != positionset[i - 2][0])) {
	    count++;
	  }
	}
      }
      //printf("%d", count);
      if (n > 3) {
	if (count == (n - 1) + (n - 3)) {
	  var = -5;
	}
      }
      else {
	if (count = n - 1) {
	  var = -5;
	}
      }
      count = 0;
    }
  }

  if (var != -2) {

    if (n == 1) {
      printf("\n\nWow! One pile! You are truly one of a kind!\n");
    }
    else if ((n > 1) && (n < 4)) {
      printf("\n\nYou did great. You are among the elite in this game.\n");
    }
    else if ((n >= 4) && (n < 7)) {
      printf("\n\nNot bad! You had a decent game.\n");
    }    
    else if ((n >=7) && (n < 10)) {
      printf("\n\nYou'll have better games.\n");
    }
    else if ((n >= 10) && (n < 13)) {
      printf("\n\nNot too hot.\n");
    }
    else if (n >= 13) {
      printf("\n\nJeez, you really stink at this, don't you?\n");
    }  
    printf("\nGame Over.\n\n");
    showmenu(n, suit, value, positionset);
  }
}


void showmenu(int n, char suit, char value, char positionset[][2]) {

  int choice;

  printf("---------------------------------------------------------------------------------------------");
  printf("\n\n");
  printf("           1   Instructions              3   Options\n\n");
  printf("           2   Play Game                 4   Quit\n");
  printf("\n\n           Enter the number of your choice: ");

  scanf("%d", &choice);
  while (choice != 2) {
    if (choice == 1) {
      instructions(n, suit, value, positionset);
      if (cont == 0) {
      	choice = 2;
      }
    }
    else if (choice == 4) {
      quit = 1;
      choice = 2;
    }
    else if (choice == 3) {
      options(n, suit, value, positionset);
      choice = 2;
    }    else {
      printf("           Please enter a number between 1 and 4: ");
    }
  }
}


void options(int n, char suit, char value, char positionset[][2]) {
  
  int choice;

  printf("\n\n");
  printf("---------------------------------------------------------------------------------------------");
  printf("                                                         OPTIONS\n");
  printf("---------------------------------------------------------------------------------------------");
  printf("\n\n           1  Automatic Card Drawing (Default) %c\n\n", select1);
  printf("           2  Manual Card Drawing %c\n\n\n", select2);
  printf("           Enter your choice: ");

  scanf("%d", &choice);
  if (choice == 1) {
    mode = 1;
    select1 = '+';
    select2 = ' ';
  }
  else if (choice == 2) {
    mode = 2;
    select2 = '+';
    select1 = ' ';
  }
  else {
    printf("         Please enter either 1 or 2: ");
  }
  showmenu(n, suit, value, positionset);
    
}


void instructions(int n, char suit, char value, char positionset[][2]) {
  // if (cont == 1) {

    n = 4;

    printf("\n\n");
    printf("---------------------------------------------------------------------------------------------");
  printf("                                        INSTRUCTIONS FOR PLAYING THE GAME\n");
  printf("---------------------------------------------------------------------------------------------");
  printf("\n\nIntroduction:\n\n");
  printf("This is a simplified version of the classic Solitaire game. It uses all 52 standard\n");
  printf("playing cards, but has a more linear structure. The object of the game is to end up\n"); 
  printf("with ONE pile of cards.\n\n");
  printf("For the purposes of displaying in your Terminal window, suits have been represented\n");
  printf("using ASCII text according to the following ruleset:\n\n");
  printf("           C = Clubs\n           H = Hearts\n           S = Spades\n           D = Diamonds\n\n");
  printf("In addition, the value '10' has been replaced with '0'.\n\n");
  //printf("---------------------------------------------------------------------------------------------");
  contin(n, suit, value, positionset);

  if (cont == 1) {

    printf("---------------------------------------------------------------------------------------------");
    printf("\n\nGame Play:\n\n");
    printf("1. The game starts with four cards that are dealt automatically and displayed in\n");
    printf("a straight line. Each has a position number for you to refer to each card and keep\n");
    printf("track of them. Underneath, you will be prompted to enter these position numbers on your\n");
    printf("keyboard in order to move the cards around.\n\n");

    positionset[0][0] = 'A';
    positionset[0][1] = 'H';
    positionset[1][0] = '3';
    positionset[1][1] = 'C';
    positionset[2][0] = '9';
    positionset[2][1] = 'S';
    positionset[3][0] = '4';
    positionset[3][1] = 'H';
  
    drawNCards(n, suit, value, positionset);
    printf("\nEnter position numbers > Put ");

    printf("\n\n2. You can place a card on top of a card that has a either a matching suit or\n");
    printf("or a matching value, as long as the card is either ADJACENT to the card on its LEFT, or is\n");
    printf("THREE cards over from a card on the LEFT, meaning you can skip over 2 cards to the left.\n");
    printf("In the above example, card 4 can be placed on card 1. To do this, simply enter the number '4'\n");
    printf("after the Put prompt and press RETURN.\n\n");
    contin(n, suit, value, positionset);

    if (cont == 1) {

      printf("---------------------------------------------------------------------------------------------");
      printf("\n\n");
      drawNCards(n, suit, value, positionset);
      printf("\nEnter position numbers > Put 4");
      printf("\n\nYou will then be prompted to enter the position of the card on which you would like\n");
      printf("to place Card 4. In this case, You can enter '1' and press RETURN. No other value will\n");
      printf("be accepted.\n\n"); 
      drawNCards(n, suit, value, positionset);
      //printf("\nEnter position numbers > Put 4 on ");
      //drawNCards(n, suit, value, positionset);
      printf("\nEnter position numbers > Put 4 on 1\n\n");
      contin(n, suit, value, positionset);

      if (cont == 1) {

	printf("---------------------------------------------------------------------------------------------");
	printf("\n\nThe result is that you now have 3 'piles', as shown below.\n\n");

	positionset[0][0] = '4';
	positionset[0][1] = 'H';
	n = 3;
	drawNCards(n, suit, value, positionset);
	printf("\nEnter position numbers > Put ");
	//	printf("\n\n3. Now, since there are no other matches that we can make, it is time to draw a new\n");
	printf("\n\n3. In automatic card drawing mode (the default option), new cards are dealt\n");
	printf("automatically whenever there are no matches that can be made. In manual card drawing mode,\n");
	printf("however, you are given direct control of this process, which means you can draw\n");
	printf("a new card whenever you wish by by entering a position value one greater than the last card\n");
	printf("displayed in line. In this example, we must enter '4', one greater than 3, to get the new\n");
	printf("card. Press RETURN after entering.\n\n");

	drawNCards(n, suit, value, positionset);
	printf("\nEnter position numbers > Put 4\n\n");
	contin(n, suit, value, positionset);

	if (cont == 1) {
	  printf("---------------------------------------------------------------------------------------------");
	  printf("\n\nThe new card is automatically displayed. Look for another match: Now, the card 4 can\n");
	  printf("go on card 3.\n\n");
	  positionset[3][0] = 'K';
	  positionset[3][1] = 'S';
	  n = 4;
	  drawNCards(n, suit, value, positionset);
	  printf("\nEnter position numbers > Put ");
      
	  printf("\n\n4. Game play continues in this fashion until all cards have been drawn. The aim is to\n");
	  printf("end up with one pile or as few as possible.\n\n");
	  printf("** You may enter '0' after the Put prompt at any time to return to the main menu.");
	  printf("\n\n");
	  showmenu(n, suit, value, positionset);
	  cont = 0;
	  // goback = 1;
	}
      }
    }
  }
  // }
}

void contin(int n, char suit, char value, char positionset[][2]) {   //instructions menu
  
  cont = 1;
  int choice;
  printf("---------------------------------------------------------------------------------------------");
  printf("\n");
  printf("           1   Continue              0   Main Menu            Enter your choice: ");

  scanf("%d", &choice);
  while (choice != 1) {
    if (choice == 0) {
      showmenu(n, suit, value, positionset);
      choice = 1;
      cont = 0;
    }     
    else {
      printf("           Please enter either 1 or 0:\n ");
      choice = 1;
    }
  }  
}


void drawNCards(int n, char suit, char value, char positionset[][2]) {   //draws cards up to the nth card

  int p = 0;
  int i;
  int k;

  for (i = 1; i <= n; i++) {
    drawCard(suit, value, p, i, positionset);
    putposition(i, p);    //prints number of card's position
    p = p + 3;
    if (n > i && (i % 4 == 0)) {
      p = 0;
      printf("\n\n");
    }
    else {
      for (k = 1; k < 13; k++) {
	putchar('\b');
	putchar('\r');
      }
    }
  }
  for (k = 1; k < 13; k++) {
    putchar('\n');
  }
}


void drawCard(char suit, char value, int p, int j, char positionset[][2]) {

  int i;

  hdashes(p);  //creates top edge of card
  firstline(suit, p, j, positionset);  //creates top line that shows the suit
  for (i = 1; i < CARDLENGTH / 2; i++) 
    vdashes(p);  //creates left and right edges of card
  centerline(value, p, j, positionset);  //creates middle line that shows value of card
  for (i = 1; i < CARDLENGTH / 2; i++)
    vdashes(p);
  lastline(suit, p, j, positionset);  //creates bottom line that shows the suit
  hdashes(p);  //creates bottom edge of card 
}

void hdashes(int p) {
  
  char plus = '+';
  int i;

  for (i = 1; i <= p; i++)
    printf("\t");
  printf("%c", plus);
  for (i = 1; i < CARDWIDTH; i++) {
    printf("-");
  }
  printf("%c", plus);
  printf("\n");
}

void firstline(char suit, int p, int j, char positionset[][2]) {

  suit = positionset[j - 1][1];
  char vert = '|';
  int i;

  for (i = 1; i <= p; i++)
    printf("\t");
  printf("%c", vert);
  printf("%c", suit);
  for (i = 2; i < CARDWIDTH; i++)
    printf(" ");
  printf("%c", vert);
  printf("\n");
}

void vdashes(int p) {

  char vert = '|';
  int i;

  for (i = 1; i <= p; i++)
    printf("\t");
  printf("%c", vert);
  for (i = 1; i < CARDWIDTH; i++)
    printf(" ");
  printf("%c", vert);
  printf("\n");
}

void centerline(char value, int p, int j, char positionset[][2]) {

  value = positionset[j - 1][0];

  char vert = '|';
  int i;

  for (i = 1; i <= p; i++)
    printf("\t");
  printf("%c", vert);
  for (i = 1; i < CARDWIDTH / 2; i++)
    printf(" ");
  printf("%c", value);
  for (i = 1; i < CARDWIDTH / 2; i++)
    printf(" ");
  printf("%c", vert);
  printf("\n");
}
      
void lastline(char suit, int p, int j, char positionset[][2]) {

  suit = positionset[j - 1][1];

  char vert = '|';
  int i;

  for (i = 1; i <= p; i++)
    printf("\t");
  printf("%c", vert);
  for (i = 2; i < CARDWIDTH; i++)
    printf(" ");
  printf("%c", suit);
  printf("%c", vert);
  printf("\n");
}

void putposition(int i, int p) {
  
  int k;

  for (k = 1; k <= p; k++)
    printf("\t");
  putchar('[');
  printf("%d", i);
  putchar(']');
}
