Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
optable.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 //
3 // FILE: optable.h
4 // OpTable class (for opening reports and theory tables)
5 //
6 // Part of: Scid (Shane's Chess Information Database)
7 // Version: 3.5
8 //
9 // Notice: Copyright (c) 2001-2003 Shane Hudson. All rights reserved.
10 //
11 // Author: Shane Hudson (sgh@users.sourceforge.net)
12 //
13 //////////////////////////////////////////////////////////////////////
14 
15 #ifndef SCID_OPTABLE_H
16 #define SCID_OPTABLE_H
17 
18 #include "common.h"
19 #include "game.h"
20 #include "indexentry.h"
21 #include <string>
22 class PBook;
23 
30 const uint OPTABLE_MAX_LINES = 2000;
31 const uint OPTABLE_MAX_TABLE_LINES = 5000;//500;
33 
34 const uint OPTABLE_Text = 0;
35 const uint OPTABLE_HTML = 1;
36 const uint OPTABLE_LaTeX = 2;
37 const uint OPTABLE_CText = 3; // Color hypertext.
38 const uint OPTABLE_Compact = 4; // For more compact moves in table.
39 
40 // Positional themes
41 const uint NUM_POSTHEMES = 10;
47 const uint POSTHEME_WIQP = 5;
48 const uint POSTHEME_BIQP = 6;
52 const uint POSTHEME_THRESHOLD = 4; // Theme must occur this many times.
53 
54 const uint NUM_EGTHEMES = 8;
55 const uint EGTHEME_P = 0;
56 const uint EGTHEME_M = 1;
57 const uint EGTHEME_R = 2;
58 const uint EGTHEME_RM = 3;
59 const uint EGTHEME_Q = 4;
60 const uint EGTHEME_QM = 5;
61 const uint EGTHEME_QR = 6;
62 const uint EGTHEME_QRM = 7;
63 
64 const uint OPTABLE_Line = 0;
65 const uint OPTABLE_All = 1;
66 
67 
68 struct moveOrderT {
69  uint id; // Move Order id number
70  uint count; // Number of times this order has occurred
71  char * moves; // String containing the moves in SAN notation
72 };
73 
74 class OpLine
75 {
76  friend class OpTable;
77  private:
78  char * White;
79  char * Black;
80  char * Site;
81  gamenumT GameNumber;
82  idNumberT WhiteID;
83  idNumberT BlackID;
84  eloT WhiteElo; // Actual White rating (no estimate)
85  eloT BlackElo; // Actual Black rating
86  eloT AvgElo; // Average Elo (using actual or estimates)
87  dateT Date;
89  uint Length;
90  uint NumMoves;
91  bool ShortGame; // True if all game ends early enough that
92  // this line contains all its moves.
93  ecoT EcoCode;
94  uint MoveOrderID;
96  uint NoteMoveNum; // If a note, at what move does it start?
97  uint NoteNumber; // If a note, this stores its footnote number.
98  OpLine * Next; // Linked list used for sorting and footnotes.
99  bool Selected; // For selecting lines by some criteria.
100  uint StartPly;
101 
102  uint Theme [NUM_POSTHEMES];
103  uint EgTheme;
104 
105  void Init (void);
106  void Init (Game * g, const IndexEntry * ie, gamenumT gameNum,
107  uint maxExtraMoves, uint maxThemeMoveNumber);
108  void Destroy (void);
109 
110  public:
111  OpLine () { Init(); }
112  OpLine (Game * g, const IndexEntry * ie, gamenumT gnum, uint max, uint tm) {
113  Init (g, ie, gnum, max, tm);
114  }
115  ~OpLine() { Destroy(); }
116  void SetPositionalThemes (Position * pos);
117  void Insert (OpLine * subline);
118  void SetMoveOrderID (uint id) { MoveOrderID = id; }
119  uint CommonLength (OpLine * line);
120  static void PrintMove (DString * dstr, const char * move, uint format);
121  void PrintNote (DString * dstr, uint movenum, uint start, uint format);
122  void PrintSummary (DString * dstr, uint format, bool fullDate, bool nmoves);
123 
124  const char * GetMove (uint depth) { return Move[depth]; }
125 };
126 
127 
128 class OpTable
129 {
130  private:
131  uint NumRows;
132  uint TargetRows;
133  uint NumLines;
134  uint FilterCount;
135  uint NumTableLines;
136  uint MaxTableLines;
137  uint MaxNoteLength;
138  uint MaxThemeMoveNumber;
139  uint NumNotes;
140  uint Format;
141  char * Type; // "opening" or "player" report
142  bool WTM; // whether White is to move in the start position.
143  sanStringT StartLine [OPTABLE_MAX_STARTLINE];
144  uint StartLength;
145  OpLine * Line [OPTABLE_MAX_LINES];
146  uint Results [NUM_RESULT_TYPES];
147  uint TheoryResults [NUM_RESULT_TYPES];
148  uint TheoryCount;
149  std::string ECOstr_;
150  sanStringT ExcludeMove;
151  char DecimalChar;
152 
153  // Statistics on material of final positions:
154  uint EndgameCount [2][NUM_EGTHEMES];
155 
156  // Statistics on move orders to reach the start line:
157  uint NumMoveOrders;
158  moveOrderT MoveOrder [OPTABLE_MAX_LINES];
159 
160  // Statistics on themes:
161  uint ThemeCount [NUM_POSTHEMES];
162 
163  // Arrays for making rows out of the lines:
165  uint NLines [OPTABLE_MAX_TABLE_LINES];
166  uint RowScore [OPTABLE_MAX_TABLE_LINES];
167 
168  void SelectTableLines (void);
169  void SortTableLines (OpLine ** lines, uint nlines, uint depth);
170  bool IsRowMergable (uint rownum);
171  void MergeRow (uint rownum);
172  bool HasNotes (OpLine * line, uint movenum);
173  uint NoteCount (uint note);
174  uint NoteScore (uint note);
175  void PrintNotes (DString * dstr, uint format);
176 
177  public:
178  OpTable (const char * type, Game * g, PBook * ecoBook) {
179  Init (type, g, ecoBook);
180  }
181  OpTable (const char * type, Game * g) { Init (type, g, NULL); }
182  ~OpTable() { Clear(); delete[] Type; }
183  void Init (const char * type, Game * g, PBook * ecoBook);
184  void Clear ();
185  void ClearNotes ();
186  void SetFormat (const char * str);
187  void SetDecimalChar (char c) { DecimalChar = c; }
188 
189  uint GetTotalCount() { return FilterCount; }
190  uint GetTheoryCount() { return TheoryCount; }
191 
192  void SetExcludeMove (const char * s) {
193  strCopy (ExcludeMove, s);
194  strStrip (ExcludeMove, '-');
195  strStrip (ExcludeMove, '=');
196  }
197  const char* GetEco() const { return ECOstr_.c_str(); }
198  void SetNumRows (uint nrows) { TargetRows = nrows; }
199  void GuessNumRows (void);
200  void SetMaxTableLines (uint nlines) {
201  if (nlines <= OPTABLE_MAX_TABLE_LINES) {
202  MaxTableLines = nlines;
203  }
204  }
205  uint GetMaxTableLines (void) { return MaxTableLines; }
206  void SetMaxExtraMoves (uint nmoves) {
207  MaxNoteLength = (OPTABLE_COLUMNS + nmoves) * 2;
208  }
210  return (MaxNoteLength / 2) - OPTABLE_COLUMNS;
211  }
212  uint GetNumLines (void) { return NumLines; }
213  void SetMaxThemeMoveNumber (uint x) { MaxThemeMoveNumber = x; }
214  bool Add (OpLine * line);
215  uint PercentScore (void);
216  uint TheoryPercent (void);
217  uint TheoryScore (void);
218  uint PercentFreq (resultT result);
219  uint AvgLength (resultT result);
220  uint AvgElo (colorT color, uint *count, uint *oppScore, uint *oppPerf);
221  void BestGames (DString * dstr, uint count, const char * rtype);
222  void TopPlayers (DString * dstr, colorT c, uint count);
223  void TopEcoCodes (DString * dstr, uint count);
224  void PrintStemLine (DString * dstr, uint format, bool exclude);
225  void PrintStemLine (DString * dstr) { PrintStemLine (dstr, Format, false); }
226  void MakeRows (void);
227 #ifdef WINCE
228  void DumpLines (/*FILE **/Tcl_Channel fp);
229 #else
230  void DumpLines (FILE * fp);
231 #endif
232  void PrintTable (DString * dstr, const char *title, const char *comment);
233  void PrintLaTeX (DString * dstr,const char *title, const char *comment);
234  void PrintHTML (DString * str, const char *title, const char *comment);
235  void PrintText (DString * str, const char *title, const char *comment,
236  bool htext);
237  static uint FormatFromStr (const char * str);
238  uint AddMoveOrder (Game * g);
239  void PopularMoveOrders (DString * dstr, uint count);
240  void ThemeReport (DString * dstr, uint argc, const char ** argv);
241  void AddEndMaterial (matSigT ms, bool inFilter);
242  void EndMaterialReport (DString * dstr, const char * repGames,
243  const char * allGames);
244  uint * SelectGames (char type, uint number);
245 };
246 
247 #endif // SCID_OPTABLE_H
248 
249 //////////////////////////////////////////////////////////////////////
250 // optable.h
251 //////////////////////////////////////////////////////////////////////
const uint POSTHEME_CastSame
Definition: optable.h:42
const uint POSTHEME_BIQP
Definition: optable.h:48
uint GetNumLines(void)
Definition: optable.h:212
byte resultT
Definition: common.h:187
const uint POSTHEME_THRESHOLD
Definition: optable.h:52
void SetMaxThemeMoveNumber(uint x)
Definition: optable.h:213
const uint OPTABLE_MAX_ROWS
Definition: optable.h:26
uint AvgElo(colorT color, uint *count, uint *oppScore, uint *oppPerf)
Definition: optable.cpp:1925
const uint POSTHEME_OneBPair
Definition: optable.h:45
uint count
Definition: optable.h:70
const uint POSTHEME_CastOpp
Definition: optable.h:43
const uint NUM_RESULT_TYPES
Definition: common.h:186
uint GetMaxExtraMoves(void)
Definition: optable.h:209
Definition: optable.h:74
const uint OPTABLE_All
Definition: optable.h:65
uint max(int a, int b)
Definition: crosstab.cpp:237
uint dateT
Definition: common.h:147
const uint OPTABLE_COLUMNS
Definition: optable.h:24
const uint OPTABLE_Text
Definition: optable.h:34
const uint NUM_POSTHEMES
Definition: optable.h:41
const char * GetEco() const
Definition: optable.h:197
uint32_t matSigT
Definition: matsig.h:25
const uint OPTABLE_MAX_STARTLINE
Definition: optable.h:32
const uint OPTABLE_DEFAULT_ROWS
Definition: optable.h:27
const uint POSTHEME_OpenFyle
Definition: optable.h:51
OpLine()
Definition: optable.h:111
const uint POSTHEME_WIQP
Definition: optable.h:47
const uint EGTHEME_RM
Definition: optable.h:58
void SetMaxTableLines(uint nlines)
Definition: optable.h:200
const uint POSTHEME_Kstorm
Definition: optable.h:46
uint32_t idNumberT
Definition: common.h:152
const uint OPTABLE_MAX_LINES
Definition: optable.h:30
void SetMaxExtraMoves(uint nmoves)
Definition: optable.h:206
const uint OPTABLE_MIN_ROWS
Definition: optable.h:25
OpTable(const char *type, Game *g)
Definition: optable.h:181
const uint POSTHEME_BAdvPawn
Definition: optable.h:50
char * moves
Definition: optable.h:71
const uint OPTABLE_Line
Definition: optable.h:64
uint32_t uint
Definition: common.h:91
uint id
Definition: optable.h:69
const uint EGTHEME_P
Definition: optable.h:55
const uint EGTHEME_R
Definition: optable.h:57
~OpLine()
Definition: optable.h:115
UI_res_t Result(UI_handle_t ti, errorT res)
Definition: ui_tcltk.h:208
const uint OPTABLE_MAX_EXTRA_MOVES
Definition: optable.h:28
Definition: move.tcl:20
void SetExcludeMove(const char *s)
Definition: optable.h:192
uint GetTotalCount()
Definition: optable.h:189
const uint EGTHEME_QR
Definition: optable.h:61
const uint OPTABLE_LaTeX
Definition: optable.h:36
ushort eloT
Definition: common.h:164
ushort ecoT
Definition: common.h:165
void SetMoveOrderID(uint id)
Definition: optable.h:118
const uint OPTABLE_HTML
Definition: optable.h:35
Clear
Definition: game.tcl:8
const uint NUM_EGTHEMES
Definition: optable.h:54
OpTable(const char *type, Game *g, PBook *ecoBook)
Definition: optable.h:178
void SetDecimalChar(char c)
Definition: optable.h:187
colorpct ?col?
Definition: ptracker.tcl:77
Definition: game.h:167
void PrintStemLine(DString *dstr)
Definition: optable.h:225
Datename el op
Definition: validate.tcl:64
const uint OPTABLE_MAX_TABLE_LINES
Definition: optable.h:31
const uint POSTHEME_WAdvPawn
Definition: optable.h:49
void SetNumRows(uint nrows)
Definition: optable.h:198
const uint EGTHEME_QRM
Definition: optable.h:62
const uint EGTHEME_Q
Definition: optable.h:59
const uint OPLINE_MOVES
Definition: optable.h:29
void strCopy(char *target, const char *original)
Definition: misc.h:298
const uint EGTHEME_QM
Definition: optable.h:60
uint GetTheoryCount()
Definition: optable.h:190
byte colorT
Definition: common.h:104
char sanStringT[10]
Definition: common.h:129
const uint EGTHEME_M
Definition: optable.h:56
const uint POSTHEME_QueenSwap
Definition: optable.h:44
uint gamenumT
Definition: common.h:163
uint GetMaxTableLines(void)
Definition: optable.h:205
void strStrip(char *str, char ch)
Definition: misc.cpp:296
const uint OPTABLE_CText
Definition: optable.h:37
A PBook is a collection of chess positions, each with the corresponding ECO code, a mnemonic name...
Definition: pbook.h:37
Definition: indexentry.h:54
~OpTable()
Definition: optable.h:182
const char * GetMove(uint depth)
Definition: optable.h:124
const uint OPTABLE_Compact
Definition: optable.h:38
OpLine(Game *g, const IndexEntry *ie, gamenumT gnum, uint max, uint tm)
Definition: optable.h:112
Definition: htext.tcl:8