elo-ratings 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.document +5 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +22 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +23 -0
  6. data/Rakefile +54 -0
  7. data/VERSION +1 -0
  8. data/elo-ratings.gemspec +148 -0
  9. data/ext/bayeselo/.gitignore +4 -0
  10. data/ext/bayeselo/CBradleyTerry.cpp +670 -0
  11. data/ext/bayeselo/CBradleyTerry.h +137 -0
  12. data/ext/bayeselo/CCDistribution.cpp +135 -0
  13. data/ext/bayeselo/CCDistribution.h +44 -0
  14. data/ext/bayeselo/CCDistributionCUI.cpp +104 -0
  15. data/ext/bayeselo/CCDistributionCUI.h +38 -0
  16. data/ext/bayeselo/CCondensedResults.cpp +253 -0
  17. data/ext/bayeselo/CCondensedResults.h +64 -0
  18. data/ext/bayeselo/CDiscretization.h +40 -0
  19. data/ext/bayeselo/CDistribution.cpp +123 -0
  20. data/ext/bayeselo/CDistribution.h +58 -0
  21. data/ext/bayeselo/CDistributionCollection.cpp +34 -0
  22. data/ext/bayeselo/CDistributionCollection.h +29 -0
  23. data/ext/bayeselo/CEloRatingCUI.cpp +1046 -0
  24. data/ext/bayeselo/CEloRatingCUI.h +67 -0
  25. data/ext/bayeselo/CIndirectCompare.h +28 -0
  26. data/ext/bayeselo/CJointBayesian.cpp +111 -0
  27. data/ext/bayeselo/CJointBayesian.h +38 -0
  28. data/ext/bayeselo/CLUDecomposition.cpp +154 -0
  29. data/ext/bayeselo/CLUDecomposition.h +36 -0
  30. data/ext/bayeselo/CMatrix.cpp +48 -0
  31. data/ext/bayeselo/CMatrix.h +35 -0
  32. data/ext/bayeselo/CMatrixIO.cpp +27 -0
  33. data/ext/bayeselo/CMatrixIO.h +17 -0
  34. data/ext/bayeselo/CPredictionCUI.cpp +393 -0
  35. data/ext/bayeselo/CPredictionCUI.h +50 -0
  36. data/ext/bayeselo/CResultSet.cpp +245 -0
  37. data/ext/bayeselo/CResultSet.h +50 -0
  38. data/ext/bayeselo/CResultSetCUI.cpp +355 -0
  39. data/ext/bayeselo/CResultSetCUI.h +44 -0
  40. data/ext/bayeselo/CTimeIO.cpp +58 -0
  41. data/ext/bayeselo/CTimeIO.h +19 -0
  42. data/ext/bayeselo/CVector.cpp +110 -0
  43. data/ext/bayeselo/CVector.h +42 -0
  44. data/ext/bayeselo/EloDataFromFile.cpp +120 -0
  45. data/ext/bayeselo/EloDataFromFile.h +21 -0
  46. data/ext/bayeselo/README +8 -0
  47. data/ext/bayeselo/ReadLineToString.cpp +32 -0
  48. data/ext/bayeselo/ReadLineToString.h +18 -0
  49. data/ext/bayeselo/chtime.cpp +56 -0
  50. data/ext/bayeselo/chtime.h +61 -0
  51. data/ext/bayeselo/chtimer.h +27 -0
  52. data/ext/bayeselo/clktimer.cpp +178 -0
  53. data/ext/bayeselo/clktimer.h +29 -0
  54. data/ext/bayeselo/consolui.cpp +538 -0
  55. data/ext/bayeselo/consolui.h +154 -0
  56. data/ext/bayeselo/const.cpp +79 -0
  57. data/ext/bayeselo/const.h +42 -0
  58. data/ext/bayeselo/date.cpp +96 -0
  59. data/ext/bayeselo/date.h +44 -0
  60. data/ext/bayeselo/debug.h +58 -0
  61. data/ext/bayeselo/elomain.cpp +26 -0
  62. data/ext/bayeselo/extconf.rb +6 -0
  63. data/ext/bayeselo/list.h +367 -0
  64. data/ext/bayeselo/listi.h +125 -0
  65. data/ext/bayeselo/move.cpp +249 -0
  66. data/ext/bayeselo/move.h +139 -0
  67. data/ext/bayeselo/pgn.h +62 -0
  68. data/ext/bayeselo/pgnlex.cpp +432 -0
  69. data/ext/bayeselo/pgnlex.h +105 -0
  70. data/ext/bayeselo/pgnstr.cpp +126 -0
  71. data/ext/bayeselo/piece.h +44 -0
  72. data/ext/bayeselo/player.h +31 -0
  73. data/ext/bayeselo/position.h +89 -0
  74. data/ext/bayeselo/random.cpp +114 -0
  75. data/ext/bayeselo/random.h +63 -0
  76. data/ext/bayeselo/rb_bayeselo.cpp +76 -0
  77. data/ext/bayeselo/readstr.cpp +51 -0
  78. data/ext/bayeselo/readstr.h +19 -0
  79. data/ext/bayeselo/square.h +61 -0
  80. data/ext/bayeselo/str.cpp +81 -0
  81. data/ext/bayeselo/str.h +71 -0
  82. data/ext/bayeselo/version.cpp +30 -0
  83. data/ext/bayeselo/version.h +28 -0
  84. data/ext/bayeselo/version_number.h +1 -0
  85. data/lib/bayeselo.rb +6 -0
  86. data/lib/bayeselo/bayeselo.rb +11 -0
  87. data/lib/bayeselo/c_bayeselo.rb +7 -0
  88. data/test/bayeselo/test_bayeselo.rb +33 -0
  89. data/test/bayeselo/test_c_bayeselo.rb +84 -0
  90. data/test/helper.rb +18 -0
  91. metadata +226 -0
