/* To use this:  type
   cc knrsource.c -o knr
   Then knr to run.

   Input format is inflexible (sorry;) see below. 
*/

/* This figures Kaplan and Rubens CCCC for hands read in */
/* How to use it:  just compile and link it up and go.
   Input: hands must be input one suit per line, spades,
   then hearts, then diamonds, then clubs.  Tens are 'T'.
   All spot cards must be specified (yes, this is dumb,
   but that's how I wrote it way back when.)  After four
   suits, an end-of-file must be sent (^D in UNIX.)  After
   it prints the hand and evaluation, another hand can be
   entered.  EOF (^D again) will exit.  The order of the 
   cards within a suit is optional.  Spot cards can be 
   replicated: 2222 is acceptable for four small, but the
   program sometimes looks at spots down to the 8 for 
   evaluation purposes.  Mistyped input will yeild a 
   core dump or other ugly failure.  Sorry.

   So, you could type this:
   KT
   AQJ
   KQ2
   Q2222
   ^D
   It'll print: HCP: 17, K&R: 15.45 
   type a new hand or ^D to exit.
*/

int debug;

#include <stdio.h>

main(argc,argv)
int argc;
char **argv;
{

float cccc(),dkcccc();
int rhand[2][13];
int hand[13];
FILE *fp;
int readhand();

debug = 0;

if (argc == 2)
    fp = fopen(argv[1],"r");
else
    fp = stdin;
   
while (readhand(fp,rhand) != EOF)
    {
    h2toh1(rhand,hand);
    print1(hand);

    printf("hcp = %d\n",hcp(hand));
    printf("K&R = %.2f\n",cccc(hand));
    printf("DK K&R = %.2f\n",dkcccc(hand));
    printf("\n");
    }
}
/* These routines compute statistics about hands */

/* cards are: AKQJ1098765432 in S,H,D,C */
/* deck is N,S,E,W */

#define ACE 0
#define KING 1
#define QUEEN 2
#define JACK 3
#define TEN 4
#define NINE 5
#define EIGHT 6
#define SUIT which_suit[hand[i]]

int hcval[52] = {4,3,2,1,0,0,0,0,0,0,0,0,0,
                 4,3,2,1,0,0,0,0,0,0,0,0,0,
                 4,3,2,1,0,0,0,0,0,0,0,0,0,
                 4,3,2,1,0,0,0,0,0,0,0,0,0};
int which_suit[52] = {0,0,0,0,0,0,0,0,0,0,0,0,0,
	    	      1,1,1,1,1,1,1,1,1,1,1,1,1,
		      2,2,2,2,2,2,2,2,2,2,2,2,2,
		      3,3,3,3,3,3,3,3,3,3,3,3,3};
int hc321[52] = {3,2,1,0,0,0,0,0,0,0,0,0,0,
                 3,2,1,0,0,0,0,0,0,0,0,0,0,
                 3,2,1,0,0,0,0,0,0,0,0,0,0,
                 3,2,1,0,0,0,0,0,0,0,0,0,0};

int hcp(hand)
int *hand;
{
int p;
int i;

p = 0;
for (i=0;i<13;i++)
    p += hcval[hand[i]];
return(p);
}

