<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Chess Rating Algorithm</title>
		<link>http://www.allegro.cc/forums/view/600698</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 26 Jun 2009 19:04:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Due to an interesting turn of events, I need to calculate someones chess rating.  So far I&#39;ve found this description of the offical formula.</p><p><a href="http://math.bu.edu/people/mg/ratings/rs/node1.html">http://math.bu.edu/people/mg/ratings/rs/node1.html</a></p><p>Does anyone have any previous experience with this or know of somewhere I can rip code from?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 26 Jun 2009 05:31:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, somehow I thought you were looking for a way to rate chess positions (for a chess program), which I do have some direct experience with.<br />From what I remember about calculating someone&#39;s performance ELO rating, it&#39;s not actually that hard, but I don&#39;t remember the details... I&#39;m sure I have the source code to the program we used in our chess club back home (the guy who wrote it is the guy who explained to me how to do the calculation), but it&#39;s on a computer that&#39;s powered down on another continent than where I am at the moment. It probably wouldn&#39;t have been terribly useful to you anyway, since I seem to remember the code had a lot of syntactic sugar to make it look like some horrible Pascal/Bourne shell hybrid (it&#39;s C though).</p><p>sorry I couldn&#39;t be more helpful...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 26 Jun 2009 06:23:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s what I&#39;ve put together based on <a href="http://en.wikipedia.org/wiki/Elo_rating_system#Theory">this article</a>:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> rating<span class="k2">;</span>
<span class="k1">int</span> opponentRating<span class="k2">;</span>
<span class="k1">float</span> score <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>

<span class="k1">if</span><span class="k2">(</span>win<span class="k2">)</span>
  score <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>draw<span class="k2">)</span>
  score <span class="k3">=</span> .<span class="n">5f</span><span class="k2">;</span>

rating <span class="k3">=</span> round<span class="k2">(</span>rating <span class="k3">+</span> <span class="n">32</span> <span class="k3">*</span> <span class="k2">(</span>score <span class="k3">-</span> <span class="n">1</span> <span class="k3">/</span> <span class="k2">(</span><span class="n">1</span>.<span class="n">0f</span> <span class="k3">+</span> <span class="n">10</span> <span class="k3">*</span> <span class="k2">(</span>otherRating <span class="k3">-</span> rating<span class="k2">)</span> <span class="k3">/</span> <span class="n">400</span>.<span class="n">0f</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
(This assumes a K value of 32, which is typically only used for novice games.  GM games and above use K values of 10 or so.  See <span class="ref"><sup>[<a href="#">1</a>]</sup></span>)</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600698/818252#target">Evert</a> said:</div><div class="quote"><p>
Ah, somehow I thought you were looking for a way to rate chess positions (for a chess program), which I do have some direct experience with.
</p></div></div><p>
I am also very curious about that.  How much time would it take me to make a decent chess program?  How <i>do</i> I rate a chess position?
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://en.wikipedia.org/wiki/Elo_rating_system#Most_accurate_K-factor">http://en.wikipedia.org/wiki/Elo_rating_system#Most_accurate_K-factor</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 26 Jun 2009 07:04:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600698/818257#target">Dustin Dettmer</a> said:</div><div class="quote"><p>(This assumes a K value of 32, which is typically only used for novice games. GM games and above use K values of 10 or so. See [1])</p></div></div><p>
The K value should depend on the number of rated games; it&#39;s higher if there are fewer games that have been rated (which is typically the case for novice players, of course).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I am also very curious about that. How much time would it take me to make a decent chess program? How do I rate a chess position?</p></div></div><p>
Writing a chess program isn&#39;t actually that hard, but writing one that plays decently... meh. I don&#39;t think I&#39;ve succeeded in doing that.<br />The most important factor in determining how good a chess program plays is how many moves in advance it can calculate. That means the key is to make everything as fast as possible, in particular move generation (the list of possible moves) and your evaluation function. Because a chess board is 8x8=64 squares and a byte is 8 bits (and 64 bits fit exactly in a word on a modern CPU), there are some very neat and efficient bit-twiddling tricks you can use to generate moves (for instance, to generate all possible pawn moves, take a &quot;bit board&quot; representing pawn positions for a particular player, shift it by one row and do a logical and with a bitboard that represents all empty squares; now you just read off the non-zero bits to find possible pawn destinations). For the evaluation function too the important thing is to keep it simple. In practice, that means counting material (disappointing as that is): give a pawn a value of 100 (say) and assign the other pieces their relative increase in value (you can play around a bit with the values here: 300 could be a knight or a bishop, or you could make bishops 325 if you prefer, or give them a slightly higher value if the player still has both of them). Then it&#39;s just a matter of bookkeeping.<br />Once that&#39;s up, you can refine it by scoring points for pawn structure or strategic placement of pieces (near the centre of the board, attacking squares near the enemy king), that&#39;s something you can spend forever on.</p><p>Do a google for &quot;minimax&quot; or &quot;alpha-beta algorithm&quot; if you want to work out the details.</p><p>Damn, now you&#39;ve made me want to write a chess program again. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 26 Jun 2009 07:40:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600698/818261#target">Evert</a> said:</div><div class="quote"><p>(for instance, to generate all possible pawn moves, take a &quot;bit board&quot; representing pawn positions for a particular player, shift it by one row and do a logical and with a bitboard that represents all empty squares; now you just read off the non-zero bits to find possible pawn destinations)</p></div></div><p>

You&#39;d also have to take into account en passant and that pawns can move two squares on their first move.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Fri, 26 Jun 2009 12:01:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600698/818295#target">Inphernic</a> said:</div><div class="quote"><p>You&#39;d also have to take into account en passant and that pawns can move two squares on their first move.</p></div></div><p>
You did realise you were stating the obvious, right?<br />Ok, what I described gives you all possible <i>regular</i> pawn moves. All double pawn moves can be generated by repeating this procedure twice, all captures by shifting the bitboard by 7 or 9 bits instead of 8 (be sure to mask the column that would wrap around the board). En-passant capture requires some special care in the sense that you have to keep track of the e.p. square.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 26 Jun 2009 16:52:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600698/818323#target">Evert</a> said:</div><div class="quote"><p>You did realise you were stating the obvious, right?</p></div></div><p>

To all chess players, sure, just like offside rules in American football are obvious to those who are familiar with them.</p><p>In my experience, many casual players (even good ones) are not aware of en passant. There should be no harm done in saying that implementing method X for generating all possible pawn moves doesn&#39;t quite generate all possible pawn moves, whether Dustin is familiar with the move or not. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Fri, 26 Jun 2009 19:04:38 +0000</pubDate>
	</item>
</rss>
