• Stars
    star
    158
  • Rank 237,131 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as chess and Go.

Elo

From Wikipedia:

The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as chess and Go. It is named after its creator Arpad Elo, a Hungarian-born American physics professor.

The Elo system was invented as an improved chess rating system, but today it is also used in many other games. It is also used as a rating system for multiplayer competition in a number of computer games, and has been adapted to team sports including association football, American college football and basketball, and Major League Baseball.

Usage

You need to have at least two players that can play a game (duh).

bob  = Elo::Player.new
jane = Elo::Player.new(:rating => 1500)

Once you have players, you can register games in a variaty of ways. There is more than one way to do it, choose whatever works from your other code:

game1 = bob.wins_from(jane)
game2 = bob.loses_from(jane)
game3 = bob.plays_draw(jane)

game4 = bob.versus(jane)
game4.winner = jane

game5 = bob.versus(jane)
game5.loser = jane

game6 = bob.versus(jane)
game6.draw

game7 = bob.versus(jane)
game7.result = 1 # result is in perspective of bob, so bob wins

game8 = bob.versus(jane, :result => 0) # jane wins

You can get all kinds of info from a player:

bob.rating       # => 1080
bob.pro?         # => false
bob.starter?     # => true
bob.games_played # => 8
bob.games        # => [ game1, game2, ... game8 ]

Configuration

You can configure Elo in many ways. In it’s default configuration, it is configured in the same way as the FIDE (World Chess Foundation).

Altering settings to your liking is very easy and very flexible. You can even specify your own K-factor rules. Have a look at the Rdoc in the code for a complete reference.

Here is an example:

Elo.configure do |config|

  # Every player starts with a rating of 1000
  config.default_rating = 1000

  # A player is considered a pro, when he/she has more than 2400 points
  config.pro_rating_boundry = 2400

  # A player is considered a new, when he/she has played less than 30 games
  config.starter_boundry = 30

end

About the K-factor

The Elo rating system knows a variable called the “K-factor”. The K-factor is used to reward new talent and stableize the rating once a player is participating longer.

FIDE (the World Chess Foundation), gives players with less than 30 played games a K-factor of 25. Normal players get a K-factor of 15 and pro’s get a K-factor of 10. Once you reach a pro status, you’re K-factor never changes, even if your rating drops.

You need to provide Elo the amount of games played, their rating and their pro-status.

bob = Elo::Player.new(:games_played => 29, :rating => 2399, :pro => true)
bob.k_factor == 10

You can define your own K-factors by adding K-factor rules. This code will change the K-factor to 12, for every player that played less than 10 games, and 16 for everybody else.

Elo.configure do |config|
  config.k_factor(12) { games_played < 10 }
  config.default_k_factor = 16
  config.use_FIDE_settings = false
end

Installation

gem install elo

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Iain Hecker. Released under the MIT License

More Repositories

1

http_accept_language

Ruby on Rails plugin. Fishes out the Accept-Language header into an array.
Ruby
771
star
2

fake_sqs

Provides a fake SQS server that you can run locally to test against
Ruby
292
star
3

roundsman

Combines Capistrano with Chef Solo
Ruby
204
star
4

metrical

Run MetricFu without making it part of your projects depencies.
Ruby
126
star
5

dotfiles

My bash / zsh / vim / pry settings
Vim Script
88
star
6

i18n_label

Adds translated form labels to Rails 2.2
Ruby
55
star
7

translatable_columns

Provides proxies for localized columns, depending on the locale set by I18n
Ruby
51
star
8

status_cats

Rack middleware replacing status codes with relevant pictures of cats.
Ruby
37
star
9

simple-backend-example

The source code for the article I wrote on Backends in Rails 3.1
Ruby
34
star
10

capistrano_chef_solo

Combining the awesome powers of Capistrano and chef-solo
Ruby
20
star
11

rack-token_auth

Rack middleware for using the Authorization header with token authentication
Ruby
14
star
12

formalize-rails

Use Formalize with the asset pipeline
Ruby
11
star
13

adventures-with-ruby

My own blog
Ruby
11
star
14

not

Syntactic sugar for negating any results: @foo.not.nil?
Ruby
10
star
15

no_value_helper

A simpel helper to display a nice message when there is no value
Ruby
6
star
16

scripted

A framework for organizing scripts
Ruby
6
star
17

spec_coverage

Ruby
6
star
18

basic_named_scopes

Basic named scopes for ActiveRecord makes all find-parameters a named scope
Ruby
5
star
19

model_based_html

Rails plugin for binding html to models
Ruby
4
star
20

root_table

Easy manageable root tables for Rails
Ruby
4
star
21

view

Displaying objects automatically
Ruby
4
star
22

coffee-machine

Some scripts I use for developing with CoffeeScript
Ruby
4
star
23

coffeescript-workshop

Examples and scripts for some workshops
Shell
4
star
24

rspec-smart-formatter

Chooses a formatter for best displaying purpose
Ruby
4
star
25

rule_table

A simple implementation of a rule table with lots of metaprogramming.
Ruby
4
star
26

faker

This fork is deleted soon
Ruby
4
star
27

stots

Ruby
3
star
28

fill

Fill your database, using rake db:seed
Ruby
3
star
29

i18n-airbrake

Ruby
3
star
30

rake_svn

Some handy svn commands for Rails
2
star
31

miniture-ninja

Experiments with WebGL
CoffeeScript
2
star
32

pillory

work in progress
Ruby
2
star
33

validate_database

Rails plugin that validates ActiveRecord according to the database
2
star
34

ubuntu_settings

Personal stuff with configuration, custom scripts and aliases for Ubuntu
Vim Script
2
star
35

capistrano-blaze

Ruby
2
star
36

tally

Simple Slack Bot, using AWS Lambda, SNS, SQS, API Gateway
Ruby
2
star
37

kingsofcode

2
star
38

iain.github.com

Github pages
2
star
39

heliosphere

Sunspot extras
Ruby
2
star
40

wodan

Ruby
1
star
41

opengl

A night of hacking OpenGL in Ruby
Ruby
1
star
42

adventure

Ruby
1
star
43

cramplire

Ruby
1
star
44

test_suite

Ruby
1
star
45

bearded-robot

Ruby
1
star
46

crockford

Crockford's Base32 (not the regular one), it switches out a couple letters to reduce chances of mistyping codes
Ruby
1
star
47

blaze

A tiny Campfire gem
Ruby
1
star
48

object_scoped_i18n

Translate using i18n and scope it according to the object's place in Ruby's hierarchial structure
Ruby
1
star