/* This is Kaplan and Rubens' Complex Computer Count */
float cccc(hand)
int *hand;
{
float p;
int i,j;
float p2;
int shape[4];
int sorted[4];
int s;
float points;
float d;
float p3;
void find_pattern(),sort_pattern();

/* 321 count for Aces, Kings and Queens */
p = 0.;
for (i=0;i<13;i++)
    p += (float) hc321[hand[i]];
if (debug) printf("%f for 321 high cards.\n",p);

/* add length factors */
find_pattern(hand,shape);
p2 = 0;
for (i=0;i<13;i++)
    p2 += hcval[hand[i]]*shape[which_suit[hand[i]]];
if (debug) printf("%f for length.\n",p2/10.);

/* long suits missing useless lower honors bonus */
for (i=0;i<4;i++)
    {  
    if (shape[i] == 7)
	if (!ifhold(hand,QUEEN,i) || !ifhold(hand,JACK,i)) p2 += 7;
    if (shape[i] == 8)
	{
	if      (!ifhold(hand,QUEEN,i)) p2 += 16;
	else if (!ifhold(hand,JACK,i))  p2 +=  8;
	}
    if (shape[i] > 8)
	{
	if (!ifhold(hand,QUEEN,i)) p2 += 2 * shape[i];
	if (!ifhold(hand,JACK ,i)) p2 +=     shape[i];
	}
    }
if (debug) printf("%f length modified for missing lower honors.\n",p2/10.);

/* lower honor suit length mods */
for (i=0;i<4;i++)
    {
    /* tens */
    if (ifhold(hand,TEN,i))
	{
	if (shape[i] > 6)
	    p2 += .5 * shape[i];
	else
	    {
	    j = 0;
            j += ifhold(hand,ACE,i);
            j += ifhold(hand,KING,i);
            j += ifhold(hand,QUEEN,i);
	    if ((j >= 2) || ifhold(hand,JACK,i)) p2 += shape[i];
	    else p2 += .5 * shape[i];
	    }
        }
    /* nines */
    if (ifhold(hand,NINE,i) && (shape[i] <= 6))
	{
	j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
	if ((j >= 2) || ifhold(hand,TEN,i) || ifhold(hand,EIGHT,i)) p2 += .5 * shape[i];
	}
    }
if (debug) printf("%f length modified for tens and nines.\n",p2/10.);
        

/* Distribution adds */
s = 0;
for (i=0;i<4;i++)
    {
    if (shape[i] == 0) s += 3;
    else if (shape[i] == 1) s += 2;
    else if (shape[i] == 2) s += 1;
    }
if (s != 0) s -= 1; 	/* discount 1st doubleton */
if (debug) printf("%d for shape.\n",s);

/* Test for stiff kings and dub queens */
for (i=0;i<13;i++)
    {
    /* kings: only .5 for stiff king */
    if ((hcval[hand[i]] == 3) && (shape[which_suit[hand[i]]] == 1)) p -= 1.5;
    /* short queens */
    if ((hcval[hand[i]] == 2) && (shape[which_suit[hand[i]]] < 3)) 
	{
	/* no count for short queens */
	p -= 1.;
	/* unless Ace or King in same suit */
        if (ifhold(hand,ACE,which_suit[hand[i]]) || 
            ifhold(hand,KING,which_suit[hand[i]])) p += .5;
	/* unless Qx exactly, in which case .25 */
	else if (shape[SUIT] == 2) p += .25;
	}
    /* long queens are demoted .25 if no Ace or King in suit */
    if ((hcval[hand[i]] == 2) && (shape[which_suit[hand[i]]] >= 3)) 
	{
	if (!ifhold(hand,ACE,which_suit[hand[i]]) && 
	    !ifhold(hand,KING,which_suit[hand[i]])) p -= .25;
	}
    
    }
if (debug) printf("%f modified HCP for short kings and queens.\n",p);

/* Lower honors */
p3 = 0.;
for (i=0;i<4;i++)
    {
    /* Jacks are worth .5 if with 2 higher honors */
    if (ifhold(hand,JACK,i))
	{
        j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
	if (j == 2) p3 += .5;
	if (j == 1) p3 += .25;
 	}
    /* Tens are worth .25 with 2 higher or 1 plus the 9 */
    if (ifhold(hand,TEN,i))
	{
        j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
        j += ifhold(hand,JACK,i);
	if (j == 2) p3 += .25;
	if ((j == 1) && ifhold(hand,NINE,i)) p3 += .25;
        }
    }
if (debug) printf("%f for lower honors\n",p3);

/* deduction for 4-3-3-3 */
sort_pattern(shape,sorted);
if (sorted[3] == 3) d = .5;
else d = 0.;
if (debug) printf("-%f for 4-3-3-3.\n",d);

return(p+p2/10.+p3+s-d);
}


void find_pattern(hand,shape)
int *hand,*shape;
{
int i;

shape[0] = 0;
shape[1] = 0;
shape[2] = 0;
shape[3] = 0;

for (i=0;i<13;i++)
    shape[which_suit[hand[i]]]++;
return;
}

