How to Use R to Gain Predictive Point Values of Chess Pieces
Rasmus Baath uses the statistical language R to get predictive point values for chess pieces, then explains his method and results.
Join the DZone community and get the full member experience.Join For Free
who doesn’t like chess? me! sure, i like the idea of chess – intellectual masterminds battling each other using nothing but pure thought – the problem is that i tend to lose, probably because i don’t really know how to play well, and because i never practice. i do know one thing: how much the different pieces are worth, their point values :
this was among the first things i learned when i was taught chess by my father. given these point values it should be as valuable to have a knight on the board as having three pawns, for example. so where do these values come from? the point values are not actually part of the rules for chess, but are rather just used as a guideline when trading pieces, and they seem to be based on the expert judgment of chess authorities. (according to the guardian of truth there are many alternative valuations , all in the same ballpark as above.) as i recently learned that it is very important to be able to write big data on your cv, i decided to see if these point values could be retrieved using zero expert judgement in favor of huge amounts of chess game data.
how to allocate point values to the chess pieces using only data? one way of doing this is to calculate the predictive values of the chess pieces. that is, given that we only know the current number of pieces in a game of chess and use that information to predict the outcome of that game, how much does each type of piece contribute to the prediction? we need a model to predict the outcome of chess games where we have the following restrictions:
- each type of piece has a single point value that directly contributes to the predicted outcome of the game, so no interaction effects between the pieces.
- the value of a piece does not change over the course of the game.
- use no context and nor positional information.
now these restrictions might feel a bit restrictive , especially if we actually would want to predict the outcome of chess games as well as possible, but they come from that the original point values follow the same restrictions. as the original point values doesn’t change with context, neither should ours. now, as my colleague can kabadayi (with an elo well above 2000) remarked: “but context is everything in chess!” absolutely, but i’m not trying to do anything profound here, this is just a fun exercise!
given the restrictions there is one obvious model: logistic regression, a vanilla statistical model that calculates the probability of a binary event, like a loss-win. to get it going i needed data and the biggest big data data set i could find was the million base 2.2 which contains over 2.2 million chess games. i had to do a fair deal of data munging to get it into a format that i could work with, but the final result was a table with a lot of rows that looked like this:
pawn_diff rook_diff knight_diff bishop_diff queen_diff white_win 1 0 1 -1 0 true
here each row is from a position in a game where a positive number means white has more of that piece. for the position above white has one more pawn and knight, but one less bishop than black. last in each row we get to know whether white won or lost in the end, as logistic regression assumes a binary outcome i discarded all games that ended in a draw. my résumé is unfortunately not going to look that good as i never really solved the big data problem well. two million chess games are a lot of games and it took my poor old laptop over a day to process only the first 100,000 games. then i had the classic big data problem that i couldn’t fit it all into working memory, so i simply threw away data until worked. still, for the analysis i ended up using a sample of 1,000,000 chess positions from the first 100,000 games in the million base 2.2 . big enough data for me.
using the statistical language r , i first fitted the following logistic model using maximum likelihood (here described by r’s formula language):
white_win ~ 1 + pawn_diff + knight_diff + bishop_diff + rook_diff + queen_diff
this resulted in the following piece values:
three things to note: (1) in addition to the piece values, the model also included a coefficient for the advantage of going first, called white’s advantage above. (2) the predictive piece values ranks the pieces in the same order as the original piece values does. (3) the piece values are given in log-odds , which can be a bit tricky to interpret but that can be easily transformed into probabilities as this graph shows:
here white’s advantage translates to a 56% chance of white winning (everything else being equal), being two knights and one rook ahead but one pawn behind gives 92% chance of winning, while being one queen behind gives only a 8% chance of winning. while log-odds are useful if you want to calculate probabilities, the original piece values are not given in log-odds, instead they are set relative to the value of a pawn which is fixed at 1.0 . let’s scale our log-odds so that the pawn is give a piece value of 1.0 :
we see now that, while the ranking is roughly the same, the scale is compressed compared to the original piece values. a queen is usually considered as nine times more valuable than a pawn, yet when it comes to predicting the outcome of a game a queen advantage counts the same as only a four pawn advantage. a second thing to notice is that bishops are valued slightly higher than knights. if you look at the wiki page for chess piece relative value you find that some alternative valuations value the bishop slightly higher than the knight, others add ½ point for a complete bishop pair. we can add that to the model!
white_win ~ 1 + pawn_diff + knight_diff + bishop_diff + rook_diff + queen_diff + bishop_pair_diff
now with a pair of bishops getting their own value, the values of a knight and a single bishop are roughly equal. there is still the “mystery” regarding the low valuation of all the pieces compared to the pawn. (this doesn’t really have to be a mystery as there is no reason why predictive piece values necessarily should be the same as the original piece values). instead of anchoring the value of a pawn to 1.0 we could anchor the value of another piece to it’s original piece value. let’s anchor the knight to 3.0:
now the value of the pieces (excluding the pawn) line up very nicely with the original piece values! so, as i don’t really play chess, i don’t know why a pawn advantage is such a strong predictor of winning (compared to the original piece values, that is). my colleague can kabadayi (the elo > 2000 guy!) had the following to say:
in a high-class game the pawns can be more valuable – they are often the decisive element of the outcome – one can even say that the whole plan of the middle game is to munch a pawn somewhere and then convert it in the endgame by exchanging the pieces, thus increasing the value of the pawn. grandmaster games tend to go to a rook endgame where both sides have a rook but one side has an extra pawn. it is not easy to convert these positions into a win, but you see the general idea. a passed pawn (a pawn that does not have any enemy pawns blocking its march to become a queen) is also an important asset in chess, as they are a constant threat to become a queen.
can also gave me two quotes from legendary chess grandmasters josé capablanca and paul keres relating to the value of pawns:
the winning of a pawn among good players of even strength often means the winning of the game. – jose capablanca
the older i grow, the more i value pawns. – paul keres
another thing to keep in mind is that the predictive piece values might have looked very difference if i had used a different data set. for example, the players in the current data set are all very skilled, having a median elo of 2400 and with 95% of the players having an elo between 2145 and 2660. still i think it is cool that the predictive piece values matched the original piece values as well as they did!
this post originally appeared on rasmus baath's blog titled "publishable stuff." it was published under the creative commons attribution 4.0 international license . formatting has been made more suitable for dzone.
Published at DZone with permission of Rasmus , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.