private static int countCombinations (long deadcards, int toprank, int botrank)
  {
    int topcount = 0;
    int botcount = 0;

    for (int s=0; s<4; s++)
      if ( (deadcards & (0x01L<<(toprank+13*s))) == 0)
  	topcount++;
    if (botrank == -1)
      {
  	switch (topcount)
  	  {
  	  case 2:
  	    return 1;
  	  case 3:
  	    return 3;
  	  case 4:
  	    return 6;
  	  default:
  	    // there must be at least two cards for this case to work.
  	    // other values indicate 0 combinations
  	    return 0;
  	  }
      }
    else
      {
  	for (int s=0; s<4; s++)
  	  if ( (deadcards & (0x01L<<(botrank+13*s))) == 0)
  	    botcount++;
  	return topcount*botcount;
      }
  }