void sort_pattern(shapein,shapeout)
int *shapein,*shapeout;
{

int i,j;
int temp;

for (i=0;i<4;i++)
    shapeout[i] = shapein[i];

for (i=0;i<3;i++)
    for (j=i+1;j<4;j++)
	{
	if (shapeout[i] < shapeout[j])
	    {
	    temp = shapeout[i];
	    shapeout[i] = shapeout[j];
            shapeout[j] = temp;
            }
	}
return;
}

/* does the hand hold this card */
int ifhold(hand,rank,suit)
int *hand;
int rank,suit;
{
int i;
for (i=0;i<13;i++)
    if (hand[i] == suit*13+rank) return(1);
return(0);
}

/* This is Kaplan and Rubens' Complex Computer Count with 
   modifications by Danny Kleinman */
float dkcccc(hand)
int *hand;
{
float p;
int i,j;
float p2;
int shape[4];
int sorted[4];
int s;
float points;
float d;
float p3;
float r;
int temp;
void find_pattern(),sort_pattern();

/* 321 count for Aces, Kings and Queens */
p = 0.;
for (i=0;i<13;i++)
    p += (float) hc321[hand[i]];
if (debug) printf("%f for 321 high cards.\n",p);

/* Danny's "richness" */
r = 0.;
for (i=0;i<13;i++)
    r += (float) (hcval[hand[i]] != 0);
r = (hcp(hand)-r*2.5)*.325;
if (debug) printf("%f for richness.\n",r);

/* add length factors */
find_pattern(hand,shape);
p2 = 0;
for (i=0;i<13;i++)
/* first change: number of high cards, rather than HCP */
    p2 += (hcval[hand[i]] != 0)*shape[which_suit[hand[i]]];
if (debug) printf("%f for length.\n",p2/4.);
p2 *= 2.5;

/* long suits missing useless lower honors bonus */
for (i=0;i<4;i++)
    {  
    if (shape[i] == 7)
	if (!ifhold(hand,QUEEN,i) || !ifhold(hand,JACK,i)) p2 += 7;
    if (shape[i] == 8)
	if (!ifhold(hand,QUEEN,i) || !ifhold(hand,JACK,i)) p2 += 16;
    if (shape[i] > 8)
	if (!ifhold(hand,QUEEN,i) || !ifhold(hand,JACK,i)) p2 += 3*shape[i];
    }
if (debug) printf("%f length modified for missing lower honors.\n",p2/10.);

/* lower honor suit length mods */
for (i=0;i<4;i++)
    {
    /* tens */
    if (ifhold(hand,TEN,i))
	{
	if (shape[i] > 6)
	    p2 += .5 * shape[i];
	else
	    {
	    j = 0;
            j += ifhold(hand,ACE,i);
            j += ifhold(hand,KING,i);
            j += ifhold(hand,QUEEN,i);
	    if ((j >= 2) || ifhold(hand,JACK,i)) p2 += shape[i];
	    else p2 += .5 * shape[i];
	    }
        }
    /* nines */
    if (ifhold(hand,NINE,i) && (shape[i] <= 6))
	{
	j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
	if ((j >= 2) || ifhold(hand,TEN,i) || ifhold(hand,EIGHT,i)) p2 += .5 * shape[i];
	}
    }
if (debug) printf("%f length modified for tens and nines.\n",p2/10.);
        

/* Distribution adds */
s = 0;
for (i=0;i<4;i++)
    {
    if (shape[i] == 0) s += 3;
    else if (shape[i] == 1) s += 2;
    else if (shape[i] == 2) s += 1;
    }
if (s != 0) s -= 1; 	/* discount 1st doubleton */
if (debug) printf("%d for shape.\n",s);

/* Test for bare honor suits */
for (j=0;j<4;j++)
    {
    temp = 0;
    for (i=0;i<13;i++)
       if ((SUIT == j) && (hcval[hand[i]] == 0)) temp = 1;
    if ((shape[j] != 0) && (temp == 0)) p -= .5;
    }

if (debug) printf("%f modified HCP for bare honor holdings.\n",p);

/* Lower honors */
p3 = 0.;
for (i=0;i<4;i++)
    {
    /* Jacks are worth .5 if with 2 higher honors */
    if (ifhold(hand,JACK,i))
	{
        j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
	if (j == 2) p3 += .5;
	if (j == 1) p3 += .25;
 	}
    /* Tens are worth .25 with 2 higher or 1 plus the 9 */
    if (ifhold(hand,TEN,i))
	{
        j = 0;
        j += ifhold(hand,ACE,i);
        j += ifhold(hand,KING,i);
        j += ifhold(hand,QUEEN,i);
        j += ifhold(hand,JACK,i);
	if (j == 2) p3 += .25;
	if ((j == 1) && ifhold(hand,NINE,i)) p3 += .25;
        }
    }
if (debug) printf("%f for lower honors\n",p3);

/* deduction for 4-3-3-3 */
sort_pattern(shape,sorted);
if (sorted[3] == 3) d = .5;
else d = 0.;
if (debug) printf("-%f for 4-3-3-3.\n",d);

if (debug) printf("p: %f, r: %f, p2/10: %f, p3: %f, s: %d, d: %f\n",
                   p,r,p2/10.,p3,s,-d);
return(p+p2/10.+p3+s-d+r);
}

