-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpbn.cpp
91 lines (74 loc) · 2.47 KB
/
pbn.cpp
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
/* This routine prints a hand in PBN format
Added by Henk Uijterwaal, Feb 1999 */
#include <stdio.h>
#include <time.h>
#include "card.h"
#include "dealer.h"
#include "pbn.h"
#include "tree.h"
extern char* input_file;
int printpbn (int board, const union board *d) {
/* Symbols for the cards */
const char representation[] = "23456789TJQKA";
/* Mnemonics for vulnerability and dealer */
const char *vulner_name[] = { "None", "NS", "EW", "All" };
const char *dealer_name[] = { "N", "E", "S", "W" };
/* Who's vulnerable on which boards */
const int board_vul[] = { 0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2 };
/* Local variables */
time_t timet;
char timearray[12];
int player, suit, rank;
printf ("[Event \"Hand simulated by dealer with file %s",
input_file);
if (gptr->seed_provided) {
printf (", seed %u", gptr->seed[0]);
for (unsigned i = 1; i < gptr->seed_provided; i++) {
printf (",%u", gptr->seed[i]);
}
}
printf ("\"]\n");
printf ("[Site \"-\"]\n");
/* Today's date */
timet = time(&timet);
strftime (timearray, 12, "%Y.%m.%d", localtime(&timet));
printf ("[Date \"%s\"]\n", timearray);
printf ("[Board \"%d\"]\n", board+1);
/* Blank tags for the players */
printf ("[West \"-\"]\n");
printf ("[North \"-\"]\n");
printf ("[East \"-\"]\n");
printf ("[South \"-\"]\n");
/* Dealer, rotates unless set by the user */
if ((gptr->maxdealer < 0) || (gptr->maxdealer > 3)) {
printf ("[Dealer \"%s\"]\n", dealer_name[board%4]);
} else {
printf ("[Dealer \"%s\"]\n", dealer_name[gptr->maxdealer]);
}
/* Vulnerability, rotates unless set by the user */
if ((gptr->maxvuln < 0) || (gptr->maxvuln > 3)) {
printf ("[Vulnerable \"%s\"]\n", vulner_name[board_vul[board%16]]);
} else {
printf ("[Vulnerable \"%s\"]\n", vulner_name[gptr->maxvuln]);
}
/* Print the cards */
printf ("[Deal \"N:");
for (player=COMPASS_NORTH; player<=COMPASS_WEST; player++) {
for (suit = SUIT_SPADE; suit>= SUIT_CLUB; suit--) {
for (rank=12; rank >= 0; rank--) {
if (HAS_CARD(d, player, MAKECARD(suit,rank))) {
printf ("%c", representation[rank]);
}
}
if (suit > SUIT_CLUB) { printf (".");}
}
if (player < COMPASS_WEST) {printf (" ");}
}
printf ("\"]\n");
/* Blank tags for declarer etc */
printf ("[Declarer \"?\"]\n");
printf ("[Contract \"?\"]\n");
printf ("[Result \"?\"]\n");
printf ("\n");
return 0;
}