elo-ratings 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/elo-ratings.gemspec +148 -0
- data/ext/bayeselo/.gitignore +4 -0
- data/ext/bayeselo/CBradleyTerry.cpp +670 -0
- data/ext/bayeselo/CBradleyTerry.h +137 -0
- data/ext/bayeselo/CCDistribution.cpp +135 -0
- data/ext/bayeselo/CCDistribution.h +44 -0
- data/ext/bayeselo/CCDistributionCUI.cpp +104 -0
- data/ext/bayeselo/CCDistributionCUI.h +38 -0
- data/ext/bayeselo/CCondensedResults.cpp +253 -0
- data/ext/bayeselo/CCondensedResults.h +64 -0
- data/ext/bayeselo/CDiscretization.h +40 -0
- data/ext/bayeselo/CDistribution.cpp +123 -0
- data/ext/bayeselo/CDistribution.h +58 -0
- data/ext/bayeselo/CDistributionCollection.cpp +34 -0
- data/ext/bayeselo/CDistributionCollection.h +29 -0
- data/ext/bayeselo/CEloRatingCUI.cpp +1046 -0
- data/ext/bayeselo/CEloRatingCUI.h +67 -0
- data/ext/bayeselo/CIndirectCompare.h +28 -0
- data/ext/bayeselo/CJointBayesian.cpp +111 -0
- data/ext/bayeselo/CJointBayesian.h +38 -0
- data/ext/bayeselo/CLUDecomposition.cpp +154 -0
- data/ext/bayeselo/CLUDecomposition.h +36 -0
- data/ext/bayeselo/CMatrix.cpp +48 -0
- data/ext/bayeselo/CMatrix.h +35 -0
- data/ext/bayeselo/CMatrixIO.cpp +27 -0
- data/ext/bayeselo/CMatrixIO.h +17 -0
- data/ext/bayeselo/CPredictionCUI.cpp +393 -0
- data/ext/bayeselo/CPredictionCUI.h +50 -0
- data/ext/bayeselo/CResultSet.cpp +245 -0
- data/ext/bayeselo/CResultSet.h +50 -0
- data/ext/bayeselo/CResultSetCUI.cpp +355 -0
- data/ext/bayeselo/CResultSetCUI.h +44 -0
- data/ext/bayeselo/CTimeIO.cpp +58 -0
- data/ext/bayeselo/CTimeIO.h +19 -0
- data/ext/bayeselo/CVector.cpp +110 -0
- data/ext/bayeselo/CVector.h +42 -0
- data/ext/bayeselo/EloDataFromFile.cpp +120 -0
- data/ext/bayeselo/EloDataFromFile.h +21 -0
- data/ext/bayeselo/README +8 -0
- data/ext/bayeselo/ReadLineToString.cpp +32 -0
- data/ext/bayeselo/ReadLineToString.h +18 -0
- data/ext/bayeselo/chtime.cpp +56 -0
- data/ext/bayeselo/chtime.h +61 -0
- data/ext/bayeselo/chtimer.h +27 -0
- data/ext/bayeselo/clktimer.cpp +178 -0
- data/ext/bayeselo/clktimer.h +29 -0
- data/ext/bayeselo/consolui.cpp +538 -0
- data/ext/bayeselo/consolui.h +154 -0
- data/ext/bayeselo/const.cpp +79 -0
- data/ext/bayeselo/const.h +42 -0
- data/ext/bayeselo/date.cpp +96 -0
- data/ext/bayeselo/date.h +44 -0
- data/ext/bayeselo/debug.h +58 -0
- data/ext/bayeselo/elomain.cpp +26 -0
- data/ext/bayeselo/extconf.rb +6 -0
- data/ext/bayeselo/list.h +367 -0
- data/ext/bayeselo/listi.h +125 -0
- data/ext/bayeselo/move.cpp +249 -0
- data/ext/bayeselo/move.h +139 -0
- data/ext/bayeselo/pgn.h +62 -0
- data/ext/bayeselo/pgnlex.cpp +432 -0
- data/ext/bayeselo/pgnlex.h +105 -0
- data/ext/bayeselo/pgnstr.cpp +126 -0
- data/ext/bayeselo/piece.h +44 -0
- data/ext/bayeselo/player.h +31 -0
- data/ext/bayeselo/position.h +89 -0
- data/ext/bayeselo/random.cpp +114 -0
- data/ext/bayeselo/random.h +63 -0
- data/ext/bayeselo/rb_bayeselo.cpp +76 -0
- data/ext/bayeselo/readstr.cpp +51 -0
- data/ext/bayeselo/readstr.h +19 -0
- data/ext/bayeselo/square.h +61 -0
- data/ext/bayeselo/str.cpp +81 -0
- data/ext/bayeselo/str.h +71 -0
- data/ext/bayeselo/version.cpp +30 -0
- data/ext/bayeselo/version.h +28 -0
- data/ext/bayeselo/version_number.h +1 -0
- data/lib/bayeselo.rb +6 -0
- data/lib/bayeselo/bayeselo.rb +11 -0
- data/lib/bayeselo/c_bayeselo.rb +7 -0
- data/test/bayeselo/test_bayeselo.rb +33 -0
- data/test/bayeselo/test_c_bayeselo.rb +84 -0
- data/test/helper.rb +18 -0
- metadata +226 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
// #include <ruby.h>
|
2
|
+
#include "rice/Class.hpp"
|
3
|
+
#include "rice/Data_Type.hpp"
|
4
|
+
#include "rice/Constructor.hpp"
|
5
|
+
#include "CBradleyTerry.h"
|
6
|
+
#include "CCondensedResults.h"
|
7
|
+
#include "CCDistribution.h"
|
8
|
+
#include "CResultSet.h"
|
9
|
+
|
10
|
+
|
11
|
+
using namespace Rice;
|
12
|
+
|
13
|
+
class CBayeselo
|
14
|
+
{
|
15
|
+
public:
|
16
|
+
CBayeselo();
|
17
|
+
void Append(unsigned w, unsigned b, unsigned r);
|
18
|
+
int GetPlayers();
|
19
|
+
int GetElo(int i);
|
20
|
+
float CountGames(int i);
|
21
|
+
private:
|
22
|
+
CResultSet rs;
|
23
|
+
};
|
24
|
+
|
25
|
+
CBayeselo::CBayeselo()
|
26
|
+
{
|
27
|
+
}
|
28
|
+
|
29
|
+
void CBayeselo::Append(unsigned w, unsigned b, unsigned r) {
|
30
|
+
rs.Append(w, b, r);
|
31
|
+
}
|
32
|
+
|
33
|
+
int CBayeselo::GetPlayers() {
|
34
|
+
return rs.GetPlayers();
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
int CBayeselo::GetElo(int i) {
|
39
|
+
CCondensedResults crs(rs);
|
40
|
+
crs.AddPrior(2.0); // CEloRating constructor
|
41
|
+
CBradleyTerry bt(crs);
|
42
|
+
|
43
|
+
//IDC_MM
|
44
|
+
int fThetaW = 0;
|
45
|
+
int fThetaD = 0;
|
46
|
+
bt.MinorizationMaximization(fThetaW, fThetaD);
|
47
|
+
|
48
|
+
// advantage 0
|
49
|
+
int eloAdvantage = 0;
|
50
|
+
bt.SetAdvantage(eloAdvantage);
|
51
|
+
|
52
|
+
// RoundDouble(double x)
|
53
|
+
double x = bt.GetElo(i);
|
54
|
+
if (x > 0)
|
55
|
+
return int(x+0.5);
|
56
|
+
else
|
57
|
+
return int(x-0.5);
|
58
|
+
}
|
59
|
+
|
60
|
+
float CBayeselo::CountGames(int i) {
|
61
|
+
return rs.CountGames(i);
|
62
|
+
}
|
63
|
+
|
64
|
+
extern "C"
|
65
|
+
void Init_bayeselo()
|
66
|
+
{
|
67
|
+
Rice::Module mBayeselo = define_module("Bayeselo");
|
68
|
+
|
69
|
+
Data_Type<CBayeselo> c_bayeselo =
|
70
|
+
define_class_under<CBayeselo>(mBayeselo, "CBayeselo")
|
71
|
+
.define_constructor(Constructor<CBayeselo>())
|
72
|
+
.define_method("get_players", &CBayeselo::GetPlayers)
|
73
|
+
.define_method("append", &CBayeselo::Append)
|
74
|
+
.define_method("get_elo", &CBayeselo::GetElo)
|
75
|
+
.define_method("count_games", &CBayeselo::CountGames);
|
76
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// readstr.cpp
|
4
|
+
//
|
5
|
+
// ReadString function
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june, 1998
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#include <iostream>
|
13
|
+
|
14
|
+
using namespace std;
|
15
|
+
|
16
|
+
#include "readstr.h"
|
17
|
+
|
18
|
+
////////////////////////////////////////////////////////////////////////////
|
19
|
+
// Function : Reads a string from a stream
|
20
|
+
// Return : Length of the string read, -1 if EOF
|
21
|
+
////////////////////////////////////////////////////////////////////////////
|
22
|
+
int ReadString(istream &is, char *pszBuffer, int Size)
|
23
|
+
{
|
24
|
+
int i;
|
25
|
+
|
26
|
+
if (is.eof())
|
27
|
+
return -1;
|
28
|
+
|
29
|
+
for(i = 0; i < Size; i++)
|
30
|
+
{
|
31
|
+
int c;
|
32
|
+
c = is.peek();
|
33
|
+
|
34
|
+
if (c == std::char_traits<char>::eof() || is.fail())
|
35
|
+
{
|
36
|
+
pszBuffer[i] = 0;
|
37
|
+
return -1;
|
38
|
+
}
|
39
|
+
|
40
|
+
is.get();
|
41
|
+
if (c == '\n')
|
42
|
+
{
|
43
|
+
pszBuffer[i] = 0;
|
44
|
+
return i;
|
45
|
+
}
|
46
|
+
else
|
47
|
+
pszBuffer[i] = c;
|
48
|
+
}
|
49
|
+
|
50
|
+
return i;
|
51
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// readstr.h
|
4
|
+
//
|
5
|
+
// ReadString function
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june, 1998
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef READSTR_H
|
13
|
+
#define READSTR_H
|
14
|
+
|
15
|
+
#include <iostream>
|
16
|
+
|
17
|
+
int ReadString(std::istream &is, char *pszBuffer, int Size);
|
18
|
+
|
19
|
+
#endif
|
@@ -0,0 +1,61 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// square.h
|
4
|
+
//
|
5
|
+
// CSquare class definition
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// june 1996
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef SQUARE_H
|
13
|
+
#define SQUARE_H
|
14
|
+
|
15
|
+
class CSquare // sq
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
int sq;
|
19
|
+
|
20
|
+
public: ///////////////////////////////////////////////////////////////////
|
21
|
+
enum
|
22
|
+
{
|
23
|
+
a1, b1, c1, d1, e1, f1, g1, h1,
|
24
|
+
a2, b2, c2, d2, e2, f2, g2, h2,
|
25
|
+
a3, b3, c3, d3, e3, f3, g3, h3,
|
26
|
+
a4, b4, c4, d4, e4, f4, g4, h4,
|
27
|
+
a5, b5, c5, d5, e5, f5, g5, h5,
|
28
|
+
a6, b6, c6, d6, e6, f6, g6, h6,
|
29
|
+
a7, b7, c7, d7, e7, f7, g7, h7,
|
30
|
+
a8, b8, c8, d8, e8, f8, g8, h8
|
31
|
+
};
|
32
|
+
|
33
|
+
enum
|
34
|
+
{
|
35
|
+
Left = -1,
|
36
|
+
Right = +1,
|
37
|
+
Up = +8,
|
38
|
+
Down = -8
|
39
|
+
};
|
40
|
+
|
41
|
+
CSquare() {}
|
42
|
+
CSquare(int i) {sq = i;}
|
43
|
+
CSquare(const char *psz) {sq = psz[0] - 'a' + 8 * (psz[1] - '1');}
|
44
|
+
|
45
|
+
operator int() const {return sq;}
|
46
|
+
const CSquare &operator +=(int i) {sq += i; return *this;}
|
47
|
+
const CSquare &operator -=(int i) {sq -= i; return *this;}
|
48
|
+
const CSquare &operator ++() {sq++; return *this;}
|
49
|
+
|
50
|
+
int GetRank() const {return sq / 8;}
|
51
|
+
int GetFile() const {return sq % 8;}
|
52
|
+
int IsWhite() const {return ((sq / 8) + (sq % 8)) & 1;}
|
53
|
+
void MakeString(char *psz)
|
54
|
+
{
|
55
|
+
psz[0] = 'a' + GetFile();
|
56
|
+
psz[1] = '1' + GetRank();
|
57
|
+
psz[2] = 0;
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
#endif
|
@@ -0,0 +1,81 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// str.cpp
|
4
|
+
//
|
5
|
+
// CSTR class
|
6
|
+
// (Seven Tag Roster)
|
7
|
+
//
|
8
|
+
// Remi Coulom
|
9
|
+
//
|
10
|
+
// june 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#include <cstring>
|
14
|
+
|
15
|
+
#include "debug.h"
|
16
|
+
#include "str.h"
|
17
|
+
|
18
|
+
////////////////////////////////////////////////////////////////////////////
|
19
|
+
// Safe copy of a string to another string with limited size
|
20
|
+
////////////////////////////////////////////////////////////////////////////
|
21
|
+
static void SafeCopy(char *pszDest, const char *pszOrig, int Size)
|
22
|
+
{
|
23
|
+
strncpy(pszDest, pszOrig, Size);
|
24
|
+
pszDest[Size - 1] = 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
////////////////////////////////////////////////////////////////////////////
|
28
|
+
// Default constructor
|
29
|
+
////////////////////////////////////////////////////////////////////////////
|
30
|
+
CSTR::CSTR()
|
31
|
+
{
|
32
|
+
Reset();
|
33
|
+
}
|
34
|
+
|
35
|
+
////////////////////////////////////////////////////////////////////////////
|
36
|
+
// Reset function
|
37
|
+
////////////////////////////////////////////////////////////////////////////
|
38
|
+
void CSTR::Reset()
|
39
|
+
{
|
40
|
+
*szEvent = 0;
|
41
|
+
*szSite = 0;
|
42
|
+
*szRound = 0;
|
43
|
+
*szWhite = 0;
|
44
|
+
*szBlack = 0;
|
45
|
+
Result = Unknown;
|
46
|
+
date = CDate::Today();
|
47
|
+
}
|
48
|
+
|
49
|
+
////////////////////////////////////////////////////////////////////////////
|
50
|
+
// Functions to set strings
|
51
|
+
////////////////////////////////////////////////////////////////////////////
|
52
|
+
void CSTR::SetEvent(const char *psz)
|
53
|
+
{
|
54
|
+
SafeCopy(szEvent, psz, sizeof szEvent);
|
55
|
+
}
|
56
|
+
|
57
|
+
void CSTR::SetSite(const char *psz)
|
58
|
+
{
|
59
|
+
SafeCopy(szSite, psz, sizeof szSite);
|
60
|
+
}
|
61
|
+
|
62
|
+
void CSTR::SetRound(const char *psz)
|
63
|
+
{
|
64
|
+
SafeCopy(szRound, psz, sizeof szRound);
|
65
|
+
}
|
66
|
+
|
67
|
+
void CSTR::SetWhite(const char *psz)
|
68
|
+
{
|
69
|
+
SafeCopy(szWhite, psz, sizeof szWhite);
|
70
|
+
}
|
71
|
+
|
72
|
+
void CSTR::SetBlack(const char *psz)
|
73
|
+
{
|
74
|
+
SafeCopy(szBlack, psz, sizeof szBlack);
|
75
|
+
}
|
76
|
+
|
77
|
+
void CSTR::SetResult(int i)
|
78
|
+
{
|
79
|
+
ASSERT(i >= BlackWins && i <= Unknown);
|
80
|
+
Result = i;
|
81
|
+
}
|
data/ext/bayeselo/str.h
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// str.h
|
4
|
+
//
|
5
|
+
// CSTR class definition
|
6
|
+
// (Seven Tag Roster)
|
7
|
+
//
|
8
|
+
// R�mi Coulom
|
9
|
+
//
|
10
|
+
// june 1996
|
11
|
+
//
|
12
|
+
////////////////////////////////////////////////////////////////////////////
|
13
|
+
#ifndef STR_H
|
14
|
+
#define STR_H
|
15
|
+
|
16
|
+
#include "date.h" // CDate
|
17
|
+
|
18
|
+
class CSTR // str
|
19
|
+
{
|
20
|
+
private: //////////////////////////////////////////////////////////////////
|
21
|
+
char szEvent[64];
|
22
|
+
char szSite[64];
|
23
|
+
CDate date;
|
24
|
+
char szRound[32];
|
25
|
+
char szWhite[64];
|
26
|
+
char szBlack[64];
|
27
|
+
int Result;
|
28
|
+
|
29
|
+
public: ///////////////////////////////////////////////////////////////////
|
30
|
+
//
|
31
|
+
// Possible Results
|
32
|
+
//
|
33
|
+
enum
|
34
|
+
{
|
35
|
+
BlackWins, // 0-1
|
36
|
+
Draw, // 1/2-1/2
|
37
|
+
WhiteWins, // 1-0
|
38
|
+
Unknown, // *
|
39
|
+
Results
|
40
|
+
};
|
41
|
+
|
42
|
+
//
|
43
|
+
// Default constructor, to prevent dangerous uninitialized data
|
44
|
+
//
|
45
|
+
CSTR();
|
46
|
+
|
47
|
+
//
|
48
|
+
// Sets
|
49
|
+
//
|
50
|
+
void Reset();
|
51
|
+
void SetResult(int i);
|
52
|
+
void SetDate(const CDate &dateNew) {date = dateNew;}
|
53
|
+
void SetEvent(const char *psz);
|
54
|
+
void SetSite(const char *psz);
|
55
|
+
void SetRound(const char *psz);
|
56
|
+
void SetWhite(const char *psz);
|
57
|
+
void SetBlack(const char *psz);
|
58
|
+
|
59
|
+
//
|
60
|
+
// Gets
|
61
|
+
//
|
62
|
+
int GetResult() const {return Result;}
|
63
|
+
const CDate &GetDate () const {return date;}
|
64
|
+
const char *GetEvent() const {return szEvent;}
|
65
|
+
const char *GetSite () const {return szSite;}
|
66
|
+
const char *GetRound() const {return szRound;}
|
67
|
+
const char *GetWhite() const {return szWhite;}
|
68
|
+
const char *GetBlack() const {return szBlack;}
|
69
|
+
};
|
70
|
+
|
71
|
+
#endif
|
@@ -0,0 +1,30 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// version.cpp
|
4
|
+
//
|
5
|
+
// CVersion class
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// May, 1997
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#include "version.h"
|
13
|
+
|
14
|
+
#include "version_number.h"
|
15
|
+
|
16
|
+
const char CVersion::szVersion[] = VERSION;
|
17
|
+
const char CVersion::szCopyright[] =
|
18
|
+
"version "VERSION", Copyright (C) 1997-2010 Remi Coulom.\n"
|
19
|
+
"compiled "__DATE__" "__TIME__".\n"
|
20
|
+
"This program comes with ABSOLUTELY NO WARRANTY.\n"
|
21
|
+
"This is free software, and you are welcome to redistribute it\n"
|
22
|
+
"under the terms and conditions of the GNU General Public License.\n"
|
23
|
+
"See http://www.gnu.org/copyleft/gpl.html for details.\n";
|
24
|
+
|
25
|
+
const char CVersion::szBinary[] =
|
26
|
+
"version "VERSION".\n"
|
27
|
+
"Copyright 1997-2010 by Remi Coulom. All Rights Reserved.\n"
|
28
|
+
"Permission is granted to freely use and distribute this program,\n"
|
29
|
+
"provided that no charge is made for it and it is distributed unmodified\n"
|
30
|
+
"This program comes with ABSOLUTELY NO WARRANTY.\n";
|
@@ -0,0 +1,28 @@
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// version.h
|
4
|
+
//
|
5
|
+
// CVersion class declaration
|
6
|
+
//
|
7
|
+
// Remi Coulom
|
8
|
+
//
|
9
|
+
// May, 1997
|
10
|
+
//
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
12
|
+
#ifndef VERSION_H
|
13
|
+
#define VERSION_H
|
14
|
+
|
15
|
+
class CVersion
|
16
|
+
{
|
17
|
+
private: //////////////////////////////////////////////////////////////////
|
18
|
+
static const char szVersion[];
|
19
|
+
static const char szCopyright[];
|
20
|
+
static const char szBinary[];
|
21
|
+
|
22
|
+
public: ///////////////////////////////////////////////////////////////////
|
23
|
+
static const char *GetVersion() {return szVersion;}
|
24
|
+
static const char *GetCopyright() {return szCopyright;}
|
25
|
+
static const char *GetBinaryCopyright() {return szBinary;}
|
26
|
+
};
|
27
|
+
|
28
|
+
#endif
|
@@ -0,0 +1 @@
|
|
1
|
+
#define VERSION "0057"
|
data/lib/bayeselo.rb
ADDED