File: deck_astud.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 (95 lines) | stat: -rw-r--r-- 2,616 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
/*
 *  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 <ctype.h>
#include "poker_defs.h"
#include "deck_astud.h"

const char AStudDeck_rankChars[] = "%%%%%789TJQKA";
const char AStudDeck_suitChars[] = "hdcs";

int 
AStudDeck_cardToString(int cardIndex, char *outString) {
  *outString++ = AStudDeck_rankChars[AStudDeck_RANK(cardIndex)];
  *outString++ = AStudDeck_suitChars[AStudDeck_SUIT(cardIndex)];
  *outString   = '\0';

  return 2;
}


int 
AStudDeck_stringToCard(char *inString, int *cardIndex) {
  char *p;
  int rank, suit;

  p = inString;
  for (rank=AStudDeck_Rank_FIRST; rank <= AStudDeck_Rank_LAST; rank++) 
    if (AStudDeck_rankChars[rank] == toupper(*p))
      break;
  if (rank > AStudDeck_Rank_LAST)
    goto noMatch;
  ++p;
  for (suit=AStudDeck_Suit_FIRST; suit <= AStudDeck_Suit_LAST; suit++) 
    if (AStudDeck_suitChars[suit] == tolower(*p))
      break;
  if (suit > AStudDeck_Suit_LAST)
    goto noMatch;
  *cardIndex = AStudDeck_MAKE_CARD(rank, suit);
  return 2;

 noMatch:
  /* Didn't match anything, return failure */
  return 0;
}


int
AStudDeck_maskToCards(void *cardMask, int cards[]) {
  int i, n=0;
  AStudDeck_CardMask c = *((AStudDeck_CardMask *) cardMask);

  for (i=AStudDeck_N_CARDS-1; i >= 0; i--) 
    if (AStudDeck_CardMask_CARD_IS_SET(c, i)) 
      cards[n++] = i;

  return n;
}

int 
AStudDeck_NumCards(void *cardMask) {
  AStudDeck_CardMask c = *((AStudDeck_CardMask *) cardMask);
  int i;
  int ncards = 0;
  for (i=0; i<AStudDeck_N_CARDS; i++)
    if (AStudDeck_CardMask_CARD_IS_SET(c, i))
      ncards++;
  return ncards;
}

Deck AStudDeck = { 
  AStudDeck_N_CARDS, 
  "AsianStudDeck", 
  AStudDeck_cardToString, 
  AStudDeck_stringToCard,
  AStudDeck_maskToCards,
  AStudDeck_NumCards
};