all-up-in-your-elo 0.0.2

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 +42 -0
  6. data/Rakefile +54 -0
  7. data/VERSION +1 -0
  8. data/all-up-in-your-elo.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/eloratings.cpp +76 -0
  63. data/ext/bayeselo/extconf.rb +6 -0
  64. data/ext/bayeselo/list.h +367 -0
  65. data/ext/bayeselo/listi.h +125 -0
  66. data/ext/bayeselo/move.cpp +249 -0
  67. data/ext/bayeselo/move.h +139 -0
  68. data/ext/bayeselo/pgn.h +62 -0
  69. data/ext/bayeselo/pgnlex.cpp +432 -0
  70. data/ext/bayeselo/pgnlex.h +105 -0
  71. data/ext/bayeselo/pgnstr.cpp +126 -0
  72. data/ext/bayeselo/piece.h +44 -0
  73. data/ext/bayeselo/player.h +31 -0
  74. data/ext/bayeselo/position.h +89 -0
  75. data/ext/bayeselo/random.cpp +114 -0
  76. data/ext/bayeselo/random.h +63 -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/elo_ratings.rb +9 -0
  86. data/lib/elo_ratings/c_bayeselo.rb +5 -0
  87. data/lib/elo_ratings/results.rb +41 -0
  88. data/test/elo_ratings/test_c_bayeselo.rb +84 -0
  89. data/test/elo_ratings/test_results.rb +41 -0
  90. data/test/helper.rb +19 -0
  91. metadata +233 -0
