File: testcommon.cpp

package info (click to toggle)
dds 2.9.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56,576 kB
  • sloc: cpp: 17,621; ansic: 385; makefile: 27; xml: 11; sh: 7
file content (234 lines) | stat: -rw-r--r-- 4,550 bytes parent folder | download | duplicates (3)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
   DDS, a bridge double dummy solver.

   Copyright (C) 2006-2014 by Bo Haglund /
   2014-2018 by Bo Haglund & Soren Hein.

   See LICENSE and README.
*/


#include <iostream>
#include <iomanip>
#include <vector>

#include "../include/dll.h"
#include "../include/portab.h"

#include "testcommon.h"
#include "TestTimer.h"
#include "parse.h"
#include "loop.h"
#include "compare.h"
#include "print.h"
#include "cst.h"

using namespace std;

string GetSystem();
string GetBits();
string GetCompiler();


const vector<string> DDS_SYSTEM_PLATFORM =
{
  "",
  "Windows",
  "Cygwin",
  "Linux",
  "Apple"
};

const vector<string> DDS_SYSTEM_COMPILER =
{
  "",
  "Microsoft Visual C++",
  "MinGW",
  "GNU g++",
  "clang"
};


extern OptionsType options;
TestTimer timer;


void main_identify();


int realMain(int argc, char * argv[])
{
  UNUSED(argc);
  UNUSED(argv);
  bool GIBmode = false;

  int stepsize = 0;
  if (options.solver == DTEST_SOLVER_SOLVE)
    stepsize = MAXNOOFBOARDS;
  else if (options.solver == DTEST_SOLVER_CALC)
    stepsize = MAXNOOFTABLES;
  else if (options.solver == DTEST_SOLVER_PLAY)
    stepsize = MAXNOOFBOARDS;
  else if (options.solver == DTEST_SOLVER_PAR)
    stepsize = 1;
  else if (options.solver == DTEST_SOLVER_DEALERPAR)
    stepsize = 1;

  set_constants();
  main_identify();

  int number;
  int * dealer_list;
  int * vul_list;
  dealPBN * deal_list;
  futureTricks * fut_list;
  ddTableResults * table_list;
  parResults * par_list;
  parResultsDealer * dealerpar_list;
  playTracePBN * play_list;
  solvedPlay * trace_list;
  if (read_file(options.fname, number, GIBmode, &dealer_list, &vul_list,
        &deal_list, &fut_list, &table_list, &par_list, &dealerpar_list,
        &play_list, &trace_list) == false)
  {
    cout << "read_file failed\n";
    exit(0);
  }

  if (GIBmode && options.solver != DTEST_SOLVER_CALC)
  {
    cout << "GIB file only works works with calc\n";
    exit(0);
  }

  timer.reset();
  timer.setname("Hand stats");

  boardsPBN bop;
  solvedBoards solvedbdp;
  ddTableDealsPBN dealsp;
  ddTablesRes resp;
  allParResults parp;
  playTracesPBN playsp;
  solvedPlays solvedplp;

  if (options.solver == DTEST_SOLVER_SOLVE)
  {
    loop_solve(&bop, &solvedbdp, deal_list, fut_list, number, stepsize);
  }
  else if (options.solver == DTEST_SOLVER_CALC)
  {
    loop_calc(&dealsp, &resp, &parp, deal_list, table_list, 
      number, stepsize);
  }
  else if (options.solver == DTEST_SOLVER_PLAY)
  {
    loop_play(&bop, &playsp, &solvedplp, deal_list, play_list, trace_list, 
      number, stepsize);
  }
  else if (options.solver == DTEST_SOLVER_PAR)
  {
    loop_par(vul_list, table_list, par_list, number, stepsize);
  }
  else if (options.solver == DTEST_SOLVER_DEALERPAR)
  {
    loop_dealerpar(dealer_list, vul_list, table_list, dealerpar_list, 
      number, stepsize);
  }
  else
  {
    cout << "Unknown type " << 
      static_cast<unsigned>(options.solver) << "\n";
    exit(0);
  }

  timer.printHands();

  free(dealer_list);
  free(vul_list);
  free(deal_list);
  free(fut_list);
  free(table_list);
  free(par_list);
  free(dealerpar_list);
  free(play_list);
  free(trace_list);

  return (0);
}


//////////////////////////////////////////////////////////////////////
//                     Self-identification                          //
//////////////////////////////////////////////////////////////////////

string GetSystem()
{
  unsigned sys;
#if defined(_WIN32)
  sys = 1;
#elif defined(__CYGWIN__)
  sys = 2;
#elif defined(__linux)
  sys = 3;
#elif defined(__APPLE__)
  sys = 4;
#else
  sys = 0;
#endif
  
  return DDS_SYSTEM_PLATFORM[sys];
}


string GetBits()
{
  if (sizeof(void *) == 4)
    return "32 bits";
  else if (sizeof(void *) == 8)
    return "64 bits";
  else
    return "unknown";
}


string GetCompiler()
{
  unsigned comp;
#if defined(_MSC_VER)
  comp = 1;
#elif defined(__MINGW32__)
  comp = 2;
#elif defined(__clang__)
  comp = 4; // Out-of-order on purpose
#elif defined(__GNUC__)
  comp = 3;
#else
  comp = 0;
#endif

  return DDS_SYSTEM_COMPILER[comp];
}


void main_identify()
{
  cout << "test program\n";
  cout << string(13, '-') << "\n";

  const string strSystem = GetSystem();
  cout << left << setw(13) << "System" <<
    setw(20) << right << strSystem << "\n";

  const string strBits = GetBits();
  cout << left << setw(13) << "Word size" <<
    setw(20) << right << strBits << "\n";

  const string strCompiler = GetCompiler();
  cout << left << setw(13) << "Compiler" <<
    setw(20) << right << strCompiler << "\n\n";
}