File: ddsLookup.h

package info (click to toggle)
deal 3.1.9-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,552 kB
  • sloc: ansic: 5,224; cpp: 4,186; tcl: 3,125; makefile: 200; sh: 10
file content (65 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "ddsInline.h"
#ifndef __DDS_LOOKUP_H__
#define __DDS_LOOKUP_H__
/*
 * This header defines some inline functions which do global lookups for DDS
 * These functions are:
 *
 *  CountOnes(holding_t) - counts the cards in a holding
 *
 *  getHighestRank(holding_t) - returns the rank (2-14) of the highest
 *     card in the holding
 *
 *  getTopCards(holding_t h,int n) - returns a holding consisting of the top n cards
 *     in holding h   
 *
 * Your application must call initializeDDSLookup() to use these lookup tables
 */

/*
struct topCardsType {
  holding_t topCards[14];
};
*/

/* In dds code, counttable is local, but since I've already got a counttable in
   Deal, I reference that table instead */
extern "C" unsigned short int counttable[];

extern int highestRankLookup[8192];

extern holding_t topCardsLookup[14][8192];

inline unsigned short int CountOnes(holding_t holding) {
  return counttable[holding];
}

inline int getHighestRank(holding_t holding) {
  return highestRankLookup[holding];
}

inline holding_t getTopCards(holding_t holding, int count) {
  return topCardsLookup[count][holding];
}

inline void initializeDDSLookup() {
  int n,rank;
  holding_t holding;
  highestRankLookup[0] = 0;
  for (n=0; n<14; n++) { topCardsLookup[n][0] = 0; }

  for (rank=2; rank<=14; rank++) {
    holding_t highestBitRank = BitRank(rank);
    for (holding=highestBitRank; holding<2*highestBitRank; holding++) {
      highestRankLookup[holding] = rank;
      holding_t rest = holding & (~highestBitRank);
      topCardsLookup[0][holding] = 0;
      for (n=1; n<14; n++) {
        topCardsLookup[n][holding] = 
	  highestBitRank | topCardsLookup[n-1][rest];
      }
    }
  }
}

#endif