char suit[4] = {'S','H','D','C'};
char card[14] = {"AKQJT98765432"};


initdeck(deck)
int *deck;
{
int i;
for (i=0;i<52;i++)
    deck[i] = i;
return;
}

void sorthands(deck)
int *deck;
{
/* dumb bubble sort, but n = 13. */
int i,j;
int temp;

for (i=0;i<12;i++)
    {
    for (j=i+1;j<13;j++)
	{
	if (deck[i] > deck[j])
	    {
	    temp = deck[i];
	    deck[i] = deck[j];
	    deck[j] = temp;
 	    }
 	}
    }
for (i=13;i<25;i++)
    {
    for (j=i+1;j<26;j++)
	{
	if (deck[i] > deck[j])
	    {
	    temp = deck[i];
	    deck[i] = deck[j];
	    deck[j] = temp;
 	    }
 	}
    }
for (i=26;i<38;i++)
    {
    for (j=i+1;j<39;j++)
	{
	if (deck[i] > deck[j])
	    {
	    temp = deck[i];
	    deck[i] = deck[j];
	    deck[j] = temp;
 	    }
 	}
    }
for (i=39;i<51;i++)
    {
    for (j=i+1;j<52;j++)
	{
	if (deck[i] > deck[j])
	    {
	    temp = deck[i];
	    deck[i] = deck[j];
	    deck[j] = temp;
 	    }
 	}
    }
return;
}

printdeal(deck)
int *deck;
{
int i;
int count;

sorthands(deck);

/* print the north hand */
printf("        S: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 13) break;
    printf("%c",card[deck[i]]);
    }
printf("\n");

printf("        H: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 26) break;
    if (deck[i] >= 13) printf("%c",card[deck[i]-13]);
    }
printf("\n");

printf("        D: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 39) break;
    if (deck[i] >= 26) printf("%c",card[deck[i]-26]);
    }
printf("\n");

printf("        C: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 39) printf("%c",card[deck[i]-39]);
    }
printf("\n");

/* print West and East hands */
printf("S: ");
count = 0;
for (i=39;i<52;i++)
    {
    if (deck[i] >= 13) break;
    printf("%c",card[deck[i]]);
    count++;
    }
for (i=0;i<14-count;i++) printf(" ");

printf("S: ");
for (i=26;i<39;i++)
    {
    if (deck[i] >= 13) break;
    printf("%c",card[deck[i]]);
    }
printf("\n");

printf("H: ");
count = 0;
for (i=39;i<52;i++)
    {
    if (deck[i] >= 26) break;
    if (deck[i] >= 13) 
	{
	printf("%c",card[deck[i]-13]);
	count++;
	}
    }
for (i=0;i<14-count;i++) printf(" ");

printf("H: ");
for (i=26;i<39;i++)
    {
    if (deck[i] >= 26) break;
    if (deck[i] >= 13) printf("%c",card[deck[i]-13]);
    }
printf("\n");

printf("D: ");
count = 0;
for (i=39;i<52;i++)
    {
    if (deck[i] >= 39) break;
    if (deck[i] >= 26) 
	{
	printf("%c",card[deck[i]-26]);
	count++;
	}
    }
for (i=0;i<14-count;i++) printf(" ");
printf("D: ");
for (i=26;i<39;i++)
    {
    if (deck[i] >= 39) break;
    if (deck[i] >= 26) printf("%c",card[deck[i]-26]);
    }
printf("\n");

printf("C: ");
count = 0;
for (i=39;i<52;i++)
    {
    if (deck[i] >= 39) 
	{
	printf("%c",card[deck[i]-39]);
	count++;
	}
    }
for (i=0;i<14-count;i++) printf(" ");
printf("C: ");
for (i=26;i<39;i++)
    {
    if (deck[i] >= 39) printf("%c",card[deck[i]-39]);
    }
printf("\n");

/* print the south hand */
printf("        S: ");
for (i=13;i<26;i++)
    {
    if (deck[i] >= 13) break;
    printf("%c",card[deck[i]]);
    }
printf("\n");

printf("        H: ");
for (i=13;i<26;i++)
    {
    if (deck[i] >= 26) break;
    if (deck[i] >= 13) printf("%c",card[deck[i]-13]);
    }
printf("\n");

printf("        D: ");
for (i=13;i<26;i++)
    {
    if (deck[i] >= 39) break;
    if (deck[i] >= 26) printf("%c",card[deck[i]-26]);
    }
printf("\n");

printf("        C: ");
for (i=13;i<26;i++)
    {
    if (deck[i] >= 39) printf("%c",card[deck[i]-39]);
    }
printf("\n");

return;
}


