File: mktab_lowball.c

package info (click to toggle)
poker-eval 134.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,544 kB
  • ctags: 1,587
  • sloc: ansic: 15,340; sh: 8,928; cs: 785; makefile: 276
file content (148 lines) | stat: -rw-r--r-- 4,241 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 *  Copyright 2006 Michael Maurer <mjmaurer@yahoo.com>, 
 *                 Brian Goetz <brian@quiotix.com>, 
 *                 Loic Dachary <loic@dachary.org>, 
 *                 Tim Showalter <tjs@psaux.com>
 *
 *  This package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 dated June, 1991.
 *
 *  This package is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this package; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 *  MA 02110-1301, USA.
 */
#include <stdio.h>

#include "poker_defs.h"
#include "mktable.h"
#include "handval_low.h"

#define B5C_COMMENT_STRING \
 "bottomFiveCardsTable[].  Maps 13-bit rank masks to a HandVal with\n" \
 "the xx_card fields representing the low five bits set.  \n" \
 "If there are not five unique bits set, value is\n" \
 "zero.  Treats 2 as low and A as high bits; to do A-5 low evaluation, \n" \
 "you will need to rotate the input mask.\n"  
#define B5C_FILENAME "t_botfivecards"

#define B5J_COMMENT_STRING \
 "bottomFiveJokerTable[].  Maps 13-bit rank masks to a HandVal with\n" \
 "the xx_card fields representing the low five bits set, assuming there.  \n" \
 "is a joker in the hand. If there are not five unique bits set, value is\n" \
 "zero.  Treats 2 as low and A as high bits; to do A-5 low evaluation, \n" \
 "you will need to rotate the input mask.\n"  
#define B5J_FILENAME "t_botfivecardsj"

#define BC_COMMENT_STRING \
 "bottomCardTable[].  Maps 13-bit rank masks to a number identifying the\n" \
 "low bit that is set.  If the input has no bits set, the answer is not\n" \
 "meaningful. \n" \
 "Treats 2 as low and A as high bits; to do A-5 low evaluation, \n" \
 "you will need to rotate the input mask.\n"  
#define BC_FILENAME "t_botcard"

static void 
doBottomFiveCardsTable(void) {
  int i, j, card;

  MakeTable_begin("bottomFiveCardsTable", 
                  B5C_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(B5C_COMMENT_STRING);
  MakeTable_comment("If there are not five unique ranks, returns zero");
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    LowHandVal eval;
    int n = i;

    eval = 0;
    for (j=0; j<5; j++) {
      if (n == 0) {
        eval = 0;
        break;
      };
      card = bottom_card_func(n);
      eval += (card << j*HandVal_CARD_WIDTH);
      n &= ~(1 << card);
    };

    MakeTable_outputUInt32(eval);
  };

  MakeTable_end();
}


static void 
doBottomFiveJokerTable(void) {
  int i, j, card;

  MakeTable_begin("bottomFiveJokerTable", 
                  B5J_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(B5J_COMMENT_STRING);
  MakeTable_comment("If there are not five unique ranks, returns zero");
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    LowHandVal eval;
    int n = i;

    eval = 0;

    /* Set the bottommost unset bit */
    for (j=0; j<StdDeck_Rank_COUNT; j++) 
      if (!(i & (1 << j))) {
        i |= (1 << j);
        break;
      };
    
    for (j=0; j<5; j++) {
      if (n == 0) {
        eval = 0;
        break;
      };
      eval <<= HandVal_CARD_WIDTH;
      card = bottom_card_func(n);
      eval += card;
      n &= ~(1 << card);
    };

    MakeTable_outputUInt32(eval);
  };

  MakeTable_end();
}


static void 
doBottomCardTable(void) {
  int i;

  MakeTable_begin("bottomCardTable", 
                  BC_FILENAME, 
                  "uint8", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(BC_COMMENT_STRING);
  MakeTable_comment("Value is only meaningful if there is actually a bit set");
  for (i=0; i < StdDeck_N_RANKMASKS; i++) 
    MakeTable_outputUInt8(bottom_card_func(i));

  MakeTable_end();
}


int 
main(int argc, char **argv) {
  doBottomFiveCardsTable();
  doBottomFiveJokerTable();
  doBottomCardTable();
  return 0;
}