File: mktab_evx.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 (160 lines) | stat: -rw-r--r-- 4,181 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
149
150
151
152
153
154
155
156
157
158
159
160
/*
 *  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 <assert.h>

#include "poker_defs.h"
#include "evx_defs.h"
#include "mktable.h"

/* 
 * Generate tables used by the evalExactlyN functions.  These have the
 * hand values pre-built, with the hand-type already ORed in, so that
 * the return value can be returned quickly, at the cost of having many
 * large lookup tables.
 */

#define TV_COMMENT_STRING \
 "evxTripsValueTable[].  Maps 13-bit rank masks to a value identifying\n" \
 "the top two bits (kickers) of the input mask and the hand value for TRIPS."
#define TV_FILENAME "t_evx_tripsval"

#define PV_COMMENT_STRING \
 "evxPairValueTable[].  Maps 13-bit rank masks to a value identifying\n" \
 "the top three bits (kickers) of the input mask and the hand value for PAIR."
#define PV_FILENAME "t_evx_pairval"

#define SV_COMMENT_STRING \
 "evxStrValueTable[].  Maps 13-bit rank masks to a value identifying\n" \
 "the high bit of the straight and the hand value for STRAIGHT."
#define SV_FILENAME "t_evx_strval"

#define FC_COMMENT_STRING \
 "evxFlushCardsTable[].  Maps 13-bit rank masks to a value identifying\n" \
 "whether there are five or more bits set, and if so which bits. "
#define FC_FILENAME "t_evx_flushcards"


static void 
doTripsValueTable(void) {
  int i;

  MakeTable_begin("evxTripsValueTable", 
                  TV_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(TV_COMMENT_STRING);
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    uint32 val, cards;

    cards = i;
    val = top_bit_func(cards);
    cards ^= val;
    val |= top_bit_func(cards);
    if (val)
      val |= EvxHandVal_TRIPS;
    MakeTable_outputUInt32(val);
  };

  MakeTable_end();
}


static void 
doStraightValueTable(void) {
  int i;

  MakeTable_begin("evxStrValueTable", 
                  SV_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(SV_COMMENT_STRING);
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    uint32 sv, val;

    sv = straight_func(i);
    val = sv ? 
      (1 << sv) | EvxHandVal_STRAIGHT : 0;
    MakeTable_outputUInt32(val);
  };

  MakeTable_end();
}


static void 
doPairValueTable(void) {
  int i;

  MakeTable_begin("evxPairValueTable", 
                  PV_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(PV_COMMENT_STRING);
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    uint32 retval, cards, temp;

    cards = i;
    retval = top_bit_func(cards);
    cards ^= retval;
    temp = top_bit_func(cards);
    retval ^= temp;
    cards ^= temp;
    retval |= top_bit_func(cards) 
              | EvxHandVal_ONEPAIR;

    MakeTable_outputUInt32(retval);
  };

  MakeTable_end();
}


static void 
doFlushCardsTable(void) {
  int i;

  MakeTable_begin("evxFlushCardsTable", 
                  FC_FILENAME, 
                  "uint32", 
                  StdDeck_N_RANKMASKS);
  MakeTable_comment(FC_COMMENT_STRING);
  for (i=0; i < StdDeck_N_RANKMASKS; i++) {
    uint32 val;

    val = (n_bits_func(i) >= 5) ? i : 0;
    MakeTable_outputUInt32(val);
  };

  MakeTable_end();
}


int 
main(int argc, char **argv) {
  doPairValueTable();
  doStraightValueTable();
  doTripsValueTable();
  doFlushCardsTable();

  return 0;
}