print1(deck)
int *deck;
{
int i;
int count;
void sort1();

sort1(deck);

/* print the hand */
printf("S: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 13) break;
    printf("%c",card[deck[i]]);
    }
printf("\n");

printf("H: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 26) break;
    if (deck[i] >= 13) printf("%c",card[deck[i]-13]);
    }
printf("\n");

printf("D: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 39) break;
    if (deck[i] >= 26) printf("%c",card[deck[i]-26]);
    }
printf("\n");

printf("C: ");
for (i=0;i<13;i++)
    {
    if (deck[i] >= 39) printf("%c",card[deck[i]-39]);
    }
printf("\n");

return;
}

void sort1(deck)
int *deck;
{
/* dumb bubble sort, but n = 13. */
int i,j;
int temp;

for (i=0;i<12;i++)
    {
    for (j=i+1;j<13;j++)
	{
	if (deck[i] > deck[j])
	    {
	    temp = deck[i];
	    deck[i] = deck[j];
	    deck[j] = temp;
 	    }
 	}
    }
return;
}
/* This program reads in a hand in the format
	spades
	hearts
	diamonds
	clubs

	spades
	...

   So, different hands have blank lines between them.
   Voids are indicated ---.  Tens are "T".
   The result is an array 13 by 2, level 0 is suit:
	1 = spades
	2 = hearts
	3 = diamonds
	4 = clubs
   Level 1 is card: 1 = Ace, 2 = Deuce, ... , 13 = King.
*/

int readhand(file,hand)
FILE *file; 			/* file is open already */
int hand[2][13];
{
char line[30];			/* input buffer */
int i;				/* loop index   */
int h;				/* hand pointer: next free */
int s;				/* suit on which we are working (1=spades, ...) */

h = 0;
/* read spades, perhaps skipping blank line */
if (fgets(line,20,file) == (char *)0) return(EOF);
if (strlen(line) == 0) fgets(line,20,file);
for (s=1;s<=4;s++)
  {
  for (i=0;i<strlen(line);i++)
    {
    switch (line[i])
	{
	case '-':
	    break;
	case 'A':
	case 'a':
	    hand[0][h] = s;
	    hand[1][h++] = 1;
	    break;
	case 'K':
	case 'k':
	    hand[0][h] = s;
	    hand[1][h++] = 13;
	    break;
	case 'Q':
	case 'q':
	    hand[0][h] = s;
	    hand[1][h++] = 12;
	    break;
	case 'J':
	case 'j':
	    hand[0][h] = s;
	    hand[1][h++] = 11;
	    break;
	case 'T':
	case 't':
 	case '1':
	    hand[0][h] = s;
	    hand[1][h++] = 10;
	    break;
	case '9':
	    hand[0][h] = s;
	    hand[1][h++] = 9;
	    break;
	case '8':
	    hand[0][h] = s;
	    hand[1][h++] = 8;
	    break;
	case '7':
	    hand[0][h] = s;
	    hand[1][h++] = 7;
	    break;
	case '6':
	    hand[0][h] = s;
	    hand[1][h++] = 6;
	    break;
	case '5':
	    hand[0][h] = s;
	    hand[1][h++] = 5;
	    break;
	case '4':
	    hand[0][h] = s;
	    hand[1][h++] = 4;
	    break;
	case '3':
	    hand[0][h] = s;
	    hand[1][h++] = 3;
	    break;
	case '2':
	case 'X':
	case 'x':
	    hand[0][h] = s;
	    hand[1][h++] = 2;
	    break;
	default:
	    break;
        }
    }
  fgets(line,20,file);
  }
if (h != 13) printf("Apparently corrupted hand; contains %d cards.\n",h);
return(0);
}

