elo-ratings 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,249 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // move.cpp
4
+ //
5
+ // CMove class
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // june 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #include <cstring>
13
+ #include <iostream>
14
+
15
+ #include "move.h"
16
+ #include "square.h" // CSquare
17
+ #include "player.h" // CPlayer
18
+ #include "piece.h" // CPiece
19
+ #include "position.h" // CPosition
20
+
21
+ using namespace std;
22
+
23
+ CMove CMove::moveNull(0, 0, 0, 0);
24
+
25
+ ////////////////////////////////////////////////////////////////////////////
26
+ // Function to write a move string
27
+ // psz must point to a string with at least MaxMoveString characters
28
+ ////////////////////////////////////////////////////////////////////////////
29
+ #define ADD(c) do {*psz = (c); psz++;} while(0)
30
+ void CMove::MakeString(char *psz, int Notation) const
31
+ {
32
+ //
33
+ // Null move
34
+ //
35
+ if (!sqFrom && !sqTo)
36
+ {
37
+ ADD('n');
38
+ ADD('u');
39
+ ADD('l');
40
+ ADD('l');
41
+ ADD(0);
42
+ return;
43
+ }
44
+
45
+ static const char PieceLetter[] = "?KQRBNP";
46
+ static int Conversion[] = {1, 2, 3, 3, 4, 4, 5, 5, 6};
47
+
48
+ if (Notation == Basic || Notation == ChessBase)
49
+ {
50
+ ADD('a' + (sqFrom & 7));
51
+ ADD('1' + (sqFrom / 8));
52
+ ADD('a' + (sqTo & 7));
53
+ ADD('1' + (sqTo / 8));
54
+
55
+ if (ucType & Promotion)
56
+ {
57
+ if (Notation == Basic)
58
+ ADD('=');
59
+ ADD(PieceLetter[Conversion[ucType & 0x0f]]);
60
+ }
61
+
62
+ if (ucType == ep && Notation == Basic)
63
+ {
64
+ ADD('e');
65
+ ADD('p');
66
+ }
67
+
68
+ if ((ucType == OO || ucType == OOO) && Notation == Basic)
69
+ ADD('c');
70
+ }
71
+ else
72
+ {
73
+ //
74
+ // Short castle
75
+ //
76
+ if (ucType == OO)
77
+ {
78
+ ADD('O');
79
+ ADD('-');
80
+ ADD('O');
81
+ }
82
+
83
+ //
84
+ // Long castle
85
+ //
86
+ else if (ucType == OOO)
87
+ {
88
+ ADD('O');
89
+ ADD('-');
90
+ ADD('O');
91
+ ADD('-');
92
+ ADD('O');
93
+ }
94
+
95
+ //
96
+ // Other moves
97
+ //
98
+ else
99
+ {
100
+ //
101
+ // Origin square
102
+ //
103
+ if ((ucSAN & 0x07) == Pawn &&
104
+ (ucSAN & Capture) &&
105
+ Notation == StandardAlgebraic)
106
+ ADD('a' + (sqFrom & 7));
107
+ else if ((ucSAN & 0x07) != Pawn || Notation == LongAlgebraic)
108
+ {
109
+ if ((ucSAN & 0x07) != Pawn)
110
+ ADD(PieceLetter[ucSAN & 0x07]);
111
+ if ((ucSAN & File) || Notation == LongAlgebraic)
112
+ ADD('a' + (sqFrom & 7));
113
+ if ((ucSAN & Rank) || Notation == LongAlgebraic)
114
+ ADD('1' + (sqFrom / 8));
115
+ }
116
+
117
+ //
118
+ // Capture indication
119
+ //
120
+ if (ucSAN & Capture)
121
+ ADD('x');
122
+ else if (Notation == LongAlgebraic)
123
+ ADD('-');
124
+
125
+ //
126
+ // Destination square
127
+ //
128
+ ADD('a' + (sqTo & 7));
129
+ ADD('1' + (sqTo / 8));
130
+
131
+ //
132
+ // Promotions
133
+ //
134
+ if (ucType & Promotion)
135
+ {
136
+ ADD('=');
137
+ ADD(PieceLetter[Conversion[ucType & 0x0f]]);
138
+ }
139
+ }
140
+
141
+ //
142
+ // Check and mate
143
+ //
144
+ if (FullSANComputed())
145
+ {
146
+ if (ucSAN & Mate)
147
+ ADD('#');
148
+ else if (ucSAN & Check)
149
+ ADD('+');
150
+ }
151
+ }
152
+
153
+ //
154
+ // End of move string
155
+ //
156
+ ADD(0);
157
+ }
158
+ #undef ADD
159
+
160
+ ////////////////////////////////////////////////////////////////////////////
161
+ // Function to parse a move string
162
+ // Return value : 0 when sucessfully parsed, 1 otherwise
163
+ ////////////////////////////////////////////////////////////////////////////
164
+ int CMove::ParseString(const char *psz)
165
+ {
166
+ ucType = 0;
167
+ ucSAN = 0;
168
+
169
+ //
170
+ // null move
171
+ //
172
+ if (psz[0] == 'n' && psz[1] == 'u' && psz[2] == 'l' && psz[3] == 'l')
173
+ *this = moveNull;
174
+
175
+ //
176
+ // sqFrom and sqTo;
177
+ //
178
+ sqFrom = CSquare(psz);
179
+ sqTo = CSquare(psz + 2);
180
+ if (sqFrom > CSquare::h8 || sqTo > CSquare::h8)
181
+ return 1;
182
+
183
+ //
184
+ // Castling
185
+ //
186
+ if (psz[4] == 'c')
187
+ {
188
+ if (psz[2] == 'g')
189
+ ucType = CMove::OO;
190
+ else
191
+ ucType = CMove::OOO;
192
+ }
193
+
194
+ //
195
+ // Promotion
196
+ //
197
+ if (psz[4] == '=')
198
+ {
199
+ switch(psz[5])
200
+ {
201
+ case 'Q': ucType = Promotion | CPiece::Queen; break;
202
+ case 'R': ucType = Promotion | CPiece::Rook; break;
203
+ case 'B': ucType = Promotion | CPiece::Bishop; break;
204
+ case 'N': ucType = Promotion | CPiece::Knight; break;
205
+ }
206
+ }
207
+
208
+ //
209
+ // capture "en passant"
210
+ //
211
+ if (psz[4] == 'e')
212
+ ucType = ep;
213
+
214
+ return 0;
215
+ }
216
+
217
+ ////////////////////////////////////////////////////////////////////////////
218
+ // output operator
219
+ ////////////////////////////////////////////////////////////////////////////
220
+ ostream &operator<<(ostream &ostr, const CMove &move)
221
+ {
222
+ char szMove[CMove::MaxMoveString];
223
+ if (move.FullSANComputed())
224
+ move.MakeString(szMove, CMove::StandardAlgebraic);
225
+ else
226
+ move.MakeString(szMove, CMove::Basic);
227
+ return ostr << szMove;
228
+ }
229
+
230
+ ////////////////////////////////////////////////////////////////////////////
231
+ // Function to get the gnuchess notation of a move
232
+ ////////////////////////////////////////////////////////////////////////////
233
+ void CMove::GNUChessNotation(char *pszString) const
234
+ {
235
+ #define ADD(c) do {*pszString = c; pszString++;} while(0)
236
+ ADD('a' + (GetFrom() & 7));
237
+ ADD('1' + (GetFrom() / 8));
238
+ ADD('a' + (GetTo() & 7));
239
+ ADD('1' + (GetTo() / 8));
240
+
241
+ static const char PieceLetter[] = "?kqrbnp";
242
+ static int Conversion[] = {1, 2, 3, 3, 4, 4, 5, 5, 6};
243
+
244
+ if (GetType() & Promotion)
245
+ ADD(PieceLetter[Conversion[GetType() & 0x0f]]);
246
+
247
+ ADD(0);
248
+ #undef ADD
249
+ }
@@ -0,0 +1,139 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // move.h
4
+ //
5
+ // CMove class definition
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // june 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #ifndef MOVE_H
13
+ #define MOVE_H
14
+
15
+ #include <iostream>
16
+
17
+ class CPosition;
18
+ class CMove;
19
+
20
+ std::ostream &operator<<(std::ostream &ostr, const CMove &move);
21
+
22
+ class CMove // move
23
+ {
24
+ private: //////////////////////////////////////////////////////////////////
25
+ unsigned char sqFrom;
26
+ unsigned char sqTo;
27
+ unsigned char ucType;
28
+ unsigned char ucSAN;
29
+
30
+ public: ///////////////////////////////////////////////////////////////////
31
+ //
32
+ // Move type flags
33
+ //
34
+ enum
35
+ {
36
+ Normal = 0x00,
37
+ OO = 0x80,
38
+ OOO = 0x40,
39
+ ep = 0x20,
40
+ Promotion = 0x10
41
+ };
42
+
43
+ //
44
+ // SAN flags
45
+ //
46
+ enum
47
+ {
48
+ King = 0x01,
49
+ Queen = 0x02,
50
+ Rook = 0x03,
51
+ Bishop = 0x04,
52
+ Knight = 0x05,
53
+ Pawn = 0x06,
54
+ File = 0x08,
55
+ Rank = 0x10,
56
+ Capture = 0x20,
57
+ Check = 0x40,
58
+ Mate = 0x80,
59
+ Partial = Mate | File | Rank
60
+
61
+ // Mate without Check is impossible in a fully computed set of SAN flags
62
+ // This is the reason why mate without check is used as an indicator that
63
+ // the full SAN flags have not been computed
64
+ // (see 'int FullSANComputed() const')
65
+
66
+ };
67
+
68
+ //
69
+ // Notations
70
+ //
71
+ enum
72
+ {
73
+ StandardAlgebraic, // Only when FullSANComputed()
74
+ LongAlgebraic, // Partial SAN flags required
75
+ Basic, // Does not use ucSAN. No ppos required for parsing
76
+ ChessBase
77
+ };
78
+
79
+ //
80
+ // Maximum characters of move strings (counting '\0' at the end)
81
+ //
82
+ enum {MaxMoveString = 10};
83
+
84
+ //
85
+ // Constructors
86
+ //
87
+ CMove() {}
88
+ CMove(const char *psz) {ParseString(psz);}
89
+
90
+ CMove(unsigned char sqFromNew,
91
+ unsigned char sqToNew,
92
+ unsigned char ucTypeNew = Normal,
93
+ unsigned char ucSANNew = 0)
94
+ {
95
+ Set(sqFromNew, sqToNew, ucTypeNew, ucSANNew);
96
+ }
97
+
98
+ //
99
+ // Basic sets and gets
100
+ //
101
+ void SetFrom(unsigned char sq) {sqFrom = sq;}
102
+ void SetTo(unsigned char sq) {sqTo = sq;}
103
+ void SetType(unsigned char uc) {ucType = uc;}
104
+ void SetSAN(unsigned char uc) {ucSAN = uc;}
105
+ void AddSAN(unsigned char uc) {ucSAN |= uc;}
106
+ void Set(unsigned char sqFromNew,
107
+ unsigned char sqToNew,
108
+ unsigned char ucTypeNew = Normal,
109
+ unsigned char ucSANNew = 0)
110
+ {
111
+ SetFrom(sqFromNew);
112
+ SetTo(sqToNew);
113
+ SetType(ucTypeNew);
114
+ SetSAN(ucSANNew);
115
+ }
116
+
117
+ unsigned char GetFrom() const {return sqFrom;}
118
+ unsigned char GetTo() const {return sqTo;}
119
+ unsigned char GetType() const {return ucType;}
120
+ unsigned char GetSAN() const {return ucSAN;}
121
+
122
+ //
123
+ // Other functions
124
+ //
125
+ int FullSANComputed() const
126
+ {
127
+ return ucSAN && (!(ucSAN & Mate) || (ucSAN & Check));
128
+ }
129
+ int ParseString(const char *psz);
130
+ void MakeString(char *psz, int Notation = StandardAlgebraic) const;
131
+ void GNUChessNotation(char *pszString) const;
132
+
133
+ //
134
+ // Null move
135
+ //
136
+ static CMove moveNull;
137
+ };
138
+
139
+ #endif
@@ -0,0 +1,62 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // pgn.h
4
+ //
5
+ // PGN input/output functions
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // august 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #ifndef PGN_H
13
+ #define PGN_H
14
+
15
+ #include <iostream>
16
+
17
+ class CGame;
18
+ class CJustifiedText;
19
+ class CConstGameCursor;
20
+ class CPGNLex;
21
+ class CSTR;
22
+
23
+ class CPGN
24
+ {
25
+ public : //////////////////////////////////////////////////////////////////
26
+ static const char * const tszResult[];
27
+
28
+ enum
29
+ {
30
+ NoMoveNumber = 1,
31
+ NoComment = 2,
32
+ NoNAG = 4,
33
+ NoRAV = 8
34
+ };
35
+
36
+ static const char * const tszTag[];
37
+
38
+ enum
39
+ {
40
+ TAG_Event,
41
+ TAG_Site,
42
+ TAG_Date,
43
+ TAG_Round,
44
+ TAG_White,
45
+ TAG_Black,
46
+ TAG_Result,
47
+ TAG_SetUp,
48
+ TAG_FEN,
49
+ TAGs
50
+ };
51
+
52
+ static void WriteMoveText(CJustifiedText &jt,
53
+ CConstGameCursor &cgc,
54
+ int Flags = 0);
55
+ static void Write(const CGame &game, std::ostream &ostr, int Flags = 0);
56
+
57
+ static int Read(CGame &game, CPGNLex &pgnlex);
58
+ static int ReadSTR(CSTR &str, CPGNLex &pgnlex);
59
+ static void WriteTag(int Tag, const char *psz, std::ostream &ostr);
60
+ };
61
+
62
+ #endif