@@ -0,0 +1,154 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // consolui.h
4
+ //
5
+ // CConsoleUI class declaration
6
+ //
7
+ // This class is an abstract class, used to define console user interfaces.
8
+ // It is typically used by adding a pointer to a class, and overriding the
9
+ // ProcessCommand member function to process commands on this class.
10
+ // See classes that inherit from CConsoleUI to find examples demonstrating
11
+ // how to do so.
12
+ //
13
+ // Remi Coulom
14
+ //
15
+ // june 1996
16
+ //
17
+ ////////////////////////////////////////////////////////////////////////////
18
+ #ifndef CONSOLUI_H
19
+ #define CONSOLUI_H
20
+
21
+ #include <iosfwd>
22
+
23
+ #include "list.h" // CList<>
24
+
25
+ class CConsoleUI //cui
26
+ {
27
+ private: //////////////////////////////////////////////////////////////////
28
+ //
29
+ // private data
30
+ //
31
+ static const int BufferSize;
32
+ static const char * const tszCommands[];
33
+
34
+ CList<CConsoleUI *> lpcuiChildren;
35
+ CConsoleUI *pcuiParent;
36
+ int fPrompt;
37
+ const int openmode;
38
+
39
+ //
40
+ // private functions
41
+ //
42
+ void Parse(char *pszCommand,
43
+ const char *&pszCommand2,
44
+ const char *&pszParameters,
45
+ const char *&pszInput,
46
+ const char *&pszOutput) const;
47
+
48
+ void OpenChild(int Parameter, std::istream &in, std::ostream &out);
49
+
50
+ //
51
+ // Copy constructor and assignment operator do not work
52
+ //
53
+ // CConsoleUI(const CConsoleUI &cui): openmode(0)
54
+ // {const CConsoleUI *pcui = &cui; pcui = pcui;}
55
+ // CConsoleUI &operator=(const CConsoleUI &cui): openmode(0)
56
+ // {const CConsoleUI *pcui = &cui; pcui = pcui; return *this;}
57
+
58
+ protected: ////////////////////////////////////////////////////////////////
59
+ //
60
+ // Prompt functions
61
+ //
62
+ virtual void PrintLocalPrompt(std::ostream &out) = 0;
63
+ void PrintPrompt(std::ostream &out);
64
+
65
+ //
66
+ // Useful fonctions to help processing commands
67
+ // ??? (should not be a member function)
68
+ //
69
+ const char *SetFlag(int &f, const char *psz);
70
+ int ArrayLookup(const char * const psz,
71
+ const char * const * const ppsz);
72
+
73
+ //
74
+ // This function is called repeatedly by EnterParseAndProcess
75
+ //
76
+ virtual int ProcessCommand(const char *pszCommand,
77
+ const char *pszParameters,
78
+ std::istream &in,
79
+ std::ostream &out);
80
+
81
+ //
82
+ // Opening modes
83
+ //
84
+ enum // openmode
85
+ {
86
+ OpenModal,
87
+ OpenModeless,
88
+ OpenPermanent
89
+ };
90
+
91
+ //
92
+ // Function to print an error message
93
+ //
94
+ virtual void PrintErrorMessage(std::ostream &out, const char *pszCommand);
95
+
96
+ //
97
+ // Function used to add a CConsoleCUI to the list of modeless children
98
+ // These user interfaces are deleted when they are closed (they must have
99
+ // been allocated dynamically by new ...)
100
+ //
101
+ void AddChild(CConsoleUI *pcui, std::istream &in, std::ostream &out);
102
+
103
+ //
104
+ // Utility function to get[set] variables
105
+ //
106
+ template<class T>
107
+ static void GetSet(T &x, const char *psz, std::ostream &out);
108
+
109
+ public: ///////////////////////////////////////////////////////////////////
110
+ //
111
+ // Constructor
112
+ //
113
+ CConsoleUI(CConsoleUI *pcui = 0, int openmodeInit = OpenModal);
114
+
115
+ //
116
+ // ProcessCommand return values
117
+ //
118
+ enum
119
+ {
120
+ PC_Continue, // The command loop should go on
121
+ PC_Close, // The command loop should stop and return PC_Close
122
+ PC_Parent // The command loop should stop and return PC_Parent
123
+ };
124
+
125
+ //
126
+ // Functions to set/get the prompt flag
127
+ //
128
+ void SetFPrompt(int i) {fPrompt = !!i;};
129
+ int GetFPrompt() const {return fPrompt;};
130
+
131
+ //
132
+ // set parent
133
+ //
134
+ void SetParent(CConsoleUI *pcui);
135
+
136
+ //
137
+ // Function to process a single command
138
+ //
139
+ int EnterParseAndProcess(std::istream &in,
140
+ std::ostream &out,
141
+ std::ostream *pofsLog = 0);
142
+
143
+ //
144
+ // Main command loop of calls to EnterParseAndProcess
145
+ //
146
+ int MainLoop(std::istream &in, std::ostream &out);
147
+
148
+ //
149
+ // This class has virtual functions, so we provide a virtual destructor
150
+ //
151
+ virtual ~CConsoleUI();
152
+ };
153
+
154
+ #endif
@@ -0,0 +1,79 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // const.cpp
4
+ //
5
+ // CConst class
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // July 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #include "const.h"
13
+ #include "square.h" // CSquare class
14
+
15
+ //
16
+ // Table indicating distances to the edge of the board
17
+ //
18
+ const int CConst::tcEdge[64] =
19
+ {
20
+ Left|Down ,Left2|Down ,Down ,Down ,Down ,Down ,Right2|Down ,Right|Down,
21
+ Left|Down2,Left2|Down2,Down2,Down2,Down2,Down2,Right2|Down2,Right|Down2,
22
+ Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
23
+ Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
24
+ Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
25
+ Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
26
+ Left|Up2 ,Left2|Up2 ,Up2 ,Up2 ,Up2 ,Up2 ,Right2|Up2 ,Right|Up2,
27
+ Left|Up ,Left2|Up ,Up ,Up ,Up ,Up ,Right2|Up ,Right|Up
28
+ };
29
+
30
+ //
31
+ // Table of Knight moves
32
+ //
33
+ const struct CConst::st CConst::TKnightMove[8] =
34
+ {
35
+ {Up | Left | Left2 , CSquare::a5 - CSquare::c4},
36
+ {Up | Up2 | Left , CSquare::b6 - CSquare::c4},
37
+ {Up | Up2 | Right , CSquare::d6 - CSquare::c4},
38
+ {Up | Right | Right2 , CSquare::e5 - CSquare::c4},
39
+ {Down | Right | Right2 , CSquare::e3 - CSquare::c4},
40
+ {Down | Down2 | Right , CSquare::d2 - CSquare::c4},
41
+ {Down | Down2 | Left , CSquare::b2 - CSquare::c4},
42
+ {Down | Left | Left2 , CSquare::a3 - CSquare::c4}
43
+ };
44
+
45
+ //
46
+ // Table of King moves
47
+ //
48
+ const struct CConst::st CConst::TKingMove[8] =
49
+ {
50
+ {Down | Right, CSquare::c1 - CSquare::b2},
51
+ {Down , CSquare::b1 - CSquare::b2},
52
+ {Down | Left , CSquare::a1 - CSquare::b2},
53
+ { Left , CSquare::a2 - CSquare::b2},
54
+ {Up | Left , CSquare::a3 - CSquare::b2},
55
+ {Up , CSquare::b3 - CSquare::b2},
56
+ {Up | Right, CSquare::c3 - CSquare::b2},
57
+ { Right, CSquare::c2 - CSquare::b2}
58
+ };
59
+
60
+ //
61
+ // Array of directions
62
+ //
63
+ const int CConst::tDirection[13] =
64
+ {
65
+ 0,
66
+ CSquare::Left,
67
+ CSquare::Up,
68
+ CSquare::Left + CSquare::Up,
69
+ CSquare::Right,
70
+ CSquare::Left + CSquare::Right,
71
+ CSquare::Up + CSquare::Right,
72
+ CSquare::Left + CSquare::Up + CSquare::Right,
73
+ CSquare::Down,
74
+ CSquare::Left + CSquare::Down,
75
+ CSquare::Up + CSquare::Down,
76
+ CSquare::Left + CSquare::Up + CSquare::Down,
77
+ CSquare::Right + CSquare::Down
78
+ };
79
+
@@ -0,0 +1,42 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // const.h
4
+ //
5
+ // CConst class definition
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // July 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #ifndef CONST_H
13
+ #define CONST_H
14
+
15
+ class CConst
16
+ {
17
+ public: ///////////////////////////////////////////////////////////////////
18
+
19
+ //
20
+ // Flags indicating direction and distance from the edge for each square
21
+ //
22
+ enum
23
+ {
24
+ Left = 0x01,
25
+ Up = 0x02,
26
+ Right = 0x04,
27
+ Down = 0x08,
28
+ Left2 = 0x10,
29
+ Up2 = 0x20,
30
+ Right2 = 0x40,
31
+ Down2 = 0x80
32
+ };
33
+
34
+ static const int tcEdge[64];
35
+ struct st {int cDirection; int Direction;};
36
+ static const struct st TKnightMove[8];
37
+ static const struct st TKingMove[8];
38
+ static const int tDirection[13];
39
+ };
40
+
41
+
42
+ #endif
@@ -0,0 +1,96 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // date.cpp
4
+ //
5
+ // CDate class
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // june 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #include <ctime>
13
+ #include <iostream>
14
+ #include <sstream>
15
+ #include <iomanip>
16
+ #include <cstring>
17
+
18
+ #include "date.h"
19
+
20
+ using namespace std;
21
+
22
+ ////////////////////////////////////////////////////////////////////////////
23
+ // Function to retrieve the current date
24
+ ////////////////////////////////////////////////////////////////////////////
25
+ CDate CDate::Today()
26
+ {
27
+ time_t now;
28
+ time(&now);
29
+ struct tm *ptm = localtime(&now);
30
+ return CDate(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday);
31
+ }
32
+
33
+
34
+ ////////////////////////////////////////////////////////////////////////////
35
+ // Constructor to convert a string to a date
36
+ // Format : YYYY?MM?DD (filled with zeroes)
37
+ ////////////////////////////////////////////////////////////////////////////
38
+ CDate::CDate(const char *psz)
39
+ {
40
+ int Length = strlen(psz);
41
+
42
+ Year = 0;
43
+ Month = 0;
44
+ Day = 0;
45
+
46
+ char szBuffer[5];
47
+
48
+ szBuffer[0] = psz[0];
49
+ szBuffer[1] = psz[1];
50
+ szBuffer[2] = psz[2];
51
+ szBuffer[3] = psz[3];
52
+ szBuffer[4] = 0;
53
+ istringstream(szBuffer) >> dec >> Year;
54
+
55
+ if (Length > 5)
56
+ {
57
+ szBuffer[0] = psz[5];
58
+ szBuffer[1] = psz[6];
59
+ szBuffer[2] = 0;
60
+ istringstream(szBuffer) >> dec >> Month;
61
+
62
+ if (Length > 8)
63
+ {
64
+ szBuffer[0] = psz[8];
65
+ szBuffer[1] = psz[9];
66
+ szBuffer[2] = 0;
67
+ istringstream(szBuffer) >> dec >> Day;
68
+ }
69
+ }
70
+ }
71
+
72
+ ////////////////////////////////////////////////////////////////////////////
73
+ // output operator
74
+ ////////////////////////////////////////////////////////////////////////////
75
+ ostream &operator<<(ostream &ostr, const CDate &date)
76
+ {
77
+ char cOldFill = ostr.fill('0');
78
+
79
+ if (date.GetYear())
80
+ ostr << setw(4) << date.GetYear() << '.';
81
+ else
82
+ ostr << "??" << "??.";
83
+
84
+ if (date.GetMonth())
85
+ ostr << setw(2) << date.GetMonth() << '.';
86
+ else
87
+ ostr << "??.";
88
+
89
+ if (date.GetDay())
90
+ ostr << setw(2) << date.GetDay();
91
+ else
92
+ ostr << "??";
93
+
94
+ ostr.fill(cOldFill);
95
+ return ostr;
96
+ }
@@ -0,0 +1,44 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // date.h
4
+ //
5
+ // CDate class definition
6
+ //
7
+ // Remi Coulom
8
+ //
9
+ // June 1996
10
+ //
11
+ ////////////////////////////////////////////////////////////////////////////
12
+ #ifndef DATE_H
13
+ #define DATE_H
14
+
15
+ #include <iostream>
16
+
17
+ class CDate;
18
+
19
+ std::ostream &operator<<(std::ostream &ostr, const CDate &date);
20
+
21
+ class CDate // date
22
+ {
23
+ private: //////////////////////////////////////////////////////////////////
24
+ int Day;
25
+ int Month;
26
+ int Year;
27
+
28
+ public: ///////////////////////////////////////////////////////////////////
29
+ CDate() : Day(0), Month(0), Year(0) {}
30
+ CDate(int y, int m, int d) : Day(d), Month(m), Year(y) {}
31
+ CDate(const char *psz);
32
+
33
+ void SetDay(int NewDay) {Day = NewDay;}
34
+ void SetMonth(int NewMonth) {Month = NewMonth;}
35
+ void SetYear(int NewYear) {Year = NewYear;}
36
+
37
+ int GetDay() const {return Day;}
38
+ int GetMonth() const {return Month;}
39
+ int GetYear() const {return Year;}
40
+
41
+ static CDate Today();
42
+ };
43
+
44
+ #endif
@@ -0,0 +1,58 @@
1
+ ////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // debug.h
4
+ //
5
+ // debug macros
6
+ //
7
+ // Macros for conditionnal compilation :
8
+ // INLINE, MY_ERROR, ASSERT, FATAL, CHECKPOINT, TRACE
9
+ // (see the following code for details)
10
+ //
11
+ // Remi Coulom
12
+ //
13
+ // April, 1996
14
+ //
15
+ ////////////////////////////////////////////////////////////////////////////
16
+ #ifndef DEBUG_H
17
+ #define DEBUG_H
18
+
19
+ #include <iostream>
20
+ #include <cstdlib>
21
+
22
+ //
23
+ // MY_ERROR
24
+ //
25
+ #define MY_ERROR(s) do { \
26
+ std::cout << '\n' << s << '\n'; \
27
+ std::cout << "File: " << __FILE__ << '\n'; \
28
+ std::cout << "Line: " << __LINE__ << '\n'; \
29
+ exit(1);} while(0)
30
+
31
+ //
32
+ // FATAL(x)
33
+ //
34
+ #define FATAL(x) do if ((x)) MY_ERROR("Fatal error: " << #x); while(0)
35
+
36
+ //
37
+ // INLINE, ASSERT(x), CHECKPOINT()
38
+ //
39
+
40
+ #ifdef DEBUG
41
+ #define INLINE
42
+ #define TRACE(s) do {std::cout << s << '\n';} while(0)
43
+ #define ASSERT(x) do if (!(x)) MY_ERROR("Assertion failed: "<<#x); while(0)
44
+ #define CHECKPOINT() do { \
45
+ std::cout << '?'; \
46
+ std::cout.flush(); \
47
+ int x = cin.get(); \
48
+ if (x != '\n') \
49
+ exit(1); \
50
+ } while(0);
51
+ #else
52
+ #define INLINE inline
53
+ #define TRACE(s)
54
+ #define ASSERT(x)
55
+ #define CHECKPOINT()
56
+ #endif
57
+
58
+ #endif