/* This routine sorts the hand by suits: spades hearts clubs diamonds.
   This is to alternate colors. 					*/

colorsort(hand)
int hand[2][13];
{
int hold[2][13];	/* temporary copy   */
int i,j;		/* counters 	    */
int h;			/* pointer	    */
int order[4];		/* order of the suits */

order[0] = 1;
order[1] = 2;
order[2] = 4;
order[3] = 3;

/* make a copy of the hand */
for (i=0;i<13;i++)
    {
    hold[0][i] = hand[0][i];
    hold[1][i] = hand[1][i];
    }

/* move cards into hand */
h = 0;
for (j=0;j<4;j++)
    for (i=0;i<13;i++)
        if (hold[0][i] == order[j])
	    {
	    hand[0][h] = hold[0][i];
	    hand[1][h] = hold[1][i];
	    h++;
 	    }
return;
}

int trans[13] = {0,12,11,10,9,8,7,6,5,4,3,2,1};

/* converts from hands in [2][13] form to [13] form */
h2toh1(handin,handout)
int handin[2][13];
int handout[13];
{
int i;
for (i=0;i<13;i++)
    handout[i] = 13 * (handin[0][i] - 1) + trans[handin[1][i]-1];
return;
}

int stringhand(string,hand)
char **string;
int hand[2][13];
{
char line[30];			/* input buffer */
int i;				/* loop index   */
int s;				/* suit on which we are working (1=spades, ...) */
int h;

h = 0;

for (s=1;s<=4;s++)
  {
  for (i=0;i<strlen(string[s-1]);i++)
    {
    switch (string[s-1][i])
	{
	case '-':
	    break;
	case 'A':
	case 'a':
	    hand[0][h] = s;
	    hand[1][h++] = 1;
	    break;
	case 'K':
	case 'k':
	    hand[0][h] = s;
	    hand[1][h++] = 13;
	    break;
	case 'Q':
	case 'q':
	    hand[0][h] = s;
	    hand[1][h++] = 12;
	    break;
	case 'J':
	case 'j':
	    hand[0][h] = s;
	    hand[1][h++] = 11;
	    break;
	case 'T':
	case 't':
 	case '1':
	    hand[0][h] = s;
	    hand[1][h++] = 10;
	    break;
	case '9':
	    hand[0][h] = s;
	    hand[1][h++] = 9;
	    break;
	case '8':
	    hand[0][h] = s;
	    hand[1][h++] = 8;
	    break;
	case '7':
	    hand[0][h] = s;
	    hand[1][h++] = 7;
	    break;
	case '6':
	    hand[0][h] = s;
	    hand[1][h++] = 6;
	    break;
	case '5':
	    hand[0][h] = s;
	    hand[1][h++] = 5;
	    break;
	case '4':
	    hand[0][h] = s;
	    hand[1][h++] = 4;
	    break;
	case '3':
	    hand[0][h] = s;
	    hand[1][h++] = 3;
	    break;
	case '2':
	case 'X':
	case 'x':
	    hand[0][h] = s;
	    hand[1][h++] = 2;
	    break;
	default:
	    break;
        }
    }
  }
if (h != 13) return(1);
return(0);
}