@@ -0,0 +1,26 @@
1
+ /////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // R�mi Coulom
4
+ //
5
+ // December, 2004
6
+ //
7
+ /////////////////////////////////////////////////////////////////////////////
8
+ #include "version.h"
9
+ #include "CResultSet.h"
10
+ #include "CResultSetCUI.h"
11
+
12
+ #include <iostream>
13
+
14
+ /////////////////////////////////////////////////////////////////////////////
15
+ // main function
16
+ /////////////////////////////////////////////////////////////////////////////
17
+ int main()
18
+ {
19
+ std::cout << CVersion::GetCopyright();
20
+ CResultSet rs;
21
+ std::vector<std::string> vecName;
22
+ CResultSetCUI rscui(rs, vecName);
23
+ rscui.MainLoop(std::cin, std::cout);
24
+
25
+ return 0;
26
+ }
@@ -0,0 +1,6 @@
1
+ require 'mkmf-rice'
2
+
3
+ extension_name = 'bayeselo'
4
+ have_library("stdc++")
5
+ dir_config(extension_name)
6
+ create_makefile(extension_name)
@@ -0,0 +1,367 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // list.h
4
+ //
5
+ // Remi Coulom
6
+ //
7
+ // april 1996
8
+ //
9
+ // list template
10
+ // efficient for small types (int, pointers, ...)
11
+ //
12
+ ////////////////////////////////////////////////////////////////////////////
13
+ #ifndef LIST_H
14
+ #define LIST_H
15
+
16
+ #include "debug.h" // Debug macros (ASSERT, INLINE)
17
+
18
+ #ifdef LISTINLINE
19
+ #define BIGINLINE INLINE
20
+ #else
21
+ #define BIGINLINE
22
+ #endif
23
+
24
+ template<class T> class CListIterator;
25
+ template<class T> class CConstListIterator;
26
+ template<class T> class CListSort;
27
+
28
+ ////////////////////////////////////////////////////////////////////////////
29
+ // CListCell class definition
30
+ ////////////////////////////////////////////////////////////////////////////
31
+ template<class T>
32
+ class CListCell // cell
33
+ {
34
+ private:
35
+ T tValue;
36
+ CListCell<T> *pcellNext;
37
+
38
+ public:
39
+ T& Value() {return tValue;};
40
+ const T& Value() const {return tValue;};
41
+
42
+ CListCell<T> *Next() {return pcellNext;};
43
+ const CListCell<T> *Next() const {return pcellNext;};
44
+
45
+ void Link(CListCell<T> *pcell) {pcellNext = pcell;};
46
+ };
47
+
48
+ ////////////////////////////////////////////////////////////////////////////
49
+ // CCellBloc class definition
50
+ ////////////////////////////////////////////////////////////////////////////
51
+ template<class T>
52
+ class CCellBloc // bloc
53
+ {
54
+ private:
55
+ CListCell<T> *ptcell; // Array of cells
56
+ CCellBloc<T> *pblocNext; // Next bloc
57
+
58
+ public:
59
+ CCellBloc(int Size, CCellBloc<T> *pbloc);
60
+ ~CCellBloc();
61
+
62
+ const CListCell<T> *FirstCell() const {return ptcell;};
63
+ CListCell<T> *FirstCell() {return ptcell;};
64
+
65
+ const CCellBloc<T> *Next() const {return pblocNext;};
66
+ CCellBloc<T> *Next() {return pblocNext;};
67
+ };
68
+
69
+ ////////////////////////////////////////////////////////////////////////////
70
+ // CList class definition
71
+ ////////////////////////////////////////////////////////////////////////////
72
+ template<class T>
73
+ class CList //lt
74
+ {
75
+ friend class CListIterator<T>;
76
+ friend class CConstListIterator<T>;
77
+ friend class CListSort<T>;
78
+
79
+ private: //////////////////////////////////////////////////////////////////
80
+ int BlocSize;
81
+ CListCell<T> *pcellFirst;
82
+ CListCell<T> *pcellFree;
83
+ CCellBloc<T> *pblocFirst;
84
+
85
+ void FreeCell(CListCell<T> *pcell);
86
+ CListCell<T> *AllocateCell();
87
+
88
+ public: ///////////////////////////////////////////////////////////////////
89
+ CList();
90
+ ~CList();
91
+ CList(const CList<T> &lt);
92
+ CList<T> &operator=(const CList<T> &lt);
93
+
94
+ void Reset();
95
+ void Append(const CList<T> &lt);
96
+ void Add();
97
+ void Remove();
98
+ void SetBlocSize(int Size);
99
+ T& Head();
100
+
101
+ const T& Head() const;
102
+ int IsEmpty() const;
103
+ int GetSize() const;
104
+ };
105
+
106
+ ////////////////////////////////////////////////////////////////////////////
107
+ // Constructor
108
+ ////////////////////////////////////////////////////////////////////////////
109
+ template<class T>
110
+ CCellBloc<T>::CCellBloc(int Size, CCellBloc<T> *pbloc)
111
+ {
112
+ ASSERT(Size > 0);
113
+ pblocNext = pbloc;
114
+ ptcell = new CListCell<T>[Size];
115
+
116
+ {
117
+ for (int i = Size - 1; --i >= 0;)
118
+ ptcell[i].Link(&ptcell[i + 1]);
119
+ }
120
+
121
+ ptcell[Size - 1].Link(0);
122
+ }
123
+
124
+ ////////////////////////////////////////////////////////////////////////////
125
+ // Destructor
126
+ ////////////////////////////////////////////////////////////////////////////
127
+ template<class T>
128
+ inline
129
+ CCellBloc<T>::~CCellBloc()
130
+ {
131
+ delete[] ptcell;
132
+ }
133
+
134
+ ////////////////////////////////////////////////////////////////////////////
135
+ // Constructor for CList<T>
136
+ ////////////////////////////////////////////////////////////////////////////
137
+ template<class T>
138
+ BIGINLINE
139
+ CList<T>::CList()
140
+ {
141
+ pcellFirst = 0;
142
+ pcellFree = 0;
143
+ BlocSize = 1;
144
+ pblocFirst = 0;
145
+ }
146
+
147
+ ////////////////////////////////////////////////////////////////////////////
148
+ // Copy constructor for CList<T>
149
+ ////////////////////////////////////////////////////////////////////////////
150
+ template<class T>
151
+ CList<T>::CList(const CList<T> &lt)
152
+ {
153
+ BlocSize = lt.BlocSize;
154
+
155
+ pcellFirst = 0;
156
+ pcellFree = 0;
157
+ pblocFirst = 0;
158
+
159
+ Append(lt);
160
+ }
161
+
162
+ ////////////////////////////////////////////////////////////////////////////
163
+ // Assignment operator
164
+ ////////////////////////////////////////////////////////////////////////////
165
+ template<class T>
166
+ CList<T> &CList<T>::operator=(const CList<T> &lt)
167
+ {
168
+ if (&lt != this)
169
+ {
170
+ Reset();
171
+ BlocSize = lt.BlocSize;
172
+ Append(lt);
173
+ }
174
+ return *this;
175
+ }
176
+
177
+ ////////////////////////////////////////////////////////////////////////////
178
+ // Destructor : deletes all the allocated memory
179
+ ////////////////////////////////////////////////////////////////////////////
180
+ template<class T>
181
+ CList<T>::~CList()
182
+ {
183
+ Reset();
184
+ }
185
+
186
+ ////////////////////////////////////////////////////////////////////////////
187
+ // Function called in destructor and assignment operator to free memory
188
+ ////////////////////////////////////////////////////////////////////////////
189
+ template<class T>
190
+ void CList<T>::Reset()
191
+ {
192
+ CCellBloc<T> *pblocCurrent = pblocFirst;
193
+
194
+ while (pblocCurrent)
195
+ {
196
+ CCellBloc<T> *pblocNext = pblocCurrent->Next();
197
+ delete pblocCurrent;
198
+ pblocCurrent = pblocNext;
199
+ }
200
+
201
+ pcellFirst = 0;
202
+ pcellFree = 0;
203
+ pblocFirst = 0;
204
+ }
205
+
206
+ ////////////////////////////////////////////////////////////////////////////
207
+ // Function to append a list at the end of a list
208
+ ////////////////////////////////////////////////////////////////////////////
209
+ template<class T>
210
+ void CList<T>::Append(const CList<T> &lt)
211
+ {
212
+ if (lt.pcellFirst)
213
+ {
214
+ CListCell<T> *pcellCopy = AllocateCell();
215
+
216
+ //
217
+ // Allocation of a copy of the appended list
218
+ //
219
+ {
220
+ const CListCell<T> *pcellFrom = lt.pcellFirst;
221
+ CListCell<T> *pcellTo = pcellCopy;
222
+
223
+ do
224
+ {
225
+ pcellTo->Value() = pcellFrom->Value();
226
+ pcellFrom = pcellFrom->Next();
227
+ if (pcellFrom)
228
+ {
229
+ pcellTo->Link(AllocateCell());
230
+ pcellTo = pcellTo->Next();
231
+ }
232
+ else
233
+ pcellTo->Link(0);
234
+ }
235
+ while(pcellFrom);
236
+ }
237
+
238
+ //
239
+ // Search of the end of this list and addition of the copy
240
+ //
241
+ {
242
+ CListCell<T> *pcell = pcellFirst;
243
+
244
+ if (pcell)
245
+ {
246
+ while (pcell->Next())
247
+ pcell = pcell->Next();
248
+ pcell->Link(pcellCopy);
249
+ }
250
+ else
251
+ pcellFirst = pcellCopy;
252
+ }
253
+ }
254
+ }
255
+
256
+ ////////////////////////////////////////////////////////////////////////////
257
+ // Adds a new cell at the beginning of the list
258
+ ////////////////////////////////////////////////////////////////////////////
259
+ template<class T>
260
+ BIGINLINE
261
+ void CList<T>::Add()
262
+ {
263
+ CListCell<T> *pcellNew = AllocateCell();
264
+ ASSERT(!!pcellNew);
265
+ pcellNew->Link(pcellFirst);
266
+ pcellFirst = pcellNew;
267
+ }
268
+
269
+ ////////////////////////////////////////////////////////////////////////////
270
+ // Deletes the head of the list
271
+ ////////////////////////////////////////////////////////////////////////////
272
+ template<class T>
273
+ BIGINLINE
274
+ void CList<T>::Remove()
275
+ {
276
+ ASSERT(!IsEmpty());
277
+ CListCell<T> *pcell = pcellFirst;
278
+ pcellFirst = pcellFirst->Next();
279
+ FreeCell(pcell);
280
+ }
281
+
282
+ ////////////////////////////////////////////////////////////////////////////
283
+ // Function to set the bloc size
284
+ ////////////////////////////////////////////////////////////////////////////
285
+ template<class T>
286
+ void CList<T>::SetBlocSize(int Size)
287
+ {
288
+ ASSERT(Size > 0);
289
+ BlocSize = Size;
290
+ }
291
+
292
+ ////////////////////////////////////////////////////////////////////////////
293
+ // Access to data at the head of the list
294
+ ////////////////////////////////////////////////////////////////////////////
295
+ template<class T> // const version
296
+ INLINE
297
+ const T& CList<T>::Head() const
298
+ {
299
+ ASSERT(!IsEmpty());
300
+ return pcellFirst->Value();
301
+ }
302
+ template<class T> // non-const version
303
+ INLINE
304
+ T& CList<T>::Head()
305
+ {
306
+ ASSERT(!IsEmpty());
307
+ return pcellFirst->Value();
308
+ }
309
+
310
+ ////////////////////////////////////////////////////////////////////////////
311
+ // Tests whether the list is empty
312
+ ////////////////////////////////////////////////////////////////////////////
313
+ template<class T>
314
+ inline
315
+ int CList<T>::IsEmpty() const
316
+ {
317
+ return !pcellFirst;
318
+ }
319
+
320
+ ////////////////////////////////////////////////////////////////////////////
321
+ // Frees one cell
322
+ ////////////////////////////////////////////////////////////////////////////
323
+ template<class T>
324
+ inline
325
+ void CList<T>::FreeCell(CListCell<T> *pcell)
326
+ {
327
+ pcell->Link(pcellFree);
328
+ pcellFree = pcell;
329
+ }
330
+
331
+ ////////////////////////////////////////////////////////////////////////////
332
+ // Count of list elements
333
+ ////////////////////////////////////////////////////////////////////////////
334
+ template<class T>
335
+ int CList<T>::GetSize() const
336
+ {
337
+ CListCell<T> *pcell = pcellFirst;
338
+ int s = 0;
339
+
340
+ while (pcell)
341
+ {
342
+ s++;
343
+ pcell = pcell->Next();
344
+ }
345
+
346
+ return s;
347
+ }
348
+
349
+ ////////////////////////////////////////////////////////////////////////////
350
+ // Allocates a new cell
351
+ ////////////////////////////////////////////////////////////////////////////
352
+ template<class T>
353
+ BIGINLINE
354
+ CListCell<T> *CList<T>::AllocateCell()
355
+ {
356
+ if (!pcellFree)
357
+ {
358
+ pblocFirst = new CCellBloc<T>(BlocSize, pblocFirst);
359
+ pcellFree = pblocFirst->FirstCell();
360
+ }
361
+
362
+ CListCell<T> *pcell = pcellFree;
363
+ pcellFree = pcellFree->Next();
364
+ return pcell;
365
+ }
366
+
367
+ #endif
@@ -0,0 +1,125 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // listi.h
4
+ //
5
+ // CListIterator<class T> template definition
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // june 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #ifndef LISTI_H
13
+ #define LISTI_H
14
+
15
+ #include "list.h" // CList template
16
+
17
+ ////////////////////////////////////////////////////////////////////////////
18
+ // CListIterator class definition
19
+ ////////////////////////////////////////////////////////////////////////////
20
+ template<class T>
21
+ class CListIterator // listi
22
+ {
23
+ private: //////////////////////////////////////////////////////////////////
24
+ CList<T> *plt;
25
+ CListCell<T> *pcellCurrent;
26
+ CListCell<T> *pcellPrevious;
27
+
28
+ public: ///////////////////////////////////////////////////////////////////
29
+ CListIterator(CList<T>& ltInit);
30
+
31
+ void Increment();
32
+ void Remove();
33
+ void Insert();
34
+ void Reset();
35
+
36
+ T& Value();
37
+ int IsFirst() const {return !pcellPrevious;}
38
+ int IsAtTheEnd() const {return !pcellCurrent;}
39
+ };
40
+
41
+ ////////////////////////////////////////////////////////////////////////////
42
+ // Constructor
43
+ ////////////////////////////////////////////////////////////////////////////
44
+ template<class T>
45
+ CListIterator<T>::CListIterator(CList<T>& ltInit)
46
+ {
47
+ plt = &ltInit;
48
+ pcellPrevious = 0;
49
+ pcellCurrent = ltInit.pcellFirst;
50
+ }
51
+
52
+ ////////////////////////////////////////////////////////////////////////////
53
+ // Resets an iterator to the beginning of its list
54
+ ////////////////////////////////////////////////////////////////////////////
55
+ template<class T>
56
+ void CListIterator<T>::Reset()
57
+ {
58
+ pcellPrevious = 0;
59
+ pcellCurrent = plt->pcellFirst;
60
+ }
61
+
62
+ ////////////////////////////////////////////////////////////////////////////
63
+ // Moves to the next position in a list
64
+ ////////////////////////////////////////////////////////////////////////////
65
+ template<class T>
66
+ INLINE
67
+ void CListIterator<T>::Increment()
68
+ {
69
+ ASSERT(!IsAtTheEnd());
70
+ pcellPrevious = pcellCurrent;
71
+ pcellCurrent = pcellCurrent->Next();
72
+ }
73
+
74
+ ////////////////////////////////////////////////////////////////////////////
75
+ // Insert one cell at the current position
76
+ ////////////////////////////////////////////////////////////////////////////
77
+ template<class T>
78
+ void CListIterator<T>::Insert()
79
+ {
80
+ if (!pcellPrevious)
81
+ {
82
+ plt->Add();
83
+ pcellCurrent = plt->pcellFirst;
84
+ }
85
+ else
86
+ {
87
+ CListCell<T> *pcellNew = plt->AllocateCell();
88
+ pcellNew->Link(pcellCurrent);
89
+ pcellPrevious->Link(pcellNew);
90
+ pcellCurrent = pcellNew;
91
+ }
92
+ }
93
+
94
+ ////////////////////////////////////////////////////////////////////////////
95
+ // Removes one cell from the list
96
+ ////////////////////////////////////////////////////////////////////////////
97
+ template<class T>
98
+ void CListIterator<T>::Remove()
99
+ {
100
+ ASSERT(!IsAtTheEnd());
101
+
102
+ {
103
+ CListCell<T> *pcell = pcellCurrent;
104
+ pcellCurrent = pcellCurrent->Next();
105
+ plt->FreeCell(pcell);
106
+ }
107
+
108
+ if (pcellPrevious)
109
+ pcellPrevious->Link(pcellCurrent);
110
+ else
111
+ plt->pcellFirst = pcellCurrent;
112
+ }
113
+
114
+ ////////////////////////////////////////////////////////////////////////////
115
+ // Reads the value contained by the current cell
116
+ ////////////////////////////////////////////////////////////////////////////
117
+ template<class T>
118
+ INLINE
119
+ T& CListIterator<T>::Value()
120
+ {
121
+ ASSERT(!IsAtTheEnd());
122
+ return pcellCurrent->Value();
123
+ }
124
+
125
+ #endif