04 September 2009

Free Chess + Opening Browser Iphone “App”

I play chess at ShredderChess.com on my iphone. I also look at opening moves on QueenAlice.com. It’d be very convenient to immediately jump from a particular position in a chess game on shredder to the opening moves browser of that position on queen alice. I have built an “App” to do exactly that…

OK, it’s not an app, it’s actually a bookmarklet (a url that runs javascript). To use it, you’ll have to get a bookmark with the following url onto your iphone:

javascript:(function()%7Bvar%20pieces=%5B'-','k','q','r','b','n','p','K','Q','R','B','N','P'%5D;var%20getBoard=function(p)%7Bvar%20result='';for(var%20i=0;i%3C64;i++)%7Bresult+=pieces%5Bp.b%5B64-8*parseInt(i/8)-(8-i%258)%5D%5D%7D;result+=(p.castling%3E12?'kq':'--');result+=(p.castling%3E3?'KQ':'--');return%20result%7D;var%20p=document.getElementsByTagName('iframe')%5B0%5D.contentWindow.p,halfmove=p.pliesplayed+1,board=getBoard(p);window.open('http://queenalice.com/opening.php?board='+board+'&halfmove='+halfmove);%7D)()

How to get it on your iPhone:

If you’re running OS 3, then just:

  1. copy the bookmarklet code above
  2. create a bookmark called something like "Opening Bookmarklet"
  3. go edit the bookmark and change the location to the code you just copied. Simple!

If you don’t have copy and paste, then your best bet is to make the bookmark on your browser and sync it to your iphone.

Using the bookmarklet:

Once you have the bookmarklet on your phone, go to the Shredderchess iphone page and start a game.

When you’ve made a few moves and you’re not sure what you should do next, click on the bookmarks option in bottom of safari and select the bookmarklet—“Opening Bookmarklet”. It will read the position on the current board and magically open up a new window showing the Queen alice opening moves browser with suggestions on where to move next.

By the way, Shredder does offer a relatively cheap iphone app that is probably a better experience, which I’ll probably buy, but the bookmarklet is kind of fun in a retro web-developer sort of way.

Technical Details:

I have included the non-obsfucated code for anyone who is interested. It accesses the javascript object that represents the board and uses its data to generate a string that the opening browser can understand:

(function() {
var pieces = ['-','k','q','r','b','n','p','K','Q','R','B','N','P'];
var getBoard = function(p) {
  var result = '';
  for (var i=0; i<64; i++) {
    result += pieces[p.b[64-8*parseInt(i/8)-(8-i%8)]];
  }
  result += (p.castling > 12 ? 'kq' : '--');
  result += (p.castling > 3 ? 'KQ' : '--');
  return result;
}
var p = document.getElementsByTagName('iframe')[0].contentWindow.p,
    halfmove = p.pliesplayed+1,
    board = getBoard(p);
window.open('http://queenalice.com/opening.php?board='+board+'&halfmove='+halfmove);
})()

Comments (3)

1. algdfa wrote:

good chess Scripts

Posted on 8 May 2010 at 6:05 PM  |  permalink

2. Chess Game wrote:

It is very nice see the blog. Usally one can play chess on Iphone. So its a nice experience.

Posted on 11 June 2010 at 10:06 AM  |  permalink

3. vivek wrote:

hey man ... great work i am looking for such app for my iphon

Posted on 12 April 2011 at 3:04 PM  |  permalink




Did you find this helpful or fun? paypal.me/mrcoles

Peter Coles

Peter Coles

is a software engineer living in NYC who is building Superset 💪 and also created GoFullPage 📸
more »

github · soundcloud · @lethys · rss